Time for action –making win and lose conditions
For any game alerts to even appear during game play, we need to create some if
statements for every possible scenario available in each level. When this occurs, the score needs to be reset back to zero. To make the win and lose conditions, follow these steps:
Below the
alertScreen()
function, create a new function calledrestart()
:function restart()
Create an
if
statement for a"win"
game event when the first level has been completed and transitions to level 2:if gameEvent == "win" and currentLevel == 1 then currentLevel = currentLevel + 1 changeLevel2() levelNum.text = tostring(currentLevel)
Note
The
tostring()
method converts any argument to a string. In the preceding example, thecurrentLevel
value changes from1
to2
when a"win"
game event occurs. The value will convert to a string format that thelevelNum
text object can display on screen for level 2.Add an
elseif
statement for a"win"
game event when the second level has been...