Hi GLaDOS
I can see that you're getting into a bit of mess and judging by your other post you seem to have confused how GOTO and GOSUB work. GOTO allows you to skip chunks of code where as GOSUB needs to work in conjunction with RETURN, which will take the program back to the line after the GOSUB was called when the programming is running.
In order to get "respawn" or "play again" to work properly you need to wrap the game play portion of the code in some kind of loop. By way of example (I did this for someone else on the forum so it's not specific to your problem):
`this is a top down driving demo
`use the arrow keys to control the car
`as the car moves it will use up fuel
`when the car has run out of fuel then the car will stop
`the player can press space at any time to reset the demo
gosub GENERAL_SETUP
gosub GAME_CONSTANTS
gosub LOAD_MODELS
gosub STARTING_VALUES
gosub MAKE_MAP
main_loop:
do
gosub MOVE_PLAYER
gosub OTHER_CONTROLS
gosub POSITION_CAMERA
gosub PRINT_STUFF
sync
loop
end
GENERAL_SETUP:
`set any not game specific things in here
sync on
sync rate 65
autocam off
hide mouse
set camera range 1,3000
return
GAME_CONSTANTS:
`set any variables that will not change throughout the game
`player attributes
max_speed# = 5.5
acceleration# = 1.0
turn_speed# = 1.5
player_friction# = 0.3
player_width = 50
player_height = 25
player_depth = 100
max_fuel = 500
rate_fuel_used = 1
`map
map_width# = 1000
map_depth# = map_width#
`camera
camera_height_above_map = 1000
return
STARTING_VALUES:
`initial position of player
position object 1, 0,player_height/2, 0
yrotate object 1, 0
`player starting speed
current_speed# = 0.0
current_fuel = max_fuel
return
LOAD_MODELS:
`load any models (or other media) here
make object box 1, player_width, player_height, player_depth
return
MAKE_MAP:
`generate the map in (this could be done as part of the LOAD_MODELS sub-routine
make matrix 1, map_width#,map_depth#,10,10
return
MOVE_PLAYER:
`this hold all the code that is used to control the car
if current_fuel > 0
if upkey() = 1
current_speed# = current_speed# + acceleration#
current_fuel = current_fuel - rate_fuel_used
if current_fuel <= 0.0 then current_fuel = 0.0
endif
if leftkey() = 1 then turn object left 1, turn_speed#
if rightkey() = 1 then turn object right 1, turn_speed#
endif
current_speed# = current_speed# - player_friction#
if current_speed# <= 0.0 then current_speed# = 0.0
if current_speed# > max_speed# then current_speed# = max_speed#
move object 1, current_speed#
return
OTHER_CONTROLS:
`this sub-routine holds any controls that do not involve movement
if spacekey() = 1 then gosub STARTING_VALUES
return
POSITION_CAMERA:
`in this case the camera is fixed
position camera map_depth#/2, camera_height_above_map, map_depth#/2
point camera map_depth#/2, 0, map_depth#/2
return
PRINT_STUFF:
`print game information
text 1,1, "Press: Up arrow key to accelerate, left and right arrow keys to turn"
text 1,15, "Press: space bar to reset"
text 1,30, "When fuel reaches zero car will slow to a stop"
text 1,60, "FUEL LEVEL : " + str$(current_fuel)
return
The important thing to note here is not what all the lines of code are doing but how the program as a whole is structured, how the sub-routines have a RETURN command at the end of them (unlike a label that would be used for a GOTO). This is just an example and by no means the only or best way of structuring your code.
So, ignoring all the remalks at the start, the first line (line 7) of the program is:
gosub GENERAL_SETUP
this means that the program now jumps to the GENERAL_SETUP: label (line 28). A bunch of code is then executed and then the program hits a RETURN command (line 38), which takes the program back to line 8 (which happens to be another GOSUB command.
The sub-routines are really just giving the code a a more organised structured, it could all be done without sub-routines or could be done using functions.
Specifically to your code, is could be written like this:
Rem Project: Learning1
Rem Created: Saturday, December 22, 2012
Rem ***** Main Source File *****
do
Menu:
Print "Benvenuto In Cerca il tesoro! premi un tasto per continuare"
Wait key
Print "Per giocare Devi Premere Un Tasto da 1 a 6,Come Visto nello schermo,premi spazio per iniziare"
Wait key
gosub Respawn
Repeat
I$=Inkey$()
Until Asc(I$)>48 and Asc(I$)<55
If I$="1" Then Print "Non C'è Niente "
If I$="2" Then Print "Non C'è Niente"
If I$="3" Then Print "Non C'è Niente "
If I$="4" Then Print "Wow! Hai trovato il tesoro!"
If I$="5" Then Print "Non C'è Niente "
wait key
CLS
loop
Respawn:
Center Text 320,100,"1. Buca Numero 1,Sembra Aperta"
Center Text 320,120,"2. Buca Numero 2,Sembra Chiusa male"
Center Text 320,140,"3. Buca Numero 3,Sembra che ci sia qualcosa che non vuole far abbassare la terra"
Center Text 320,160,"4. Buca Numero 4,Non Sembra neanche una buca!"
Center Text 320,180,"5. Buca Numero 5,Sembra vuota da qui"
Center Text 320,200,"6. Buca Numero 6,C'è Della Pietra"
return
What I've done here is wrap your entire code in a DO...LOOP. The way I've structured it, the "Respawn" sub-routine can be thought of as a "initiate game" sub-routine". However, this might not suit a game where the number of guessing is counted and, on a replay, the number of guesses would be set to zero again.
Hope this helps.