Navigating menus

Blitz3D Forums/Blitz3D Beginners Area/Navigating menus

Hmm, i'v tried a number of things to get the effect of navigation menus, none really work i get a MAV error with some, some just don't work, so how would you do it?

this is how i'm doing it:
i call this at the top of the code before everything else (after apptitle)

Global selection=1
If selection=1 Mainmenu()
If selection=2 options()


these are the funtions, it breaks the loop and goes to the main program when you click the play button, i didnt have enough time to make myself a options button, so i make the [1] key (up top not numberpad) the key to go to the options screen

heres the functions:

Mainmenu()

Function Mainmenu()
Graphics 800,600,32,2


mainimage=LoadImage("mainmenu.png")
continue=LoadImage("Playbutton.png")
;mouse=LoadImage("mouse.png")
MaskImage continue,255,0,255



While selection=1
;mouse_x=MouseX()
;mouse_y=MouseY()
Cls


DrawImage mainimage,0,0
DrawImage continue,100,400
;DrawImage mouse,mouse_x,mouse_y
Flip

If ImageRectCollide(continue,100,400,0,MouseX(),MouseY(),5,5) And MouseHit(1)
selection=2
End If

If KeyHit(1)
End
End If

If KeyHit(2)
selection=3
End If

Delay 5
Wend

End Function


options()
Function options()
Graphics 800,600,32,2

Backbutton=LoadImage("Backbuttons.png")

DrawImage backbutton,0,0

While selection=3

If ImageRectCollide(backbutton,0,0,0,MouseX(),MouseY(),5,5) And MouseHit(1)
selection=1
End If


If KeyHit(1)
End
End If

Delay 5
Wend

End Function


its works, but when i go to the options screen and click on the back button its SUPPOST to go back to the main menu, but it goes to the game insted...

I'd like to hear your menu tips and of course how you do it.

Hi Yahfree,

You need to put a loop around your menu and game. Lets see if I can visualise this for you:

You have:
selection = 1 ; show main menu
Mainmenu() ; this shows the main menu if selection = 1
Once mainmenu ends, be it by clicking on "Options" or "Play game" then next line (Options()) runs.
If you clicked on Options, selection now equals 3 and the options menu is displayed.
If you didn't click on Options, the options() function runs but quits immediately.
After the options() function has ended, it continues to the rest of you game.

What you need is something like this: (note this is not actual useable code, just pseudo code)

selection = 1 ; open main menu first
while not keyhit(1) ; loop until ESC is pressed
  if selection = 1 then
    mainmenu() ; main menu sets selection to 2 if the play game button is pressed or sets selection to 3 if the options button is pressed.
  elseif selection = 2 then
    playgame() ; move game code into its own function.  When game ends set selection = 1 again to show the main menu.
  elseif selection = 3 then
    options() ; display the options menu.  When the back button is pressed, set selection to 1 and the main menu will be shown.
  end if
wend


The top "while not keyhit(1)" loop is not great practice to be honest and you would be better assigning a variable to control the running of this main loop so you can set it where you like in your code (based on a keypress or on a menu button press).

Hope this helps.

Tim

This is what i tried:

on the main page (note not all my code just showing what has to do with the menus)

took almost everything out of my maincode page and put it in a function called playgame()
Global selection=1
;If selection=1 Mainmenu()
;If selection=2 playgame()
;If selection=3 options()

While Not KeyHit(1) ; loop until ESC is pressed
  If selection = 1 Then
    Mainmenu() ; main menu sets selection to 2 if the play game button is pressed or sets selection to 3 if the options button is pressed.
  ElseIf selection = 2 Then
    playgame() ; move game code into its own function.  When game ends set selection = 1 again to show the main menu.
  ElseIf selection = 3 Then
    options() ; display the options menu.  When the back button is pressed, set selection to 1 and the main menu will be shown.
  End If
Wend


