It looks like you're new here. If you want to get involved, click one of these buttons!
vehicle = gideros.class(Sprite) function vehicle:init(name, speed, passengers) self.name = name self.speed = speed self.passengers = passengers end ------------------------------------ plane = gideros.class(vehicle) function plane:init(name, speed, passengers, height) self.height = height -- in here should I call the vehicle's init?? end ------------------------------------ vehicleTest = gideros.class(Sprite) function vehicleTest:init() obj = plane.new("name", 100, 30, 3000) print(obj.height) print(obj.passengers) end |
Comments
meaning when function plane:init is called, all the name, speed, etc properties should already be set, because vehicle:init already did that
I just tried your example and it works as expected, printing all the attributes
Which Gideros Version are you using?
I'm using Gideros v2014.01 for windows
Here is my test result, that works correctly for me
Let me test your last comment...
So I tried your exact code and it prints
nil nil nil 3000
But I would preffer doing it my way, cause my actual code is pretty large, that's just a test code. So, any thoughts why it doesn't work separating the files?
it makes sense now
click on the plain.lua in your project manager and select Code Dependencies
and there select vehicle.lua
So it would always load vehicle class before plain class
Likes: somezombiegm
One more thing. I change the plane class parameters leaving only height and it still works:
And it should not have worked with simply height
if you only accept height in plane, then height should have value "name"
Likes: somezombiegm
in you example self.height should be name.
Can you post a complete example for me to try
vehicle.lua
Thanks a lot for your help!
@ar2rsawseen Thanks