[Resolved] Non error error

Hi

So the code works in 840… But when I click the rectangle it works but terminal gives this error, the code behaves and works like nothing is wrong… Very strange… Something I need to worry about??

error: …Desktop/untitled folder/test/test 2/main.lua:13: attempt to index upvalue ‘bv’ (a nil value)

thanks
Jeremy
Code:
local bv = display.newImage( “BirdVect1S.png”)
bv.x = 300
bv.y = 400

local myRectangle = display.newRect(0, 0, 150, 50)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180)
myRectangle.x = 200
myRectangle.y = 200

local function showB2 (event)
bv:removeSelf( )
bv = nil
local bvg = display.newImage( “BirdGr1S.png”)
bvg.x = 300
bvg.y = 400
end
myRectangle:addEventListener (“touch”, showB2)

[import]uid: 127028 topic_id: 27885 reply_id: 327885[/import]

Thank you sir.-- Yes bv is there, it’s a bird picture Your code works and I learned something about debugging and program logic.

thanks much,
Jeremy
[import]uid: 127028 topic_id: 27885 reply_id: 112895[/import]

Jeremy ,

You`re welcome!

Glad you got it working without errors.
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 27885 reply_id: 112902[/import]

Just trying:

Change your code into the function regarding your “bv” object to:

[lua]local function showB2 (event)

if bv ~= nil then
bv:removeSelf( )
bv = nil
end
print(bv) – just to be sure it`s really getting nil and removed!

local bvg = display.newImage( “BirdGr1S.png”)
bvg.x = 300
bvg.y = 400
end
myRectangle:addEventListener (“touch”, showB2)[/lua]
By this way you are checking if the “bv” object is really there before trying to remove it at all.
Hope this helps.

Rodrigo. [import]uid: 89165 topic_id: 27885 reply_id: 112886[/import]