Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Class inheritance problem — Gideros Forum

Class inheritance problem

devfujidevfuji Member
edited March 2014 in General questions
Hello, i'm having problem with class inheritance.
i'm an experienced developer but i'm a newbie in LUA and generally in game development so please be patient if this is a stupid question.

i have
Class1=Core.class(Sprite)

in another file i have

class2=Core.class(Class1)

class2:init()

self:addChild(Bitmap.new(tRegion))
--tRegion is a valid TextureRegion object created just before
end


i'm receiving this error: attempt to call method 'addChild' (a nil value)

obviously if i make class2 inherit Sprite instead of Class1 the code works fine.

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    it means, most probably, the order of execution is wrong

    class2 file is loaded before class1 file (so by that time Class1 does not exist) and you do not inherit from anything

    What you need to do is right click in project manager on class2 file and select code dependencies and select class1 file ther

    ;)

    Likes: devfuji

    +1 -1 (+1 / -0 )Share on Facebook
  • Hi @ar2rsawseen , thanks for your reply.
    Unfortunately i've already set what you mean.
    Class2 file already have the dependency to class1 file set in the properties.

    Just to help actually i have the project opened both in Gideros IDE (where i set files and dependencies) and in ZeroBrane studio where i actually write code.

    All needed file are included.
    a thing i noticed during debug is that the class1:init() code is never called. I don't know if this is a bug of ZeroBrane debugger or if actually this is a confirm to the sympthom you wrote (that's i'm effectively inherithing nothing)...

    Anyway i noticed that if i try to inherit from a class never defined, an error is raised on run... but in my case no error is run so i imagine the inheriting is working fine...

    really confused.
  • Oops, it now worked.
    i've just restarted the Gideros IDE and checked that class2 have dependency on class1 (yes it already had), now run and worked fine.

    Probably there was some conflict on project file savings or whatever i cant imagine.

    thanks anyway!
Sign In or Register to comment.