Dynamic destinations for a textbox get lost

Twine Version: 2.3.5
Story Format: sugarcube 2.30.0

The story I’m working on has several places where I want the player to be able to provide text, but I don’t (always) want to red-flag doing so will accomplish things. So, I’m trying to build a textbox in the StoryCaption passage that links back to the current passage, wherever that is. I verified that I could set up a simple self-referencing link with a variable;

<<set $selfref to passage() >>\

I then moved on to trying the same thing with a textbox.

<<set $selfref to passage() >>\
<<textbox "_invoke" "" "$selfref">>

At which point it throws an error, saying the passage doesn’t exist.

I’ve used various <<print>> calls to try and figure out where it’s going, and the variable is returning the proper destination title but a <<print passage()>> returns “bad evaluation: Maximum call stack size exceeded.”

I’ve also tried it in individual passages as well as the StoryCaption/sidebar, just to isolate there’s no difference in behavior.

I think I’m doing what the documentation says should work, but I’m clearly doing something wrong and obviously missing what it is.

Please use code blocks for code in the future—see </> on the editor toolbar.

In general, you do not quote variables passed to macros. Receiver variables are a special case, and the sole exception to that rule.

Try the following:

<<textbox "_invoke" "" $selfref>>

Edited the code blocks in for readability.

And that did it. Was definitely getting thrown off by the quoted variable right next to it.


edit; spoke too soon.
Followup note for anyone else who wants to do this sort of thing; when textboxes load they reset the variable to the default. When working in a regular passage I’ve mostly worked around this by putting the triggers (if statements, switches, etc) above the textboxes. The StoryCaption passage loads before anything else, though. I’m working through that by passing the textbox’s variable value off to a second variable above the textbox and checking the alternative variable. ie;

<<set _secrets to _invoke >>\
<<set $selfref to passage() >>\
<<textbox "_invoke" "" $selfref>>

Not working after all. Have to look at that some more.

Not exactly, the assign the default value to the Receiver variable if no value is supplied by the end-user.

So if you pre-initialise your _invoke variable within the ‘current’ Passage to a meaningful value, like whatever the associated variable’s current value is…

<<set _invoke to $colour>>

…and then changed the relevant contents of your StoryCaption passage to…

<<set $selfref to passage() >>\
<<textbox "_invoke" _invoke $selfref>>

…then the result of the text-box will be either the value entered by the end-user or the value you assigned to the _invoke variable.

I may be missing something, but I’m not sure how what you’re suggesting goes where I want to.

I’ve found that, for whatever reason, trying to do this with temp variables isn’t working. They pass to the StoryCaption page but don’t make it to the display. Interestingly, when I went to this for the sidebox;

<<set $secret to $invoke >>\
<<set $selfref to passage() >>\
<<textbox "$invoke" $secret $selfref>>

I started getting outputs on <<print $invoke>> but not on <<print $secret>> placed in the main passage.

It’s still got behavior I don’t want (retaining the last entered text across multiple passages) but it’s allowing the side bar’s textbox to effect the main passage.

turns out I don’t even need to juggle the $secrets/$invoke.

<<set $selfref to passage() >>\
<<textbox "$invoke" $invoke $selfref>>

Is producing most of the desired behavior. I’d rather have a temp variable to keep from carrying that value. (I left the $invoke as the default value because otherwise it looks like that’s reset but it doesn’t).

Actually, you can make that code even shorter, like this:

<<textbox "$invoke" $invoke `passage()`>>

The “backquotes” (found on the ~ key on most keyboards) around a statement causes it to pass the value of the statement inside.

I’d rather have a temp variable to keep from carrying that value.

You can’t do that, because temp variables are only good within the passage where they are used and then they get cleared on passage transition. However, the <<textbox>> macro sets the variable within that passage as the user types, so when they hit RETURN, that triggers a passage transition, at which point the temporary variable is cleared.

I’m kind of fuzzy on exactly what effect you’re trying to achieve here, so perhaps if you clarified that then we could provide a better solution.

Hope that helps! :slight_smile:

Good call on the backquotes, always a fan of saving steps.

For some reason I thought the textbox was supposed to pass the variable to the new passage, but I think I tried to switch to temp variables where possible at the same time I started working on this and missed that the temp variables were part of the problem.

Well, don’t forget, you can (and should) always get rid of a story variable once you’re done with it by using the <<unset>> macro.