Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Object:getClass() — Gideros Forum

Object:getClass()

totebototebo Member
edited March 2016 in General questions
In the docs it says Object:getClass() "Returns the class name of the instance as string".
http://docs.giderosmobile.com/reference/gideros/Object/getClass

When I use it, however, it instead returns the name of the Gideros class it inherits from (ie. "Sprite") or, if a custom class, it returns "Object".

I strongly feel I'm missing something. Please help!
My Gideros games: www.totebo.com

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited March 2016
    unfortunately it can't return the name of your own custom classes, cause we can't tell how you name the variable.
    It only returns Gideros class names.

    You can overwrite it though like
    MyClass = Core.class(Sprite)
     
    function MyClass:init()
        self.__classname = "MyClass"
    end
     
    print(MyClass.new():getClass()) -- should print MyClass
  • hgy29hgy29 Maintainer
    Being able to write:
    MyClass = Core.class(Sprite,"MyClass")
    would be a good shorthand to add to Gideros I think.
  • Ok, thanks guys.

    I opted for a similar workaround, returning the actual global class instead for easy instantiating:
    function MyClass:getClass()
    	return MyClass
    end
    My Gideros games: www.totebo.com
Sign In or Register to comment.