Stop and active button

Hello people :slight_smile:

i have a code that make what i need, but have one point that i need to change i have a button that is red and create block then touched, and have a other button that should stop the event listener of this red button, see that:

  
display.setStatusBar( display.HiddenStatusBar )  
  
 local game\_stop = function()  
  
local gameactive = true  
  
local paused = false  
  
local pause\_button= display.newRect( 250, 20, 50, 50 )  
pause\_button:setFillColor( 255, 255, 255, 100 )  
  
  
local function pause()  
  
if paused == false then  
gameactive=true  
  
elseif paused == true then  
gameactive=false  
  
end  
end  
pause\_button:addEventListener("tap", pause)  
  
local spawner = display.newRect( 20, 3, 20, 25 )  
 spawner:setFillColor(150, 0, 0)  
 -- physics.addBody(spawner, "static", {isSensor = true})  
  
 local function spawnMyObject (event)  
 if event.phase == "began" then  
  
  
  
 block1 = display.newRect( 50, 50, 50, 50 )  
 block1:setFillColor( 255, 255, 255, 100 )  
  
 -- physics.addBody(block1, "kinematic", { density=2, friction=0, bounce=0})  
 end   
 end  
 if gameactive==true then  
 spawner:addEventListener("touch", spawnMyObject)  
 elseif gameactive==false then  
 spawner:removeEventListener("touch", spawnMyObject)  
 end  
  
end  
game\_stop()  

i need to when i touch on the pause button i need to change the active game variable, true or false, because when i do the if statement it will check the value of gameactive variable, and is allow to create the block or no

Thanks for all the helpers [import]uid: 26056 topic_id: 16931 reply_id: 316931[/import]

look to the if statement below, it works fine but if i touch on the pause_button i need to change the variable gameactive to true or false and it isnt run good :confused: the if statement only see that i declarate the variable gameactive=true on top of code, and dont see my function pause(), really need help because it will very used and important on the game :confused: [import]uid: 26056 topic_id: 16931 reply_id: 63572[/import]

up [import]uid: 26056 topic_id: 16931 reply_id: 63669[/import]

I am not sure what exactly you are trying to achieve; you want to spawn a block when you touch the red button - unless you’ve touched the gray button? Or something like that?

Sorry, you just need to be very specific with these things. (Although it’s good you’re posting plug and play code.)

Peach :slight_smile: [import]uid: 52491 topic_id: 16931 reply_id: 63732[/import]

hi peach, i run this code and when i touch on spwaner i can create blocks but when i touch on the pause_button i want to remove the spawner event listener, to cant create blocks, i am trying to make a pause button and saw your code on techority and is simple and good but i cant stop this spawner on my code :confused: because i build the code like Ghosts vs. Monsters, some like.

[code]
function new

–variables here

local myball = function()
–here, only code for the ball
end

local myspawner = function()
–here, only code for the myspawner
end

local mypause = function()
–here only code for the mypause
end

local game =function()
mypause()
myball()
myspawner()
end

game()

end

my code is some like it, and i have a function to pause button, and i need when i touch on the pause function, i want to disable all event listeners like spawner listener, but this spawner listener is on another function, and i cant stop the button :confused: i really to understand this part, is very importante [import]uid: 26056 topic_id: 16931 reply_id: 63750[/import]

up [import]uid: 26056 topic_id: 16931 reply_id: 63912[/import]

Please don’t bump quite so often; if you need an answer in a mad rush use this link instead; http://www.anscamobile.com/corona/support/

Now, the below should hopefully do what you want; it’s not perfect I just messed with your code a little bit. I think this is what you were after;

[lua]display.setStatusBar( display.HiddenStatusBar )

local game_stop = function()

local gameactive = true

local paused = false

local spawner = display.newRect( 20, 3, 20, 25 )
spawner:setFillColor(150, 0, 0)
– physics.addBody(spawner, “static”, {isSensor = true})

local function spawnMyObject (event)
if event.phase == “began” then

block1 = display.newRect( 50, 50, 50, 50 )
block1:setFillColor( 255, 255, 255, 100 )

– physics.addBody(block1, “kinematic”, { density=2, friction=0, bounce=0})
end
end
if gameactive==true then
spawner:addEventListener(“touch”, spawnMyObject)
elseif gameactive==false then
spawner:removeEventListener(“touch”, spawnMyObject)
end

local pause_button= display.newRect( 250, 20, 50, 50 )
pause_button:setFillColor( 255, 255, 255, 100 )
local function pause()

if paused == false then
gameactive=true
paused = true
spawner:removeEventListener(“touch”, spawnMyObject)

elseif paused == true then
gameactive=false
paused = false
spawner:addEventListener(“touch”, spawnMyObject)
end
end
pause_button:addEventListener(“tap”, pause)

end
game_stop()[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 16931 reply_id: 63974[/import]

sorry about the “up” posts, but that problem was very important and used on my code and i really need a fast help :confused: Thank you peach for your help and it resolve my problem, the code that you posted works fine, have some errors but I have corrected, thanks again peach this part is really important because i use a lot :slight_smile: [import]uid: 26056 topic_id: 16931 reply_id: 64059[/import]

That’s fine andre - but if you really need a fast answer, you’ve got to use the link I posted rather than bumping too much - we can’t have paying users neglected either you know :wink:

Peach [import]uid: 52491 topic_id: 16931 reply_id: 64203[/import]