Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Possible error in the Gideros Mobile Game Development book? — Gideros Forum

Possible error in the Gideros Mobile Game Development book?

wheaticuswheaticus Member
edited September 2015 in Step by step tutorials
Howdy, I'm totally new at Gideros and I've recently picked up the 2013 Packt book, Gideros Mobile Game Dev. However, straight out the gate in chapter 2 (bottom of page 44) I'm receiving an error when it is indicated that this code would correct the intentional problem (from the page before). It is frustrating to not make progress on something so rudimentary. I feel that I've checked it many times without any indication that it has been mistyped. The image, ball.png IS in the 'images' folder. So, my question would be, could it have been possible since the publishing of the book, the current base code is no longer compatible OR is there simply an error in the book. Thank you for any help!

main.lua

local bitmap = Bitmap.new(Texture.new("images/ball.png", true))
local button = Button.new(bitmap)
stage:addChild(button)
button.lua

Button = Core.class(Sprite)

function Button:init(sprite)
print("initializing button")
self.addChild(sprite)
end
The error I'm getting is:

classes/Button.lua:5: bad argument #2 to 'addChild' (Sprite expected, got no value)
stack traceback:
classes/Button.lua:5: in function 'init'
[string "property.lua"]:52: in function '__new'
[string "property.lua"]:59: in function 'new'
main.lua:3: in main chunk

Comments

  • piepie Member
    edited September 2015 Accepted Answer
    @wheaticus I think the problem is here
    self.addChild(sprite)
    it should work if you use :
    self:addChild(sprite)
    You use : to call methods (functions) and . to refer to properties.

    A function can be defined as a property, but that is not the case :)
  • Ha! Thank you pie! Amazing how one can look at something forever and still fail to see the difference. The book even mentions in the following pages that the : and . are often what gets incorrectly interchanged with beginners.
Sign In or Register to comment.