Help with Memorize Function [Twine 2] [SugarCube 2.30.0]

Twine Version: Twine ver. 2.3.5
Story Format: Sugarcube 2.30.0

Hi,
I created an “Endings” link dialog box on the UIBar API by doing the following in the StoryMenu:

Summary
<<link "Endings">>
<< script >>
  Dialog.setup("Endings");
  
  Dialog.append(" ");
  Dialog.wiki("<<if $ending_1 == true>>Ending Name Here<< else >>???<< /if >><br>");
  
  Dialog.append(" ");
  Dialog.wiki("<< if $ending_2 == true >>Ending Name Here<<else>>???<</if>><br>");
  
  Dialog.open();
<< /script >>
<< /link >>

And setting this variable in StoryInit and the passage:

<< set $ending_1 to 'false'>>
<< set $ending_2 to 'false'>>

<<run memorize ('ending_1', true)>>

But it doesn’t appear to work. On the other hand, when I apply the basic conditional statement it does except whenever I refresh it, the variable reverts to “false” rather than retaining the ending name. Would someone please kindly point out what I’m doing wrong and explain the proper way to use memorize(key, value) ?

Thank you :slight_smile:

Variables (defined with the <<set>> macro) and metadata (defined with the memorize() function) are independent of each other, even if their keys share names. Metadata also use the recall() and forget() functions. The proper way is to put…

<<set $ending_1 to recall('ending_1')>>

…in your StoryInit. That will set $ending_1 to the value (in this case true or false) set with the key ‘ending_1’ using memorize().

Also 'false' (in quotes) is not the same as false (no quotes).

Hope this helps.

2 Likes

Thank you! The code finally worked. :smiley: But what of the difference between the in quotes and none?

Putting quotes '' (or double quotes "") around a value defines it as a string.
There are different types of values, common ones being:
booleans true or false
numbers 2, -69, 1.618 etc
and strings 'Hello world', "false", 'not true', '023' etc

A string that spells 'false' is not the same as the boolean value false

1 Like