08-03-2009, 10:54 PM
If statements check to see if a condition is true, then acting on that information. There's plenty of functions they can serve, for example:
-A bullet is fired by a player towards an enemy. An "if bullet is within x meters of enemy" method would be used to check to see if the bullet hits.
-The bullet does hit and the enemy's health goes down by a certain amount. An "if health is greater than zero" method would be used to check to see if the enemy is dead.
-The enemy is still alive, and now tries to attack the player. More if statements would be used to see if the player was close enough for the enemy to counterattack, if the enemy's attack hit, and so on.
If statements are primarily useful for games and other such interactive programs in which conditions must be constantly monitored for proper function of the Alice world.
|