My Mainmenu() function
Function Mainmenu()
Graphics 800,600,32,2


mainimage=LoadImage("mainmenu.png")
continue=LoadImage("Playbutton.png")
;mouse=LoadImage("mouse.png")
MaskImage continue,255,0,255



While Not KeyHit(1)
;mouse_x=MouseX()
;mouse_y=MouseY()
Cls


DrawImage mainimage,0,0
DrawImage continue,100,400
;DrawImage mouse,mouse_x,mouse_y
Flip

If ImageRectCollide(continue,100,400,0,MouseX(),MouseY(),5,5) And MouseHit(1)
selection=2
End If


If KeyHit(2)
selection=3
End If

Delay 5
Wend

End Function


my options() function

;Options
Function options()
Graphics 800,600,32,2

Backbutton=LoadImage("Backbuttons.png")

DrawImage backbutton,0,0

While Not KeyHit(1)

If ImageRectCollide(backbutton,0,0,0,MouseX(),MouseY(),5,5) And MouseHit(1)
selection=1
End If



Delay 5
Wend

End Function


my playgame() function
Function playgame()

Graphics 800,600,32,2
;Mid handles all of the images and creates a image called paddle.
HidePointer

AutoMidHandle True
   paddle=CreateImage(70,15)
   ball=CreateImage(10,10)
AutoMidHandle False
   pausedpic=LoadImage("Paused.png")

;draws on the empty image container..
SetBuffer ImageBuffer(paddle)
   Rect 0,0,70,15,1
SetBuffer ImageBuffer(ball)
   Oval 0,0,10,10,1
SetBuffer BackBuffer()

;Copys the ball image 3 times these will be our lifes displayed on the bottom of the screen.
   life1=CopyImage(ball)
   life2=CopyImage(ball)
   life3=CopyImage(ball)

While Not KeyHit(1)
Cls


;Calls functions.
addplayercontrols()
drawmyimages()
addcollisions()
addtext()

;conditional functions
If KeyHit(P)
   Pause(pausedpic)
End If

;small delay in the loop for less slow down.
;flips, ends the loop and termanates the program..
Delay 5
  Flip
Wend
End

End Function



Doesnt work.. it shows the main menu, but when clicking on the play button (change selection to = 2, in thoery calling the playgame() function.)

but it just sits there...

Hi yahfree,

Thanks for the additional bits. I have found some mistakes and I have a working version here now however, I need some time to show you the changes so you can understand. I will attach the new code here for now, but I will explain some more if I get chance tomorrow.

Global selection
Global ingame
ingame = 1
selection = 1
;If selection=1 Mainmenu()
;If selection=2 playgame()
;If selection=3 options()

While ingame = 1 ; loop until ESC is pressed
  If selection = 1 Then
    Mainmenu() ; main menu sets selection to 2 if the play game button is pressed or sets selection to 3 if the options button is pressed.
  ElseIf selection = 2 Then
    playgame() ; move game code into its own function.  When game ends set selection = 1 again to show the main menu.
  ElseIf selection = 3 Then
    options() ; display the options menu.  When the back button is pressed, set selection to 1 and the main menu will be shown.
  End If
Wend

Function Mainmenu()
	Graphics 800,600,32,2


	mainimage=LoadImage("mainmenu.png")
	continue=LoadImage("Playbutton.png")
	;mouse=LoadImage("mouse.png")
	MaskImage continue,255,0,255



	While selection = 1
		;mouse_x=MouseX()
		;mouse_y=MouseY()
		Cls


		DrawImage mainimage,0,0
		DrawImage continue,100,400
		;DrawImage mouse,mouse_x,mouse_y
		Flip

		If ImageRectCollide(continue,100,400,0,MouseX(),MouseY(),5,5) And MouseHit(1)
			selection=2
		End If
		If KeyHit(60) Then
			selection = 2
		End If
		If KeyHit(59) Then
			selection = 3
		End If

		
		Delay 5
	Wend

