Quote: "That's a nice example of why people have a pretty negative attitude towards using labels and goto/gosub commands.
"
If this was done in functions it would still be a mess. The use of functions isn't a cure all if you have no idea what you're doing.
@GunnerWolf, sorry for my bluntness but I think you haven't really understood how to construct the flow of you're code properly. When I say flow, I mean how to get the code to go from one part to the next without the code turning into a confusing mess.
I don't know why you're getting an infinite loop error and I don't think it's worth nit picking through the code to find out. It would be better to rewrite it from scratch.
I think I understand what you are trying to do so I had a go at rewriting it.
rem setting some initial parameters
game_over = 0 :rem flag to show if the game is over
section = 1 :rem this shows what section of the story the game is currently at
choice$ = "" :rem this holds the choice the player makes in each section
key_pressed = 0 :rem this is a flag to show if a valid key has been pressed
rem main game loop
rem loop until the game_over = 1
repeat
cls
gosub _title
select section
case 1
gosub _chapter_1_part_1
endcase
case 2
gosub _chapter_1_part_2_choice_yes
endcase
case 3
gosub _chapter_1_part_2_choice_no
endcase
case 4
gosub _chapter_1_end
endcase
endselect
until game_over = 1
end
rem +++++++ SUB ROUTINES
_title:
print "TITLE: EPIC ADVENTURE"
print "Writen by: GunnerWolf"
print
return
_chapter_1_part_1:
print "'It is time for you to depart.' Your uncle stands at the entrance to"
print "the small log cabin, watching you train."
print "'Are you ready?'"
print "1) 'Yes'"
print "2) 'No'"
rem this is a flag that will go to 1 once a valid choice has been made
key_pressed = 0
repeat
choice$ = inkey$()
select choice
case "1"
key_pressed = 1
section = 2
endcase
case "2"
key_pressed = 1
section = 3
endcase
endselect
until key_pressed <> 1
rem this bit of code halts the program until the player releases the key
rem this prevents key strokes from being "carried over" to the next section of code
repeat
until inkey$() = ""
return
_chapter_1_part_2_choice_yes:
print "'Very well, choose your weapon.'"
print "1) Sword (+2 Attack)"
print "2) Spear (+1 Attack, +1 Defence)"
print "3) Staff (+1 Magic, +1 Defence)"
print "4) Wand (+2 Magic)"
print
key_pressed = 0
repeat
choice$ = inkey$()
select choice$
case "1"
key_pressed = 1
getEquip(2)
mainhand = 1
endcase
case "2"
key_pressed = 1
getEquip(3)
mainhand = 2
offhand = -1
endcase
case "3"
key_pressed = 1
getEquip(4)
mainhand = 3
offhand = -1
endcase
case "4"
key_pressed = 1
getEquip(5)
mainhand = 4
endcase
endselect
until inkey$() <> ""
repeat
until inkey$() = ""
section = 4
return
_chapter_1_part_2_choice_no:
print "'Well I'm sorry, but we can delay no longer.'"
print "'Now, choose your weapon.'"
print "1) Sword (+2 Attack)"
print "2) Spear (+1 Attack, +1 Defence)"
print "3) Staff (+1 Magic, +1 Defence)"
print "4) Wand (+2 Magic)"
print
key_pressed = 0
repeat
choice$ = inkey$()
if inkey$() <> ""
key_pressed = 1
endif
select choice$
case "1"
key_pressed = 1
getEquip(2)
mainhand = 1
endcase
case "2"
key_pressed = 1
getEquip(3)
mainhand = 2
offhand = -1
endcase
case "3"
key_pressed = 1
getEquip(4)
mainhand = 3
offhand = -1
endcase
case "4"
key_pressed = 1
getEquip(5)
mainhand = 4
endcase
endselect
until inkey$() <> ""
repeat
until inkey$() = ""
section = 4
return
_chapter_1_end:
print "And so you're epic adventure begins"
print
print "(press any key)"
wait key
rem this flag will go at the very end of your game to show that the game is finished
game_over = 1
return
rem +++++++++ FUNCTIONS
function getEquip(n)
rem whatever code goes here
endfunction
The way I've constructed it is that each section of the story has its own sub-routine.
Each sub-routine contains: the story element, the choices the player needs to make and then code to deal with those choices. Once the player has made their choice the sub-routine then returns to the main loop.
Rather than using the INPUT command I'm using the INKEY$ command and then wrapping it in a loop until the player makes a valid choice. I've also used the SELECT... ENDSELECT and CASE... ENDCASE commands rather than IF THEN ELSE as this make it easier to have multiple choices. You don't need to call multiple RETURNS within the one sub-routine.
The code should be easily expandable to add more sections of the story.
One problem I can foresee with this method is that it probably won't be very good if the want to allow the player to back track in the story. It's basically set up as a one way journey (if that makes sense).
I hope you can make sense of the code and that it gives you some ideas.
one of these days I'll come up with a better signature