My system generates a random encounter which then calls the combat system. Stats are used to decide which combatant goes first and then a call is made to the proper combatant. That combatants label then starts by generating the CUI, followed by checking for death. If hp is less than one the script jumps to the game over label, if not the player (or AI for the enemy) continues until they are done, at which point the script calls the other combatant. This is then repeated until either the player is defeated or the enemy is vanquished. When the monster is vanquished, I tried using return to simply have the script backtrack until it reaches the place where the random encounter was first called from, and then just continue from there. According to my theory, it should work.
But it doesn't, which is why I am here typing. When the player gets defeated, the script jumps to the label death, which in turn jumps to the label game_over, which simply drops the script off at the bottom of the file. In my previous experience, this caused the game to revert back to the main menu, but for some reason, it just sends me back to the place in the player combat script where the death label was jumped to. I also tried to add a return at the bottom of the game over label, but it made no difference.
Here's my code, if anyone can figure out what I'm doing wrong, please let me know.
Code: Select all
label start:
"-Snip-"
call random_encounter
"-Snip2-"
label random_encounter:
#Remember to add a random generator here. For now, it just gives a single encounter, a swarm of bats.
$ enemy = 1
call combat_setup
return
label combat_setup:
#This contains lots of python code that sets the stats for the two combatants based on the values of $ player and $ enemy.
#I didn't include it because it works as intended and is really, really long.
call combat_ui
if p_spd > e_spd:
call p_turn
else:
call e_turn
return
label combat_ui:
#Lots of code that sets the health bar for the player and enemy based on current hp values.
return
label p_turn:
call combat_ui
if p_hp < 1:
jump death
else:
pass
if p_act < 1:
#Code to return enemy stats to proper states.
call e_turn
else:
menu:
"Attack":
#Code to calculate the attack and it's consequenses.
$ p_act -= 1
call p_turn
"Special":
#Code for special abilities and magic. p_act modifications vary depending on action, and is included here.
call p_turn
"Brace":
#Code adding the effects of bracing.
$ p_act -= 1
call p_turn
return
label e_turn:
call combat_ui
if e_hp < 1:
"The enemy is dead."
return
else:
if e_act < 1:
#Code to return player stats to proper states.
call p_turn
else:
$ e_act -= 1
if e_hp < 8 and e_mp > 0:
#Code for special attack.
call e_turn
else:
#Code for regular attack.
call e_turn
return
label death:
"You have died."
jump game_over
label game_over:
"Thank you for playing, I hope you had a good time."
#### And this is the end of the file ####
Edit: As a note, this code actually does NOT work for me (in the way that it creates the infinite loop) which seems to indicate (at least to me) that the fault is somewhere in the code I typed up above. Hence why I typed "if the code works for you people."