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]