Button question

Whenever i click the button, it gives an error:

Attempt to index global ‘PauseBtn’ (a nil value)

How can PauseBtn be a nil value, i just created that button and created properties to it? (isVisible, isActive)

[code]
display.setStatusBar( display.HiddenStatusBar )

local ui = require(“ui”)

– PAUSE BUTTON
local function onPauseTouch ()

pauseBtn:toFront()

end

local pauseBtn = ui.newButton {
default = “pausebtn.png”,
over = “pausebtn-over.png”,
onPress = onPauseTouch,
x = 65,
y = 65
}

pauseBtn.isVisible = true
pauseBtn.isActive = false

[/code] [import]uid: 50459 topic_id: 12607 reply_id: 312607[/import]

Try

 pauseBtn = ui.newButton {  
 default = "pausebtn.png",  
 over = "pausebtn-over.png",  
 onPress = onPauseTouch,  
 x = 65,  
 y = 65   
}  
  

Instead of

[code]

local pauseBtn = ui.newButton {
default = “pausebtn.png”,
over = “pausebtn-over.png”,
onPress = onPauseTouch,
x = 65,
y = 65
}

[/code] [import]uid: 24111 topic_id: 12607 reply_id: 46131[/import]

Thank you!

[import]uid: 50459 topic_id: 12607 reply_id: 46133[/import]

Alternatively, you could have put the function below the button in the code if you wish to keep it local.

Peach :slight_smile: [import]uid: 52491 topic_id: 12607 reply_id: 46231[/import]

Peach, can you explain how to do that?

Because if i define the button first, and below that code i write the Function, the button does nothing. I thought you had to write the function first, then define the button.

I removed the local word to avoid the errors i had. But now when i want to remove a button with removeSelf, the simulator crashes.

[import]uid: 50459 topic_id: 12607 reply_id: 46233[/import]

Sorry double post [import]uid: 50459 topic_id: 12607 reply_id: 46234[/import]

Sorry, I didn’t word that well at all.

What I meant was you could declare it first; there’s a good example in Ghosts VS Monsters.

Peach :slight_smile: [import]uid: 52491 topic_id: 12607 reply_id: 46391[/import]