whats wrong with this code?
i was follwing along with ar2rsawseen's book,and this happened:
print("hello world")
local texture = Texture.new("images/ball.png")
local image = Bitmap.new(texture)
image:setPosition(40,40)
stage:addChild(image)
local shape = Shape.new()
shape:setLineStyle(5, 0Xff0000,1)
shape:setFillStyle(Shape.SOLID,0x000ff,0.5)
Shape:beginPath()
Shape:moveTo(0,0)
shape:lineTo(0,100)
shape:lineTo(100,100)
shape:lineTo(100,0)
shape:closePath()
shape:endPath()
shape:setPosition(40,40)
stage:addChild(shape)
returns:
main.lua:5: calling 'beginPath' on bad self (Shape expected, got table)
stack traceback:
main.lua:5: in main chunk
main.lua:9: calling 'beginPath' on bad self (Shape expected, got table)
stack traceback:
main.lua:9: in main chunk
main.lua:9: calling 'beginPath' on bad self (Shape expected, got table)
stack traceback:
main.lua:9: in main chunk
it could be the book, but its probably me and my bad copying skills
)
“ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill
Comments
local shape = Shape.new()
but the 's' is uppercase here:
Shape:beginPath()
Shape:moveTo(0,0)
Either this is a typo or you might not fully understand the concept. Post if you need help with the concept.
print("hello world")
local texture = Texture.new("images/ball.png")
local image = Bitmap.new(texture)
image:setPosition(40,40)
stage:addChild(image)
local shape = Shape.new()
shape:setLineStyle(5, 0Xff0000,1)
shape:setFillStyle(Shape.SOLID,0x0000ff,0.5)
shape:beginPath()
shape:moveTo(0,0)
shape:lineTo(0,100)
shape:lineTo(100,100)
shape:lineTo(100,0)
shape:closePath()
shape:endPath()
shape:setPosition(40,40)
Stage:addChild(shape)
results in:
main.lua:17: index '__userdata' cannot be found
stack traceback:
main.lua:17: in main chunk
Ultimate Games on Appstore
Ultimate Games on Google Play
thanks guys!
you should explore the concept of classes (Stage, Shape > Those names are defined) and instances of classes (stage, shape > You can name it however you want).
This article on Lua Naming conventions might help also.
you could have the following:
The confusion might come from the fact that in Gideros stage is an instance of Stage that is already available for you so you can not user another name.
Probably something like this is happening behind the scenes :
Once multi stages are available (as discussed by Atilim a while ago) you will probably have the ability to do :
In books, I like when they use specific names to show that the user has freedom to name his variables.
Your code would be :
Other devs with more experience might correct me if I'm wrong / or if more clarifications are need.
It's easier to for us to scan your code that way, and for you to get quick and relevant answers.