Problems with Functions
BlitzPlus Forums/BlitzPlus Programming/Problems with Functions
| ||
In this game I am making I have a death screen were the player can choose either to retry the game, or exit. The player chooses by pressing either one or two. When the player exits, the game calls on an exit function, which works perfectly. But when the player wants to retry, the program calls on the function that creates the level, but instead of working, the game crashes, what is going wrong? This is the StartLevel() Function: And here is the DeathScreen() Function: |
| ||
you deleted your players and your enemys and you didn't tell it run through a main loop so when it does the functions instructions it ends the program. |
| ||
So how do i fix that? |
| ||
first put your load player code in a function and put your main loop in a function and call load player and such in the function you call in the restart. the put run() [your main loop function] in at the end. heres an examplefunction run() While Not KeyHit(1) Cls DrawLevel() TestInput() TestEnemy() TestCollision() Timer() DrawHUD() Flip Wend end function Function restart() loadplayer() loadenemy() loadworld() run() endgame() End Function |
| ||
What do you mean by load player? |
| ||
its a function that loads the player. example function loadplayer() p.player=new player p\im=loadimage("image1.bmp") p\x=400 p\y=300 p\otherstuff=more_other_stuff end function |
| ||
But I already did that as a global type |
| ||
Never mind, i get what you are saying, Thank you very much. |