Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
whats wrong with this code? (very short) — Gideros Forum

whats wrong with this code? (very short)

HarrisonHarrison Member
edited January 2014 in General questions
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

  • eezingeezing Member
    edited January 2014
    The 's' in your object is lowercase here:

    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.
  • HarrisonHarrison Member
    edited January 2014
    i tried to fix it... but
    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
    “ 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
  • You've now got an uppercase 'S' on 'stage' in the final stage:addChild(shape). Is that the problem?
  • ahh.. so when i write something it should be lowercaseUppercaseUppercase etec.
    thanks guys!
    “ 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
  • MellsMells Guru
    edited January 2014
    @Harrison
    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:
    local myShape = Shape.new()
    if you want.

    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 :
    stage = Stage.new(parameters)
    Same for :
    application = Application.new(parameters)

    Once multi stages are available (as discussed by Atilim a while ago) you will probably have the ability to do :
    myStage1 = Stage.new(parameters)
    myStage2 = Stage.new(parameters)


    In books, I like when they use specific names to show that the user has freedom to name his variables.
    Your code would be :
     
    -- ###############################
    -- DONE FOR YOU BY GIDEROS. DON'T DO IT. HERE FOR CLARIFICATION
    -- -> stage = Stage.new()
    -- ###############################
     
    -- Create myImage
    local myTexture = Texture.new("images/ball.png")
    local myImage = Bitmap.new(myTexture)
    myImage:setPosition(40,40)
    stage:addChild(myImage)
     
    -- Create myShape
    local myShape = Shape.new()
    myShape:setLineStyle(5, 0Xff0000,1)
    myShape:setFillStyle(Shape.SOLID,0x0000ff,0.5)
    myShape:beginPath()
    myShape:moveTo(0,0)
    myShape:lineTo(0,100)
    myShape:lineTo(100,100)
    myShape:lineTo(100,0)
    myShape:closePath()
    myShape:endPath()
    myShape:setPosition(40,40)
    stage:addChild(myShape)
    Does that help to clarify?

    Other devs with more experience might correct me if I'm wrong / or if more clarifications are need.



    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • yeah, thanks. that is perfect.
    “ 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
  • MellsMells Guru
    edited January 2014
    last thing, you can use
     < pre lang="lua" >your code here< /pre >
    to have your code formatted (remove spaces).
    It's easier to for us to scan your code that way, and for you to get quick and relevant answers.
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
Sign In or Register to comment.