help

Started by
1 comment, last by SSJCORY 19 years, 7 months ago
i'm stuck, on blitz basic i've been trying to get the shooting part down and it keeps on giving me an error saying that i cannot have a function outside the main program. my code says this Graphics 640,480 grass=LoadImage("grass.bmp") Function game() FlushKeys() While Not KeyHit(1) ; Pressing 'Esc' will quit to the menu. update_player() ; Draw player rocket and read keys. update_bullet() ; Move bullets and check for collisions. ; Check is player died and do anims. Flip ; Swap screens. Cls ; Clear the screen. Wend main_menu() ; Go to main menu. End Function you=LoadImage("you.bmp") AutoMidHandle True name$=Input$("By what name shalt thou be known as?") Print "Welcome Sir " + name$ + ". We have been expecting you." WaitKey Print "Sir " + name$ + " the world is in grave danger, you must help us." Print "" continue=0 .lable1 startstat=50 Print "you have " + startstat + " points remaining" Strength=Input$("listen To me, First, tell me how strong you are.") startstat=(startstat-Strength) Print "you have " + startstat + " remaining" life=Input$("now, how healthy are you?") startstat=(startstat-life) If life=0 Then Print "you cannot survive without life" Goto lable1 EndIf Print "you have " + startstat + " remaining" defence=Input$("now, how tough are you?") startstat=(startstat-defence) If startstat<>0 Then Print "you have not chosen wisely, please try again" Else Print "very well, your stats are " + Strength + " " + life + " " + defence + " " + dexterity correct$=Input$("is this alright?") If correct="yes" Then Print "very well, off you go." continue=1 WaitKey Else Cls Print "then lets have another go" EndIf EndIf If continue=0 Then Goto lable1 EndIf SetBuffer BackBuffer() AutoMidHandle True ;CONSTANTS ;These constants define the direction that is begin faced Const DIRECTIONLEFT = 1 ;When direction is left Const DIRECTIONUP = 2 ;When direction is up Const DIRECTIONRIGHT = 3 ;When direction is right Const DIRECTIONDOWN = 4 ;When direction is down ;These constants define how many pixels are moved per frame Const MOVEX = 5 ;How many pixels moved left/right per frame? Const MOVEY = 5 ;How many pixels moved up.down per frame? ;These are key code constants Const LEFTKEY = 203, UPKEY = 200, RIGHTKEY = 205, DOWNKEY = 208 spacebar=57 Global bullet = LoadAnimImage("fireball.bmp",13,13,0,4) backgroundimage = LoadImage("stars.bmp") ;TYPES ;The player type is used for the character on the screen Type player Field x,y ;The coordinate position Field direction ;The direction that is being faced (one of the DIRECTIONXXX constants) Field frame ;The frame that should be drawn Field image ;The image that should be drawn End Type ;Bullet type = hold the information for each bullet Type bullet Field x,y ;the coordinates of the bullet Field direction Field frame Field image End Type player.player=New player ;Player type - holds the actual player ;Give the player starting variables player\direction = DIRECTIONLEFT player\frame = 0 ;Load the player's image player\image = LoadAnimImage("you1.bmp",24,31,0,12) ;MAIN LOOP While Not KeyDown(1) ;Clear the screen Cls ;Place the text in top left hand corner Locate 0,0 Function update_player() ;If player hits left, move him left, and find the correct direction and frame If KeyDown(LEFTKEY) player\x = player\x - MOVEX ;Move him left player\direction = DIRECTIONLEFT ;face him left player\frame = (player\frame + 1 )Mod (2) + (3 * (player\direction)-3) ;find frame ;If player hits up, move him up, and find the correct direction and frame ElseIf KeyDown(UPKEY) player\y = player\y - MOVEY ;Move him up player\direction = DIRECTIONUP ;face him up player\frame = (player\frame + 1 )Mod (2) + (3 * (player\direction)-3) ;find frame ;If player hits right, move him right, and find the correct direction and frame ElseIf KeyDown(RIGHTKEY) player\x = player\x + MOVEX ;move him right player\direction = DIRECTIONRIGHT ;face him right player\frame = (player\frame + 1 )Mod (2) + (3 * (player\direction)-3) ;find frame ;If player hits down, move him down, and find the correct direction and frame ElseIf KeyDown(DOWNKEY) player\y = player\y + MOVEY ;Move him down player\direction = DIRECTIONDOWN ;face him down player\frame = (player\frame + 1 )Mod (2) + (3 * (player\direction)-3) ;find frame ElseIf KeyDown(spacebar) bullet.bullet=New bullet ;make bullet bullet\x = player\x ; X start position of bullet. bullet\y = player\y ; Y start position of bullet. bullet\direction = player\direction ; bullet direction EndIf End Function Function updatebullets() For bullet=Each bullet If direction=DIRECTIONUP bullet\y=bullety-MOVEY bullet\DIRECTIONUP EndIf If direction=DIRECTIONLEFT bullet\y=bullety-MOVEX bullet\DIRECTIONLEFT EndIf If direction=DIRECTIONRIGHT bullet\y=bullety+MOVEX bullet\DIRECTIONRIGHT EndIf If direction=DIRECTIONDOWN bullet\y=bullety+MOVEY bullet\DIRECTIONDOWN EndIf Next End Function ;Draw the player at correct position and frame TileImage(grass) Print "you have " + (life-hit) + "hits left" DrawImage player\image,player\x,player\y, player\frame If hit>=life Then Print "GAME OVER" End EndIf ;wait a (fraction of a) sec Delay 50 Flip Wend ;END OF MAIN LOOP End what am i doing wrong?
Advertisement
Few people here would have had experience with Blitz Basic, though a bunch do use other basic derivatives (VB for example). But the way you posted your code, it is unreadable. Here's a better post:
Graphics 640,480grass=LoadImage("grass.bmp")Function game()	FlushKeys()	While Not KeyHit(1)											; Pressing 'Esc' will quit to the menu.		update_player()												; Draw player rocket and read keys.		update_bullet()												; Move bullets and check for collisions.												; Check is player died and do anims.		Flip														; Swap screens.		Cls															; Clear the screen.	Wend	main_menu()														; Go to main menu.End Functionyou=LoadImage("you.bmp")AutoMidHandle Truename$=Input$("By what name shalt thou be known as?")Print "Welcome Sir " + name$ + ". We have been expecting you."WaitKey Print "Sir " + name$ + " the world is in grave danger, you must help us."Print ""continue=0.lable1	startstat=50	Print "you have " + startstat + "  points remaining" 	Strength=Input$("listen To me, First, tell me how strong you are.")	startstat=(startstat-Strength)	Print "you have " + startstat + " remaining"	life=Input$("now, how healthy are you?")	startstat=(startstat-life)	If life=0 Then		Print "you cannot survive without life"		Goto lable1	EndIf 	Print "you have " + startstat + " remaining"	defence=Input$("now, how tough are you?")	startstat=(startstat-defence)	If startstat<>0 Then		Print "you have not chosen wisely, please try again"			Else 		Print "very well, your stats are " + Strength + " " + life + " " + defence + " " + dexterity		correct$=Input$("is this alright?")		If correct="yes" Then			Print "very well, off you go."			continue=1			WaitKey 		Else 			Cls 			Print "then lets have another go"		EndIf 	EndIf 	If continue=0 Then 		Goto lable1	EndIfSetBuffer BackBuffer()AutoMidHandle True;CONSTANTS;These constants define the direction that is begin facedConst DIRECTIONLEFT = 1     ;When direction is leftConst DIRECTIONUP = 2     ;When direction is upConst DIRECTIONRIGHT = 3     ;When direction is rightConst DIRECTIONDOWN = 4     ;When direction is down;These constants define how many pixels are moved per frameConst MOVEX = 5     ;How many pixels moved left/right per frame?Const MOVEY = 5     ;How many pixels moved up.down per frame?;These are key code constantsConst LEFTKEY = 203, UPKEY = 200, RIGHTKEY = 205, DOWNKEY = 208 spacebar=57Global bullet = LoadAnimImage("fireball.bmp",13,13,0,4)backgroundimage = LoadImage("stars.bmp");TYPES;The player type is used for the character on the screenType player	Field x,y    ;The coordinate position	Field direction    ;The direction that is being faced (one of the DIRECTIONXXX constants)	Field frame    ;The frame that should be drawn	Field image    ;The image that should be drawnEnd Type;Bullet type = hold the information for each bulletType bullet	Field x,y   ;the coordinates of the bullet	Field direction	Field frame	Field imageEnd Typeplayer.player=New player;Player type - holds the actual player;Give the player starting variablesplayer\direction = DIRECTIONLEFT player\frame = 0 ;Load the player's imageplayer\image = LoadAnimImage("you1.bmp",24,31,0,12) ;MAIN LOOPWhile Not KeyDown(1);Clear the screenCls;Place the text in top left hand cornerLocate 0,0 Function update_player();If player hits left, move him left, and find the correct direction and frameIf KeyDown(LEFTKEY) 	player\x = player\x - MOVEX     ;Move him left 	player\direction = DIRECTIONLEFT     ;face him left 	player\frame = (player\frame + 1 )Mod (2) + (3 * (player\direction)-3)     ;find frame;If player hits up, move him up, and find the correct direction and frameElseIf KeyDown(UPKEY) 	player\y = player\y - MOVEY     ;Move him up	player\direction = DIRECTIONUP     ;face him up	player\frame = (player\frame + 1 )Mod (2) + (3 * (player\direction)-3)     ;find frame	;If player hits right, move him right, and find the correct direction and frameElseIf KeyDown(RIGHTKEY) 	player\x = player\x + MOVEX     ;move him right	player\direction = DIRECTIONRIGHT     ;face him right	player\frame = (player\frame + 1 )Mod (2) + (3 * (player\direction)-3)     ;find frame;If player hits down, move him down, and find the correct direction and frameElseIf KeyDown(DOWNKEY)	player\y = player\y + MOVEY     ;Move him down	player\direction = DIRECTIONDOWN     ;face him down	player\frame = (player\frame + 1 )Mod (2) + (3 * (player\direction)-3)     ;find frameElseIf KeyDown(spacebar) 	bullet.bullet=New bullet ;make bullet	bullet\x = player\x									; X start position of bullet.	bullet\y = player\y									; Y start position of bullet.	bullet\direction = player\direction                 ; bullet directionEndIf End FunctionFunction updatebullets()For bullet=Each bullet	If direction=DIRECTIONUP		bullet\y=bullety-MOVEY		bullet\DIRECTIONUP		EndIf	If direction=DIRECTIONLEFT		bullet\y=bullety-MOVEX		bullet\DIRECTIONLEFT		EndIf	If direction=DIRECTIONRIGHT		bullet\y=bullety+MOVEX		bullet\DIRECTIONRIGHT		EndIf	If direction=DIRECTIONDOWN		bullet\y=bullety+MOVEY		bullet\DIRECTIONDOWN		EndIfNext End Function 		;Draw the player at correct position and frameTileImage(grass)Print "you have " + (life-hit) + "hits left"DrawImage player\image,player\x,player\y, player\frame If hit>=life Then	Print "GAME OVER"	End EndIf ;wait a (fraction of a) secDelay 50 FlipWend ;END OF MAIN LOOP End
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
Nope sorry bro never used blitz basic but by the error that means your trying to execute a function while outside of the main function but I'm not real sure since I don't know the syntax of blitz. Maybe it means you dont have a main function or somethiN? GL not many here will know about this.
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|

This topic is closed to new replies.

Advertisement