Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Inheritance — Gideros Forum

Inheritance

click2installclick2install Member
edited November 2013 in General questions
Can someone clear this up for me please?
Scene = Core.class(Sprite);
function Scene:init()
  -- common base class for all scenes
end
SceneOne = Core.class(Scene);
function SceneOne:init()
  self:addChild(Bitmap.new(Texture.new("assets/scene1.jpg")));
  -- throws here with -> attempt to call method 'addChild' (a nil value)
end
If I make SceneOne extend Sprite it works fine with just that change.

Thanks

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @click2install it is all about file dependency
    most probably SceneOne file gets loaded before Scene file was loaded, thus
    SceneOne = Core.class(Scene);
    actually results in:
    SceneOne = Core.class(nil);
    which means it does not inherit from Sprite.

    What you would need to do, is to right click on SceneOne file in Gideros Studio, choose Code Dependencies and select the file where you have Scene defined

    and it should work ;)
  • Hi @ar2rsawseen, I thought that after I posted the question and it is definitely the correct load order. I just restarted the IDE and it is working now.

    Thanks
Sign In or Register to comment.