End Function

;Options
Function options()
	Graphics 800,600,32,2
	
	Backbutton=LoadImage("Backbuttons.png")
	
	While selection = 3
		Cls
		DrawImage backbutton,0,0
		If KeyHit(1) Then
			selection = 1
		End If
		If ImageRectCollide(backbutton,0,0,0,MouseX(),MouseY(),5,5) And MouseHit(1)
			selection=1
		End If
		Flip
		Delay 5
	Wend

End Function

Function playgame()

	Graphics 800,600,32,2
	;Mid handles all of the images and creates a image called paddle.
	HidePointer
	
	AutoMidHandle True
	   paddle=CreateImage(70,15)
	   ball=CreateImage(10,10)
	AutoMidHandle False
	
	
	;draws on the empty image container..
	SetBuffer ImageBuffer(paddle)
	   Rect 0,0,70,15,1
	SetBuffer ImageBuffer(ball)
	   Oval 0,0,10,10,1
	SetBuffer BackBuffer()
	
	;Copys the ball image 3 times these will be our lifes displayed on the bottom of the screen.
	life1=CopyImage(ball)
	life2=CopyImage(ball)
	life3=CopyImage(ball)
	
	While selection = 2
		Cls
		If KeyHit(1) Then
			selection = 1
		End If
		
		;Calls functions.
		Text 0,0, "IN game"
		
		;conditional functions
		
		;small delay in the loop for less slow down.
		;flips, ends the loop and termanates the program..
		Delay 5
		Flip
	Wend

End Function


I didn't have your pictures and I had to remove some other stuff, hopefully you will get the main idea, but if not, just wait until I can explain more.

Thanks
Tim

That works great on going back and forth between the options thing, but why doesnt it work for back and forth between the game and the main menu?

i want it so if you press esc in the game, it goes to the main menu, if you press esc, at the main menu it quits

so i did the simple

This in the playgame() loop:
If KeyHit(1) Then
selection=1
End If


at this point selection=1 so it SHOULD return to the main menu, but instead it closes, don't know why, theres no code in the playgame() function that says termanate if keyhit(1)..

and i put this in the Mainmenu() function:
;if esc is pressed ONLY AT THE MAIN MENU quit.
If KeyHit(1)
End


it closes ok at the main menu, but when i hit ESC in the game it also closes... any ideas?

End If

If you still have all my code in, add this into the WHILE loop inside the MAINMENU function

If KeyHit(1) Then
	ingame = 0
	selection = -1
End If


Also, as you have managed without my explainations, do you want me to explain or do you understand the changes I made?

This way you can have a button on the main menu that sets the same thing and also causes the game to end.

Tim

hmm, alright, i made myself a "Options" button, but cant seem to get it to work, it only seems to work with the first button it checks, options button works if its ontop of the play button, vis versa:

;Collisions basicly making the buttons work
If ImageRectCollide(options,100,450,0,MouseX(),MouseY(),5,5) And MouseHit(1)
selection=3
End If
If ImageRectCollide(continue,100,400,0,MouseX(),MouseY(),5,5) And MouseHit(1)
selection=2
End If


Err, i just tested this code to put in the main menu, (instead of ending) and it ends the program, but ingame when i press keyhit(1) (ESC) it makes the veriable selection=1

this should bring me back to the main menu... but it decides to close it...

The problem with the imagecollide bits is that the MouseHit() function resets after it has been tested the first time, so when the second IF statement runs the number of clicks held in this function is 0 and thus the second IF never evaluates to TRUE.

What you need is either:

if MouseHit(1) then
  imagecollide stuff excluding the AND MOUSEHIT(1)
end if


OR

mouseclicked = MouseHit(1)

If ImageRectCollide(options,100,450,0,MouseX(),MouseY(),5,5) And mouseclicked
...


