Problems with Functions

BlitzPlus Forums/BlitzPlus Programming/Problems with Functions

ShaunVonSuffern(Posted 2008) [#1]
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:



mtnhome3d(Posted 2008) [#2]
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.


ShaunVonSuffern(Posted 2008) [#3]
So how do i fix that?


mtnhome3d(Posted 2008) [#4]
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 example

function 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



ShaunVonSuffern(Posted 2008) [#5]
What do you mean by load player?


mtnhome3d(Posted 2008) [#6]
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



ShaunVonSuffern(Posted 2008) [#7]
But I already did that as a global type


ShaunVonSuffern(Posted 2008) [#8]
Never mind, i get what you are saying, Thank you very much.