How to give the player an extra life?

Blitz3D Forums/Blitz3D Beginners Area/How to give the player an extra life?

Check the score every time it's increased to see if it qualifies for a bonus life. If the code above is in the main loop, it's being looked at every single loop...as long as your score is 25000 or higher, it's going to keep adding 1 life every loop. Try using a function and calling that function only when the score is increased. Here's what I mean...


Global EnemyLife = 100
Global PlayerScore = 0
Global PlayerLives = 3

; Main Loop

If MyShotHitEnemy = True Then EnemyLife = EnemyLife - 10

If EnemyLife = 0 ; Enemy is Dead
   PlayerScore = PlayerScore + 100 ; Increase the Player's Score
   CheckScore() ; Run the CheckScore Function
   EnemyLife = 100 ; Reset the Enemy's life (or delete this enemy and create a new one) so this doesn't keep looping
EndIf

; End Main Loop

Function CheckScore()

If PlayerScore = 25000 Then PlayerLives = PlayerLives + 1
If PlayerScore = 50000 Then PlayerLives = PlayerLives + 1
If PlayerScore = 100000 Then PlayerLives = PlayerLives + 1

End Function