Another "invalid return; gosub has not yet been called" Error

Hi everyone,

I’m having trouble with getting a gosub_scene working.

The error I’m getting is:

My gosub scene code (in choicescript_stats) looks like this:


*choice
    # I desire to change: gender, orientation, romance and/or friendship variables
        *gosub_scene toggles toggles
        *goto navigation_menu
    #I do not desire to change: gender, orientation, romance and/or friendship variables
        *goto navigation_menu

My “toggles” scene code looks like this:

*label toggles
Gender Toggles:

Gender identity is about who you are.

*choice
    #Identify the Main Character's gender as male.
        *set gender "male"
        *set gender1 1
        The Main Character's gender is set as "male".
        *goto return
    #Identify the Main Character's gender as female.
        *set gender "female"
        *set gender1 2
        The Main Character's gender is set as "female".
        *goto return
    #Identify the Main Character's gender as non-binary
        *set gender "non-binary"
        *set gender1 3
        The Main Character's gender is set as "non-binary".
        *goto return

Orientation Toggles:

Sexual orientation is about: who you want to be with, who you’re attracted to, and who you feel drawn to romantically, emotionally, and sexually. 

*choice
    #Identify the Main Character's sexual orientation as heterosexual.
        *set orientation "heterosexual"
        *set orientation1 1
        The Main Character is attracted to the opposite binary-gender (gender should be set as male or female).
        *goto return
    #Identify the Main Character's sexual orientation as gay.
        *set orientation "gay"
        *set orientation1 2
        The Main Character is attracted to males.
        *goto return
    #Identify the Main Character's sexual orientation as lesbian.
        *set orientation "lesbian"
        *set orientation1 3
        The Main Character is attracted to females.
        *goto return
    #Identify the Main Character's sexual orientation as bisexual.
        *set orientation "bisexual"
        *set orientation1 4
        The Main Character is attracted to both males and females.
        *goto return
    #Identify the Main Character's sexual orientation as pansexual
        *set orientation "pansexual"
        *set orientation1 5
        The Main Character is attracted to many different gender identities.
        *goto return
    #Identify the Main Character's sexual orientation as questioning.
        *set orientation "questioning"
        *set orientation1 6
        The Main Character is unsure about their sexual orientation.
        *goto return
    #Identify the Main Character's sexual orientation as asexual.
        *set orientation "asexual"
        *set orientation1 7
        The Main Character doesn't experience any sexual attraction.
        *goto return
    #Identify the Main Character's sexual orientation as demisexual
        *set orientation "demisexual"
        *set orientation1 8
        The Main Character is attracted to.
        *goto return

Romance Toggle:

*choice
    #Enable customized romance arcs.
        *set romance "enabled"
        *set romance1 1
        You have enabled romance arcs.
        *goto return
    #Disable customized romance arcs.
        *set romance "disabled"
        *set romance1 2
        You have enabled romance arcs.
        *goto return
        

Friendship Toggle

*choice
    #Enable customized friendship arcs.
        *set friendship "enabled"
        *set friendship1 1
        You have enabled friendship arcs
        *goto return
    #Disable customized friendship arcs.
        *set friendship "disabled"
        *set friendship1 2
        You have enabled friendship arcs.
        *goto return

*page_break

*label return

Review:

*stat_chart
    text gender Gender
    text orientation Orientation
    text romance Romance
    text friendship Friendship

[i]Note — Changes will only be registered if you advance beyond the first choice in the game, once you return to it.[/i]

*return

*finish

I know there are a ton of these types of threads, but I still can not figure out what I am doing wrong.

The random test is what fails.

M’am, what you are trying to do is illegal. You are lucky someone hasn’t called the CS police yet.

The issue is that *gosub calls are scoped. The value from the *params and the *return calls work only on the first *gosub call. If that weren’t the case, you could access the params from the whole scene file, which defies its purpose of somewhat mimicking what subroutines do in other programming languages. To achieve the result you want, you need to pass along the name of the label you want to return to, then pass it along subsequent *gosub calls. However, I don’t think this is possible with a subroutine from another scene. You will have to move the toggles label inside the scene you are calling it from (unless there is a way in CS to call a scene by reference which I am not aware of).

You can read more about the *gotoref command here: Ref Commands | ChoiceScript Wiki | Fandom

Here is a short example of how it would work in your example

I will assume that in the example below, you have moved the toggles label inside the scene you are calling it from.

*choice
    # I desire to change: gender, orientation, romance and/or friendship variables
        *gosub toggles navigation_menu
    #I do not desire to change: gender, orientation, romance and/or friendship variables
        *goto navigation_menu

Here is a snippet on how your toggle method will change:

*label toggles
*params return_label
Gender Toggles:

Gender identity is about who you are.

*choice
    #Identify the Main Character's gender as male.
        *set gender "male"
        *set gender1 1
        The Main Character's gender is set as "male".
        *gosub return return_label

----------------------------
*label return
*params return_label

Review:

*stat_chart
    text gender Gender
    text orientation Orientation
    text romance Romance
    text friendship Friendship

[i]Note — Changes will only be registered if you advance beyond the first choice in the game, once you return to it.[/i]

*gotoref return_label

The gist of it is that you are passing a label name along the chain of goto calls so that in the end you navigate to the place where the *return command would have left you.

Thank you, Sir Quartz. :sweat_smile:

I am still lost, but I shall see if I can figure this out with some pondering.

If I understand what you are saying, the gist is: I need a *return to label and a *label to return back to the choicescript_stats scene

Edit: I struck on that idea.
Edit2: I missed the params part … trying to put that in now.

1 Like

The issue is that you can’t call *return from another place other that the first *gosub call you make.

So basically you need to tell the program “after you have finished showing all this text, go to the place you came from.” Choicescript loses “the place you came from” the moment you make another goto/gosub/gosub_scene command.

So, instead of telling it “return from where you came”, you tell it to “go to this label when you are done”. And you achieve this by passing the label you want to go to in the *params of the subroutine, in combination with the *gotoref command, which basically lets you go to a label that’s stored in a variable.

Hope this gives you a better understanding about the proposed solution.

1 Like

I am still confused. Sorry.

the first and only gosub_scene i command is in choicescript_stats…

so, you’re saying I must put the return in choicescript_stats?

If this is the case, then why is there an option to have a separated scene for gosubs?

For this solution to work, you have to move the toggles and return labels inside the scene you are calling them from.

3 Likes

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.