Problem using OWL Framework

Been working with Jonathan Bebbe’s OWL Framework lately: http://developer.coronalabs.com/code/owl-objects-lua and I have run into an odd issue that maybe someone can help me with.
I have a class, game object class :

local owl = require "owl"  
local game\_object = owl.class{ name="game\_object" }  
  
local game\_unid =nil;  
local game\_name =nil;  
  
function game\_object:init(params)  
 game\_unid = params.game\_unid;  
 game\_name = params.game\_name;  
end  
function game\_object:debug\_game\_object()  
 print("\*\*\*\*\*Debug Game Object\*\*\*\*\*");  
 print("UNID:", game\_unid);  
 print("Game Name:",game\_name);  
 print("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");  
end  
return game\_object;  

and then I have another class that inherits from the game object class, it is called the weapon class:

local owl = require "owl"  
local Game\_Object = require "game\_obj"  
local Weapon = owl.class{ from="game\_object", name="Weapon" }  
  
function Weapon:init(params)  
print("\*\*\*\*\*\*Weapon Constructor Called\*\*\*\*\*");  
self.super\_class:init(params);  
end  
  
function Weapon:debug\_weapon()  
 print("\*\*\*\*\*\*Debug weapon\*\*\*\*\*\*\*");  
 self.super\_class:debug\_game\_object();  
end  
return Weapon;  

And that all looks and works ok, the problem is when I create two instances of the Weapon class. The first gets created properly and so does the second. When I call a function in the Weapon class of the first instantiated object it calls it in the second one instead.
Here is the main.lua:

local owl = require "owl"  
require"weapon"  
local weapon\_params={  
 game\_unid="89042432",  
 game\_name= "Sword"  
 }  
local weapon\_params\_2={  
 game\_unid="222222",  
 game\_name= "Gun"  
 }  
  
local player\_weapon = owl.instance{ from="Weapon" , params = weapon\_params}  
local player\_weapon\_2 = owl.instance{ from="Weapon" , params = weapon\_params\_2}  
  
player\_weapon\_2:debug\_weapon();  
player\_weapon:debug\_weapon();  

Here is the terminal output:

\*\*\*\*\*\*Weapon Constructor Called\*\*\*\*\*   
\*\*\*\*\*\*Weapon Constructor Called\*\*\*\*\*   
\*\*\*\*\*\*Debug weapon\*\*\*\*\*\*\*   
\*\*\*\*\*Debug Game Object\*\*\*\*\*   
UNID: 222222   
Game Name: Gun   
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*   
\*\*\*\*\*\*Debug weapon\*\*\*\*\*\*\*   
\*\*\*\*\*Debug Game Object\*\*\*\*\*   
UNID: 222222   
Game Name: Gun   
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  

Basically it looks like they are sharing the same instance. Anybody have any ideas of what I am doing wrong? [import]uid: 27070 topic_id: 28810 reply_id: 328810[/import]

Did this get resolved? I’m considering using this framework as well. [import]uid: 75226 topic_id: 28810 reply_id: 134155[/import]

Hi,
Since I haven’t used OWL, I am not 100% certain,but that should fixed the problem:

function Weapon:init(params)  
 print("\*\*\*\*\*\*Weapon Constructor Called\*\*\*\*\*");  
 self.super\_class.init(self,params)  
end  

super\_class method accesses to the superclass , which is Weapon table. Calling this with a colon (:slight_smile: will actually pass the Weapon table a a self parameter to the init function, what wouldn’t achieve the desired behaviour. So you have to pass explicitely the instance as a self parameter.

I am maintaining a 30-lines library for object orientation named 30log, though it is more framework-agnostic (i.e it doesn’t have have hardocoded mechanisms for Corona’s objects), just pure Lua. But it works fine :slight_smile: [import]uid: 142361 topic_id: 28810 reply_id: 134182[/import]

Did this get resolved? I’m considering using this framework as well. [import]uid: 75226 topic_id: 28810 reply_id: 134155[/import]

Hi,
Since I haven’t used OWL, I am not 100% certain,but that should fixed the problem:

function Weapon:init(params)  
 print("\*\*\*\*\*\*Weapon Constructor Called\*\*\*\*\*");  
 self.super\_class.init(self,params)  
end  

super\_class method accesses to the superclass , which is Weapon table. Calling this with a colon (:slight_smile: will actually pass the Weapon table a a self parameter to the init function, what wouldn’t achieve the desired behaviour. So you have to pass explicitely the instance as a self parameter.

I am maintaining a 30-lines library for object orientation named 30log, though it is more framework-agnostic (i.e it doesn’t have have hardocoded mechanisms for Corona’s objects), just pure Lua. But it works fine :slight_smile: [import]uid: 142361 topic_id: 28810 reply_id: 134182[/import]