Is there a way to make the main script stop until an if statement is met then continue with the script?

Hello, I am making a pen clicking simulator that will have updates to the pens when you click it x amount of times. In the upgrade one part I am having trouble. It skips over the if statement at the bottom. is there a way to make the script stop until the if statement is met? Or maybe an else function to send it back to a certain line so it will eventually hit the if statement? Thanks in advance y’all are great.

-- Upgrade1.0 function local function upgrade1(event) if(event.phase == "ended") then audio.play(click) penclicklevel = penclicklevel - 1 penbodyrect = "one/pen.png" end end -- Upgrade1.0 button upgrades1 = widget.newButton { width = 45, height = 35, defaultFile = "images/upgrade1.0.png", onEvent = upgrade1, alpha = 0, } upgrades1.x = 4000 upgrades1.y = 200 if (penclicklevel \> 1) then upgrades1.x = 200 penclicklevel = penclicklevel \* 2 end

Corona is event-based, there is no ‘main loop’ built in, you have to create one via timers or listeners.

What this means is that your code that checks the penclicklevel runs once, unless you tell it to run again. 

However, in this case, the simplest solution is to put that code inside a function, and call that function whenever penclicklevel is updated:

  local upgrades1 = widget.newButton {     width = 45,     height = 35,     defaultFile = "images/upgrade1.0.png", onEvent = upgrade1, alpha = 0, }   upgrades1.x = 4000 upgrades1.y = 200   local checkPenClickLevel = function ()     if (penclicklevel \> 1) then     upgrades1.x = 200     penclicklevel = penclicklevel \* 2   end   end   -- this code does not run until called with checkPenClickLevel()     local function upgrade1(event) if(event.phase == "ended") then          audio.play(click)         penclicklevel = penclicklevel - 1         penbodyrect = "one/pen.png"         checkPenClickLevel()     end end