Noob issue: avoiding referencing variables

Hey Guys,

I’m pretty new to LUA so forgive me for my lack of insight. I’m trying to keep from referencing variables directly as recommended but I can’t seem to get the external function to pass the method through. My app keeps crashing the simulator and tells me that “object” is “a nil value” but from my understanding, I thought that rBloon would get passed through since I feed Self(should it be rBloon) into it. Even if I pass rBloon specifically through it tells me the method applyForce is now nil.

Please steer me in a direction. Thanks!

[code]

local function floatForce(object)
object:applyForce( 0, -.1, object.x, object.y )
end

local function spawnBloon()
local rBloon = display.newCircle(180, 200, 10 )
–MAKE IT FLOAT
function balloonFloat()
floatForce(self)
end
Runtime:addEventListener(“enterFrame”, balloonFloat)
end

–CLICK RED
local function clickRedButton(event)
local phase = event.phase
if “ended” == phase and gameReady == true then

if rBloonCur == 0 then
rBloonCur = rBloonCur + 1
–IF NO BLOON CREATE IT AND MAKE IT FLOAT
spawnBloon()

elseif rBloonCur >= 1 and rBloonCur <= 2 then
rBloonCur = rBloonCur + 1
elseif rBloonCur == 3 then
print(“pop!”)
rBloonCur = 0
–Remove Bloon
popBloon(rBloon)
rBloonTot = rBloonTot + 1

end

print("current RedBloon Size " … rBloonCur)
end
end
bloonRedButton:addEventListener(“touch”, clickRedButton)

end[/code] [import]uid: 10361 topic_id: 7080 reply_id: 307080[/import]

On line 11 you call “floatForce(self)” but “self” doesn’t exist. You should be calling “floatForce(rBloon)”

Then the reason object:applyForce() generates an error is because you never add a physics body to “rBloon.” Refer to the API for physics. [import]uid: 12108 topic_id: 7080 reply_id: 24930[/import]

Thanks J!

You know, I had it all working by directly referencing the variables then I realized I had a problem on my hands when I was trying to nil out and remove things, so I started creating those functions. My addBody which was there for rBloon took the backseat somehow when rebuilding. Stupid mistake :wink:

That, and I’m Still wrapping my mind around the passing of objects to one another.

So when I finally get to the chance of removing rBloon from the screen, will the fact that I’m calling floatForce(rBloon) prevent me from doing so?

-josh [import]uid: 10361 topic_id: 7080 reply_id: 24939[/import]