Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

I need help

edited July 2013 in Questions Posts: 3

I have just started messing around with codea and I found a tutorial and did it it had me write out a code but every time i run this code it comes up with an error and says I am attempting to index a nil value
Here is the code

function setup()
    x=50
    y=50
    d=60
    dx=2
    dy=1
end

function draw()    
    background(200,200,200,255)
    pushStyle().
    fill(255,0,0,255)
    x=x+dx
    y=y+dy
    ellipse(x,y,d)
    popStyle()
    if x<d/2 or x>WIDTH-d/2 then dx=-dx end
    if y<d/2 or y>WIDTH-d/2 then dy=-dy end
end

Any help would be greatly appreciated

Comments

  • edited July 2013 Posts: 8

    Remove the dot after push style. You'll then see a red circle move.

    As is Codea tries to index the result of the push style call with fill.

  • Posts: 3

    Thank you so much I feel really stupid

  • IgnatzIgnatz Mod
    Posts: 5,396

    We all feel stupid sometimes. It's part of programming!

  • Posts: 391

    The great thing about the debugging output is that it will point you to the location of the error, for the most part. You were receiving the following error:

    error: [string "function setup()..."]:12: attempt to index a nil value

    This lets you know that the problem lies within the setup() function and around line 12. The actual problem was on line 11 (technically after line 11 but before line 12 since it was an additional character error), but you can definitely see how close it gets you to the problem.

    Hope this helps you locate any future errors you run into.

Sign In or Register to comment.