Howdy, Stranger!

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

Toggling a variable between two states; can't get "else" to work?

edited November 2015 in Help! with 2.0
In Twine 2.0.9, using Harlowe, I am having difficulty toggling a variable back and forth between two values by using the "else" clause. I have also tried "elseif", and I have tried toggling between 0 and 1, "on" and "off", and true and false.

The "else" (or "elseif") clause never seems to trigger. The following script will switch the variable from 0 to 1, but it will then remain at 1. I must be missing something really simple, but I've been stuck on this for hours. The intention was to be able to toggle a light switch between on and off (repeatedly) from within one passage.

Value is set to $test
(if: $test is 0)[(set: $test to 1)]
(else:)[(set: $test to 0)]
Value is set to $test

[[retry]]

Comments

  • It appears you found a bug in the new 1.2 version of Harlowe, it seems like it no longer executes (else:) macros as demonstrated by the following simple test case:
    (set: $var to "B")
    
    (if: $var is "A")[The Var is A]
    (else:)[This text will not be displayed!]
    
    The else was not executed!
    

    I suggest in the short term that you return to using Twine 2.0.8 until this issue is resolved by Leon.
  • Thank you, greyelf! I thought I was going crazy when I couldn't get such a simple case to work after several hours of trying.

    I actually updated from 2.0.8 to 2.0.9 just a few hours ago, after learning that an update had been released to fix the bug (which I was experiencing a lot) where dragging multiple passages resulted in them jumping to the wrong positions.

    I'll just have to make do with one bug or the other in the meantime, though it seems that going back to 2.0.8 as you suggest would be the easiest choice.

    Thanks again!
  • Stuck wrote: »
    I'll just have to make do with one bug or the other in the meantime, though it seems that going back to 2.0.8 as you suggest would be the easiest choice.
    A much more complex solution would be to obtain a copy of the Harlowe 1.1 format.js file and to add it manually to Twine 2.0.9 as a new local Story Format, the same way SugarCube works.
    How you actually obtain a copy of the 1.1 format.js file is a totally different problem and I am not sure the best (read easiest) way to do so. You could:

    1. Find the relevant commit on the Twine 2 project site and cut-n-paste the contents into your own local file.

    2. You could build your own format.js file based on the 1.1 source code on Harlowe project site.

    3. Try to extract the relevant format.js file from the Twine 2.0.8 node-js files.

    4. Some other option I have not thought about.

    The first three of the above options require different degrees of knowledge about programming.
Sign In or Register to comment.