I also took out the DELAY 5 which was causing the results to be eratic at best.

As for your other problem, a) I dont understand and b) it works OK for me now.

Tim

Ok, that seems to work on the some buttons work some don't problem, but i still cant figure out for the life of me why i cant get it when esc is pressed to go back to the mainmenu

i'll give you all my code:
;Breakout by Yahfree
;2007-04-4 -> ????-??-(?)?
AppTitle "Breakout by Yahfree","Are you sure?"


;Globalized stuff
Global paddle, paddlex=380, paddley=560
Global ball,ballx=380, bally=580, ballxdir#=0, ballydir=-1, move=1, ballsleft=3, life1, life2, life3
Global blope=LoadSound("Beep.wav")
Global pausedpic
Global selection
Global ingame

;Constant numbers that never change..
Const ESC=1, RIGHTARR=205, LEFTARR=203, SPACE=57, MOUSE1=1, A=30, Z=44, P=25


ingame = 1
selection = 1


While ingame=1 
  If selection = 1 Then
    Mainmenu()
  ElseIf selection = 2 Then
    playgame()
  ElseIf selection = 3 Then
    options()
  End If
Delay 5
Wend




;Include "Functions.bb"


;Player controls
Function addplayercontrols()

;Paddle movemovement and controls
paddlex=paddlex+MouseXSpeed()
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
If paddlex<35 paddlex=35
If paddlex>765 paddlex=765

;Ball control.
If move=1 ballx=paddlex
If move=1 And ballx<35 ballx=35
If move=1 bally=paddley-15
If move=1 ballydir=-1 ballxdir=0
If MouseHit(MOUSE1)
   move=2
End If

;calls the moveball function if move=2
If move=2
   moveball()
End If


End Function


;Moving the ball
Function moveball()

;All physics behind moving the ball and bouncing it.
bally=bally+ballydir*10
ballx=ballx+ballxdir*10
If bally<0 ballydir=1 PlaySound(blope)
If bally>600 move=1 ballydir=-1 ballsleft=ballsleft-1
If ballx<0 ballxdir=1 PlaySound(blope)
If ballx>800 ballxdir=-1 PlaySound(blope)

End Function

;All the games collisions..
Function addcollisions()

;collisions
If ImagesCollide(paddle,paddlex,paddley,0,ball,ballx,bally,0)
   ballxdir=(ballx - paddlex)*.025
   ballydir=-1
   PlaySound(blope)
End If

End Function

;Draws the images
Function drawmyimages()

;Draws the images...
DrawImage paddle,paddlex,paddley
DrawImage ball,ballx,bally
If ballsleft>2 DrawImage life3,680,580
If ballsleft>1 DrawImage life2,700,580
If ballsleft>0 DrawImage life1,720,580
If ballsleft=0 ballsleft=3
DrawImage Backbutton,0,0

End Function

;Text maths ect...
Function addtext()

Text 0,0,selection

End Function

;Pause function,  called when P is pressed
Function Pause(picture)

FlushKeys
While Not KeyHit(P)
   DrawImage picture,0,0
   Flip
   Cls
If KeyHit(1) Then
   End
End If
  Delay 5
Wend


End Function

;!@#!@#$@#$!$#!$@#$!@$#@
;!#@!@# MAINMENU !@#!@#@
;!@#!@#!@#!@#@!#!@#!@#@#
Function Mainmenu()
Graphics 800,600,32,2

;Load/creates images
mainimage=LoadImage("mainmenu.png")
continue=LoadImage("Playbutton.png")
options=LoadImage("options.png")
MaskImage continue,255,0,255
MaskImage options,255,0,255


;Mainmenu loop
While selection=1
Cls

; draw the images
DrawImage mainimage,0,0
DrawImage continue,100,400
DrawImage options,100,450

