Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Sugarcube 1] Getting Back from a StoryMenu passage without Undoing Variables

edited March 2017 in Help! with 2.0
I suspect that this is going to be something I should have thought of... that or something that went over my head for lack of programming knowledge.

I have a Storymenu line linking to [Inventory]
Now, the Inventory, I actually have working. It's very basic, but fulfills all my needs for it... except a couple little hiccups.
1. I want to be able to turn a Lantern ($invlantern) on and off ($invlight)
2. I want there to be multiple available outfits the player can switch between. (displays "worn" in the inventory if you are wearing it. I can make that work)

In order to display the results of the player clicking on the lantern, or changing outfit, the Inventory page needs to be reloaded. Aaand there's the hiccup. As soon as the Inventory page loads again, it drops history. I can't use [back] because it would lose the Variable changes, and I can't use [return] because it causes a loop.
I did find this JS code, but every time I try to use it, I get "ERROR: State not defined" when the game tries to load.
predisplay["Menu Return"] = function (taskName) {
if (! tags().contains("noreturn")) {
State.variables.return = passage();
}
};

My only thought would be finding a way to update the text without reloading the passage, but I'm still more than a little confused trying to figure out how to do that.

(at least I know which versions I'm using this time. XD )

Comments

  • That code, as was likely noted where you found it, is for SugarCube v2, not v1.

    For SugarCube v1, you want something like the following instead:
    predisplay['menu-return'] = function (taskName) {
    	if (!tags().contains('noreturn')) {
    		state.active.variables.return = passage();
    	}
    };
    
    You'd then tag each of your inventory or other sub-menu-y passages with noreturn.

    And to use it, you'd do something like the following within those passages:
    <<click "Return" $return>><</click>>
    
    You could use a normal double square-bracket link, however, Twine 2's automatic passage creation would want to create a passage named $return, so I don't really recommend doing so.
  • Thank you, Exile!! =^.^=
    I was afraid the code wouldn't be backward compatible, but I wasn't sure, and I wasn't finding anything else.
    And this works perfectly! Thank you!!

    ...I think I need to learn Java...
  • JavaScript, not Java. Aside from a name similarity, due to marketing shenanigans, JavaScript (a.k.a. ECMAScript) has absolutely no connection to Java.
  • JavaScript, not Java. Aside from a name similarity, due to marketing shenanigans, JavaScript (a.k.a. ECMAScript) has absolutely no connection to Java.

    ...Iiii had no idea. O_o
Sign In or Register to comment.