Invalid return; we've already returned from the last gosub

The error I’m getting is… choicescript_stats line 165: invalid return; we’ve already returned from the last gosub

Does line 165 say *return?

And did you get there by a *gosub or *gosub_scene?

[b]Current Inventory:[/b] ${current_inventory}
*page_break ${name}'s deposit-box...
*gosub_scene reform_inventory
*gosub reform_inventory```
 
**Meanwhile on the same page** (choicescript_stats)...

```*label reform_inventory
[i]${name} had the following items in ${pronoun} inventory:[/i]
*if (has_butter = true)
    *set current_inventory &" butter, [n/]"
*if (has_cheese = true)
    *set current_inventory &" cheese, [n/]"
*if (has_chocolate = true)
    *set current_inventory &" a batch of chocolates, [n/]"
*if (has_chicken = true)
    *set current_inventory &" a large chicken, [n/]"
*if (has_crystal = true)
    *set current_inventory &" a magnifying crystal, [n/]"
*if (has_doll = true)
    *set current_inventory &" a discarded doll, [n/]"
*if (has_dragonegg = true)
    *set current_inventory &" a dragon's unhatched egg, [n/]"
*if (has_egg = true)
    *set current_inventory &" ${eggcarton} carton of eggs [i](${egg} eggs remaning)[/i] [n/]"
*if (has_flour = true)
    *set current_inventory &" ${item_amount} bags of flour, [n/]"
*if (has_icecream = true)
    *set current_inventory &" a bowl of icecream, [n/]"
*if (has_milk = true)
    *set current_inventory &" milk, [n/]"
*if (has_metal = true)
    *set current_inventory &" metal, [n/]"
*if (has_noodles = true)
    *set current_inventory &" a packet of noodles, [n/]"
*if (has_paper = true)
    *set current_inventory &" ${item_amount} stacks of paper, [n/]"
*if (has_pen = true)
    *set current_inventory &" a pen, [n/]"
*if (has_pencil = true)
    *set current_inventory &" a pencil, [n/]"
*if (has_potion = true)
    *set current_inventory &" Feral Inhibitor potion, [n/]"
*if (has_pepper = true)
    *set current_inventory &" a bag of pepper, [n/]"
*if (has_rice = true)
    *set current_inventory &" a bag of rice, [n/]"
*if (has_ricepot = true)
    *set current_inventory &" a metal ricepot, [n/]"
*if (has_salt = true)
    *set current_inventory &" a bag of salt, [n/]"
*if (has_seed = true)
    *set current_inventory &" a plant seed, [n/]"
*if (has_sketchbook = true)
    *set current_inventory &" sketchbook, [n/]"
*if (has_telescope = true)
    *set current_inventory &" telescope, [n/]"
*if (has_water = true)
    *set current_inventory &" a bottle of water, [n/]"
*if (has_watercan = true)
    *set current_inventory &" a metal watering-can, [n/]"
*if (has_wires = true)
    *set current_inventory &" a bundle of wires, [n/]"
*if (has_venusian = true)
    *set item_amount + 1
    *set current_inventory &" ${pet2} the Venusian, [n/]"
*if (item_amount <= 0)
    *set current_inventory ""
    You have [i]nothing[/i] of note in your inventory, ${name}!
    *return```

I might be missing something, but is there any reason for doing this as a subroutine?

Basically both the current_inventory and the reform_inventory are on the same choicescript_stats page as two seperate buttons. When the player presses current_inventory button, they are taken to reform_inventory page immediately.

I’m not sure exactly what you mean, but I think you can do that with a simple *goto command instead.

I tried doing that, but it repeated the same error.

The same one? Even though there wasn’t any *return?

Is there an extra *return somewhere you haven’t removed?

That was the only *return in the entire file.

And did you remove it when using *goto instead of *gosub?

Also, the *return is currently only activated if you have zero items, is that on purpose?

No, the *return (zero items activation) wasn’t on purpose. I’m still learning coding as I advance.

Okay, you need to remove the spacing in front of it, so it doesn’t fall under the *if statement. :blush:

Is the line it’s on line 165?

Check your *endings and *finishes and your scene list.

I had that error when I put a *finish instead of an ending on my last file, causing it to go to a subscene i had on the list which then had nothing to return to.

Yes, the *return error is on line 165

Could you send me the whole file? I can try and see if I can figure it out.

Okay. I see the problem.

The *return sends you back to the point right before the subroutine, so the game reads the entire subroutine again and gets confused when it reached the *return a second time.

Just remove the *gosub reform_inventory and the *return, and everything should work fine.

EDIT: And you need to put

below the reform_inventory part, if you want current_inventory to show everything.
Also, why does it have a page break?
I don’t think I understand what you are trying to do with this. :sweat_smile:

2 Likes

Good idea, I haven’t thought of it before you mentioned it! You have a good eye for things!

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