mouseclick1=MouseHit(1)
;Collisions basicly making the buttons work
If ImageRectCollide(continue,100,400,0,MouseX(),MouseY(),5,5) And mouseclick1
selection=2
End If
If ImageRectCollide(options,100,450,0,MouseX(),MouseY(),5,5) And mouseclick1
selection=3
End If



If KeyHit(2)
selection=3
End If

;if esc is pressed ONLY AT THE MAIN MENU quit.
If KeyHit(1)
	ingame = 0
	selection = -1
End If


;delay and bye bye loop
Delay 5
Wend

End Function

;!#!@#!@#!@#!@#!@#!@#!
;!@#!@ OPTIONS !@#!@$$
;#@!#!@$#@$@#$@#$@#$@#
Function options()
Graphics 800,600,32,2


backbutton=LoadImage("Backbuttons.png")
MaskImage backbutton,255,0,255

;options loop
While selection=3
Cls

DrawImage backbutton,0,0


;Makes the buttons work
If ImageRectCollide(backbutton,0,0,0,MouseX(),MouseY(),5,5) And MouseHit(1)
selection=1
End If


;delays and bye bye loop
Delay 5
Wend

End Function

;!#$@#$@#%@!#$@#$!@#$!@#$
;@#$@#$# PLAYGAME !@#!@##
;!@#!@$@#$@#$@#$@#$@#$@#$
Function playgame()

;Graphics mode set for playgame()
Graphics 800,600,32,2
HidePointer

;Loads/Creates all the images
AutoMidHandle True
   paddle=CreateImage(70,15)
   ball=CreateImage(10,10)
AutoMidHandle False
   pausedpic=LoadImage("Paused.png")

;draws on the empty image container..
SetBuffer ImageBuffer(paddle)
   Rect 0,0,70,15,1
SetBuffer ImageBuffer(ball)
   Oval 0,0,10,10,1
SetBuffer BackBuffer()

;Copys the ball image 3 times these will be our lifes displayed on the bottom of the screen.
   life1=CopyImage(ball)
   life2=CopyImage(ball)
   life3=CopyImage(ball)


;playgame() loop
While selection=2
Cls


;Calls functions.
addplayercontrols()
drawmyimages()
addcollisions()
addtext()


;if keyhit 1 (ESC) then SUPPOST TO GO BACK TO MAIN MENU
If KeyHit(1)
selection=1
End If

;conditional functions
If KeyHit(P)
   Pause(pausedpic)
End If

;small delay in the loop for less slow down.
;flips, ends the loop and termanates the program..
Delay 5
  Flip
Wend
End

End Function


PS. I have the Delay 5 in the main loops because it makes no difference in the program but a HUGE difference in how much CPU it uses

Hi Yahfree,

At the end of your playgame function, after the Wend, comment out or delete the line that reads END. This is the problem. Sorry I didn't reply before, been busy. I removed this earlier when I was testing, and forgot to mention it.

Also you will want to add a ShowPointer in the If KeyHit(1) section. The playgame function should look something like this:

;!#$@#$@#%@!#$@#$!@#$!@#$
;@#$@#$# PLAYGAME !@#!@##
;!@#!@$@#$@#$@#$@#$@#$@#$
Function playgame()

;Graphics mode set for playgame()
Graphics 800,600,32,2
HidePointer

;Loads/Creates all the images
AutoMidHandle True
   paddle=CreateImage(70,15)
   ball=CreateImage(10,10)
AutoMidHandle False
   pausedpic=LoadImage("Paused.png")

;draws on the empty image container..
SetBuffer ImageBuffer(paddle)
   Rect 0,0,70,15,1
SetBuffer ImageBuffer(ball)
   Oval 0,0,10,10,1
SetBuffer BackBuffer()

;Copys the ball image 3 times these will be our lifes displayed on the bottom of the screen.
   life1=CopyImage(ball)
   life2=CopyImage(ball)
   life3=CopyImage(ball)


;playgame() loop
While selection=2
Cls


