|
If |
|
if (expression) then { coding; }
If expression is true, the block will be executed. The if statement checks to see whether the next expression is true or false. If it is true then the if statement tells the computer to execute the expression after the then. In this case if the expression is true then coding; will be executed. If expression is false then coding; will not be executed and the computer will go on past this if statement to subsequent coding. It is not necessary to put the then in, the computer will run the program just the same.
--oOo--
Example: We are making a game, at the end of level 1 we have a boss that we fight and we want it so that if we finish level 1 and we have less then 100 score then we restart the level. Level 1 ends when you defeat the boss, so we might as well put it in the destruction event of the boss. We will need the game to check if we have 100 score, and if we don't have that much it will restart the level. So we will need to write some code that will do this for us. We looked up the code for restarting a room, room_restart(), now all we need to do is write the code that will restart it if score is less then 100.
"If expression is true then the block will be executed" that is from the information of the if statement. In this case score<100 is our expression, and room_restart() is in our block, therefore if score<100 is true then room_restart() will be executed. score<100 will only be true if score is less then 100, so this code fits our needs perfectly.
Abyssal_Nuclei - Revision #1
|