Howdy, Stranger!

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

Permanently Changing a Variable as the Result of a Choice

I have decision points that not only advance the story, but also change a variable. The code I've used so far helps me exit the if statement, but it doesn't permanently change the variable. I need to be able to track it over the course of the story.

(set:$1st to 1)
(if:$1st is 1)[
(link: "(A) \“Hello .... District\”")[
(set:$1st to 2)
(replace: ?choice)[“Hello ... District.”]]
(link: "\“Good .... cause.\”")[
(set:$1st to 2)
(replace: ?choice)[“Good .... cause.”]]


  • edited April 21
    I don't think variables can have a number immediately following the sigil. So, $x1 would work, but $1x wouldn't. There might be other problems too, and its possible that Harlowe allows numbers immediately after the sigil (though I doubt it), but I'd try to see if changing the names of your variables helps.
  • @Gingerjack: You need to state the name and full version number of the Story Format you are using, as answers can be different for each one. Based on the syntax of your example I will assume you are using Harlowe, I will also assume you are using v1.2.3 as it is the default. Also please use the code tag when posting examples - it's the C on the editor bar.

    While Harlowe does support using a number as the first character of a variable's name, as @Chapel stated it is generally not a good idea to do so.

    Your example does change the value of the $1st variable to 2 if either of those links are selected, and this can be demonstrated by adding a third markup link to the bottom of the code and then displaying the current value of $1st in the next passage.

    eg. your example passage plus extra link.
    (set: $1st to 1)
    (if: $1st is 1)[
    		(link: "(A)	\“Hello .... District\”")[
    			(set: $1st to 2)
    			(replace: ?choice)[“Hello ... District.”]
    		(link: "\“Good .... cause.\”")[
    			(set: $1st to 2)
    			(replace: ?choice)[“Good .... cause.”]
    The Next passage:
    value of 1st: $1st
    ... should display 2 if either of your 'choice' links are selected before selecting the 'Next' link.

    The ERROR text in your example will never be displayed, even if you revisit that passage, because you are assigning a value of 1 to the $1st variable each time that passage is visited. If you move that initial assignment to an earlier passage (ideally your story's startup tagged passage) then your example passage with be able to display the ERROR text when the variable is not equal to 1.
Sign In or Register to comment.