;Calls functions.
addplayercontrols()
drawmyimages()
addcollisions()
addtext()


;if keyhit 1 (ESC) then SUPPOST TO GO BACK TO MAIN MENU
If KeyHit(1)
selection=1
ShowPointer ; add this line so the mouse is shown again
End If

;conditional functions
If KeyHit(P)
   Pause(pausedpic)
End If

;small delay in the loop for less slow down.
;flips, ends the loop and termanates the program..
Delay 5
  Flip
Wend
;End ; delete or comment this line out!

End Function



THANKS!!! thanks for helping me all this time, i must be a pain :D

Hmm, i must be doing somthing wierd here, it looks a bit wierd setting a graphics mode for each screen when you can just clear the screen for each graphics mode, so i called the graphics mode once before anything else, and took out the graphics modes in the functions, to my excitment it worked, i could go between the options screen and the main menu... but when i tried to go to the main menu from the game screen it freezes it lets the mouse go, kinda like i'm at the right screen... any ideas?

my code:
;Breakout by Yahfree
;2007-04-4 -> ????-??-(?)?
AppTitle "Breakout by Yahfree","Are you sure?"

;NEWNEWNEWNEWNEWNEWNENWEN
Graphics 800,600,32,2;NEWNEWNEWNENWNEWNE
;NEWNEWNEWNWENWENWENWNEWN

;Globalized stuff
Global paddle, paddlex=380, paddley=560
Global ball,ballx=380, bally=580, ballxdir#=0, ballydir=-1, move=1, ballsleft=3, life1, life2, life3
Global blope=LoadSound("Beep.wav")
Global pausedpic
Global selection
Global ingame

;Constant numbers that never change..
Const ESC=1, RIGHTARR=205, LEFTARR=203, SPACE=57, MOUSE1=1, A=30, Z=44, P=25


ingame = 1
selection = 1


While ingame=1 
  If selection = 1 Then
    Mainmenu()
  ElseIf selection = 2 Then
    playgame()
  ElseIf selection = 3 Then
    options()
  End If
Delay 5
Wend

;Player controls
Function addplayercontrols()

;Paddle movemovement and controls
paddlex=paddlex+MouseXSpeed()
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
If paddlex<35 paddlex=35
If paddlex>765 paddlex=765

;Ball control.
If move=1 ballx=paddlex
If move=1 And ballx<35 ballx=35
If move=1 bally=paddley-15
If move=1 ballydir=-1 ballxdir=0
If MouseHit(MOUSE1)
   move=2
End If

;calls the moveball function if move=2
If move=2
   moveball()
End If

;if keyhit 1 (ESC) then go back to the main menu


;conditional functions
If KeyHit(P)
   Pause(pausedpic)
End If

End Function


;Moving the ball
Function moveball()

;All physics behind moving the ball and bouncing it.
bally=bally+ballydir*10
ballx=ballx+ballxdir*10
If bally<0 ballydir=1 PlaySound(blope)
If bally>600 move=1 ballydir=-1 ballsleft=ballsleft-1
If ballx<0 ballxdir=1 PlaySound(blope)
If ballx>800 ballxdir=-1 PlaySound(blope)

End Function

;All the games collisions..
Function addcollisions()

;collisions
If ImagesCollide(paddle,paddlex,paddley,0,ball,ballx,bally,0)
   ballxdir=(ballx - paddlex)*.025
   ballydir=-1
   PlaySound(blope)
End If

End Function

;Draws the images
Function drawmyimages()

;Draws the images...
DrawImage paddle,paddlex,paddley
DrawImage ball,ballx,bally
If ballsleft>2 DrawImage life3,680,580
If ballsleft>1 DrawImage life2,700,580
If ballsleft>0 DrawImage life1,720,580
If ballsleft=0 ballsleft=3

End Function

;Text maths ect...
Function addtext()

End Function

;Pause function,  called when P is pressed
Function Pause(picture)

