I don’t know what this error means. How am I doing gosub wrong? I’m trying to create a combat system, so when gosub is called it calculates randomly the damage that is done.
*fake_choice
*selectable_if (psionics > 0) #Use psionics.
*if (psionics >=90)
A powerful hit!
*set atked true
*gosub atk_enemy_powerful
*if (psionics >=70)
A strong hit!
*set atked true
*gosub atk_enemy_strong
*if (psionics >=50)
A decent hit!
*set atked true
*gosub atk_enemy_medium
*if (psionics >=30)
A weak hit!
*set atked true
*gosub atk_enemy_weak
*if (psionics <30)
A very weak hit!
*set atked true
*gosub atk_enemy_veryweak
*selectable_if (explosives > 0) #Use explosives.
#Retreat
You attempt to run away!
*label atk_enemy_powerful
*if (atked = true)
*rand hit 30 60
*set enemy_dam hit
*return
*label atk_enemy_strong
*if (atked = true)
*rand hit 20 50
*set enemy_dam hit
*return
*label atk_enemy_medium
*if (atked = true)
*rand hit 10 30
*set enemy_damn hit
*return
*label atk_enemy_weak
*if (atked = true)
*rand hit 0 20
*set enemy_dam hit
*return
*label atk_enemy_veryweak
*if (atked = true)
*rand hit 0 10
*set enemy_dam hit
*return
In your example CS will automatically jump into *label atk_enemy_powerful after the first return from subroutine and will bug out on the *return because gosub wasn’t called. Move the subroutine (all atk labels) somewhere out of game scope, e.g. after chapter *finish or before chapter start.
Having standard *choices with *goto’s should also prove useful in this case. Keep in mind that upon *return game parser will start at the line directly after *gosub, so having a goto will help avoid bugs similar to yours.
*gosub test
*goto there << the line where game resumes after *return
The above *goto makes sure CS heads in the right direction instead of wandering off.
I’m not sure I understand what you mean. What do you mean move the subroutine? When I move it to the top of the page it says gosub has not yet been called.
It is the case where you can reach the subroutine’s *label without actually coming from *gosub. As a result, the code would eventually meet *return without knowing which *gosub it is anchored with and should return to.
What you did by adding *finish is sealing-off your subroutines from being reached by default, which is one way to solve this issue.