Where in storyboard to define object and set image?

Hello,

I know I have asked a lot on the storyboard and Rob has helped a lot. But if I can just grasp this a little more I will have it.

I have a basic game with one level like angry birds where I am throwing an object. Right now I am defining the object at the stop outside of any storyboard functions. It is called shoe because I am throwing a horse shoe. So at the top I am saying:

local shoe

In the enterScene function of the storyboard I have:

shoe = display.newImage( "gfx/shoe1.png",186,287)

And then at the bottom of the code outside of any storyboard functions I have:

function loop(e) local targetx = 300 - shoe.y if shoe.y \< 200 then local d = (game.y - (shoe.y - 200) ) d = d - game.y if game.y \< 950 then game.y = d end end end

I get an error on line 814 which is the first line of the function above saying attempt to index upvalue ‘shoe’ (a nil value) … Normally I get it as shoe is not defined. Attached is the entire program. I need it working in a storyboard because it will be one scene of an app. I had it working when everything was outside of the functions but it would not reload the scene. And no objects are added to the storyboard’s view. Where would I define each part of the var shoe? Maybe that would help me get the rest working right.

Thanks!

I would suggest placing your function inside the enterScene since you have predeclared shoe.  Place it after:

shoe = display.newImage( “gfx/shoe1.png”,186,287)

,  or you could place if after you define

local shoe

before createScene.

I would suggest placing your function inside the enterScene since you have predeclared shoe.  Place it after:

shoe = display.newImage( “gfx/shoe1.png”,186,287)

,  or you could place if after you define

local shoe

before createScene.

I’m trying to swap out an avatar image created in a button reference in the createScene call:

local off = display.newImageRect( “kidwithdisk.png”, system.DocumentsDirectory, 142, 205 )

local on = display.newImageRect( “kidwithoutdisk.png”, system.DocumentsDirectory, 142, 205 )

    on.alpha = 0;

    off.alpha=1

    group:insert(on)

    group:insert(off)

since it’s an imageRect, I tried to nil it out and replace it with the updated files copied to the DocDirectory in an enterScene call, but all hell broke out with errors similar to warrenswav’s. I tried to create and update the buttons completely in an enterScene script and fell into a similar hell of confused forward references. what’s the best practice for updating images created in the createScene?

THANKS!

I’m trying to swap out an avatar image created in a button reference in the createScene call:

local off = display.newImageRect( “kidwithdisk.png”, system.DocumentsDirectory, 142, 205 )

local on = display.newImageRect( “kidwithoutdisk.png”, system.DocumentsDirectory, 142, 205 )

    on.alpha = 0;

    off.alpha=1

    group:insert(on)

    group:insert(off)

since it’s an imageRect, I tried to nil it out and replace it with the updated files copied to the DocDirectory in an enterScene call, but all hell broke out with errors similar to warrenswav’s. I tried to create and update the buttons completely in an enterScene script and fell into a similar hell of confused forward references. what’s the best practice for updating images created in the createScene?

THANKS!