FlushKeys
While Not KeyHit(P)
   DrawImage picture,0,0
   Flip
   Cls
If KeyHit(1) Then
   End
End If
  Delay 5
Wend


End Function

;!@#!@#$@#$!$#!$@#$!@$#@
;!#@!@# MAINMENU !@#!@#@
;!@#!@#!@#!@#@!#!@#!@#@#
Function Mainmenu()
;Graphics 800,600,32,2

;Load/creates images
mainimage=LoadImage("mainmenu.png")
continue=LoadImage("Playbutton.png")
options=LoadImage("options.png")
MaskImage continue,255,0,255
MaskImage options,255,0,255


DrawImage mainimage,0,0
DrawImage continue,100,400
DrawImage options,100,450
;Mainmenu loop
While selection=1
Cls

; draw the images
DrawImage mainimage,0,0
DrawImage continue,100,400
DrawImage options,100,450


mouseclick1=MouseHit(1)
;Collisions basicly making the buttons work
If ImageRectCollide(continue,100,400,0,MouseX(),MouseY(),5,5) And mouseclick1
selection=2
End If
If ImageRectCollide(options,100,450,0,MouseX(),MouseY(),5,5) And mouseclick1
selection=3
End If



If KeyHit(2)
selection=3
End If

;if esc is pressed ONLY AT THE MAIN MENU quit.
If KeyHit(1)
	ingame = 0
	selection = -1
End If


;delay and bye bye loop
Delay 5
Wend

End Function

;!#!@#!@#!@#!@#!@#!@#!
;!@#!@ OPTIONS !@#!@$$
;#@!#!@$#@$@#$@#$@#$@#
Function options()
;Graphics 800,600,32,2


backbutton=LoadImage("Backbuttons.png")
MaskImage backbutton,255,0,255

;options loop
While selection=3
Cls

DrawImage backbutton,0,0


;Makes the buttons work
If ImageRectCollide(backbutton,0,0,0,MouseX(),MouseY(),5,5) And MouseHit(1)
selection=1
End If


;delays and bye bye loop
Delay 5
Wend

End Function

;!#$@#$@#%@!#$@#$!@#$!@#$
;@#$@#$# PLAYGAME !@#!@##
;!@#!@$@#$@#$@#$@#$@#$@#$
Function playgame()

;Graphics mode set for playgame()
;Graphics 800,600,32,2
HidePointer

;Loads/Creates all the images
AutoMidHandle True
   paddle=CreateImage(70,15)
   ball=CreateImage(10,10)
AutoMidHandle False
   pausedpic=LoadImage("Paused.png")

;draws on the empty image container..
SetBuffer ImageBuffer(paddle)
   Rect 0,0,70,15,1
SetBuffer ImageBuffer(ball)
   Oval 0,0,10,10,1
SetBuffer BackBuffer()

;Copys the ball image 3 times these will be our lifes displayed on the bottom of the screen.
   life1=CopyImage(ball)
   life2=CopyImage(ball)
   life3=CopyImage(ball)


;playgame() loop
While selection=2
Cls


;Calls functions.
addplayercontrols()
drawmyimages()
addcollisions()
addtext()

If KeyHit(1)
ShowPointer
selection=1
End If


;small delay in the loop for less slow down.
;flips, ends the loop and termanates the program..
Delay 5
  Flip
Wend

End Function


Eh, that's a huge sourcecode to search for a bug.

I'd suggest to do the following:
Systematicly isolate the bug. One simple solution is to add an end command to a line that you know was still executed before freezing. Then move the end command forward, one by one. Soon you'll realize where it's freezing. That's already half of the work - or more.

Ok, its not "Freezing" per say, it going to the main menu like its suppost to, but not displaying the main menus media (buttons ect) instead it just freezes the gameplay media, strange thing is if i click where the "Play" button is suppost to be it resumes! wierd..