Howdy, Stranger!

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

How can I reset a true variable back to false?

At first I made this a new discussion before I reread the "First time Posting" discussion and realized I should have clicked on "Ask Question". Sorry about that :/

I am using the Harlowe 2.0 format and using it online. I have some riddles in my story with multiple answers. I want the player to choose the correct answer first before they can move to the next puzzle. So far this is what I got:

Passage "blue cap":

Two college kids got kicked out of college. Their dorm room was on the third floor. They have to move all their belongings from the third floor to the first floor. The larger student can carry two boxes at a time, and it takes him one minute to get to the first floor. The smaller student can carry only one box at a time, but it takes him just 30 seconds to make it to the first floor. For both students, the return trip to the third floor is the same as the trip down.

If there were seven boxes total, how many minutes would it take the students to get all the boxes to the first floor?


It would take:

seven minutes Pick me!

three minutes No me!

five minutes No, pick me!


Passage "seven minutes"
No.

(link-goto: "Try Again", "blue cap")

(set: $sevmins's isSelected to true)

Passage "three minutes"

Yes!

(if: $sevmins's isSelected is false)[Now look for a red cap]

(if: $sevmins's isSelected is true)[Now solve the puzzle in one try to move on to the next puzzle. (link-undo: "Go back")]


I thought the, (link-undo: "Go back"), would reset the $sevmins's isSelected to true back to false, so this, "
(if: $sevmins's isSelected is false)[Now look for a red cap]" would appear in the "three minutes" passage. However, this does not appear, but this does, "(if: $sevmins's isSelected is true)[Now solve the puzzle in one try to move on to the next puzzle. (link-undo: "Go back")]".

What am I doing wrong? or, is this not possible to do in Harlowe?

Thanks in advance and I'm sorry if I left out any information that would make it easier to help answer my questions.

I tried this:

Passage 3:
(click: ?goback)(set: $goback's isSelected to true)(set: $sevmins's isSelected to false)

and it works, but it says this, "The (click:) command should be assigned to a variable or attached to a hook.►"

Comments

  • This also works:
    (click: ?goback)[(set: $goback's isSelected to true)]
    (if: $gobacks's isSelected to true)(set: $sevmins's isSelected to false)

    but it says, " (if:)'s 1st value is a 'to' or 'into' expression, but should be a boolean.►
    If you gave a number, you may instead want to check that the number is not 0. If you gave a string, you may instead want to check that the string is not "". "

    I feel like I am close to figuring it out, but what is obvious to others is sometimes lost on me. lol
  • edited March 2017
    I figured it out.

    (click: ?goback)[(set: ?goback to true)]
    (if: is not ?goback)[(set: $sevmins's isSelected to false)]

    this worked for resetting the "seven minutes" from true back to false so when the player goes back to click the correct answer again as the, "first" choice, they can then move on to the next puzzle.

  • Please use the code tag when posting your example - it's the C on the editor bar.

    The following may clear up some misunderstandings:

    1. The undo related macros only undo recent variable changes that occur within the current passage, or within passages that are included into the current passage's output via a (display:) macro. The follow three passage example demonstrates this.

    1a. You story's startup tagged passage.
    (set: $variable to "A")
    
    1b. The First passage:
    variable: $variable
    
    [[Next Passage->Second]]
    
    1c. The Second passage:
    (set: $variable to "B")\
    \
    (link-goto: "Return to first passage (don't undo changes)", "First")
    (link-undo: "Return to first passage (undo changes)")
    
    Clicking on the first "Return" related link in the above navigates the story forward in history to the First passage thus all variables are remembered. Clicking on the second "Return" related link navigates the story backwards in history to the First passage thus undoing any recent variable changes.

    2. The following example demonstrates how to test if a variable's value is true or false:
    (set: $answer to true)
    (if: $answer)[The answer variable equals true]
    
    (set: $answer to false)
    (if: not $answer)[The answer variable equals false]
    


    3. Assignment vs Comparison.
    In Harlowe the to operator is used to assign a value to a variable and the is operator is used to compare if two values are equal. This is one of the reasons the following code did not work because to are trying to assign the value true to the $gobacks's isSelected variable within the (if:) macro's condition parameter.
    (if: $gobacks's isSelected to true)(set: $sevmins's isSelected to false)
    ... the other reason it would not of worked is because the (set: $sevmins's isSelected to false) part is not within the square brackets required to define the (if:) macro's associated hook.

    4. Assigning values to Named-Hook references:
    Harlowe 2.0.0 no longer supports this functionality, which means the following code is not valid.
    (click: ?goback)[(set: ?goback to true)]

  • edited March 2017
    greyelf-I just want to say, I realize I have a lot more practice to do before I can say you answered my question :blush: , but it was definitely helpful, so Thank You! :smile: Hopefully soon, I will be able to confirm that this answered my question.
  • Thanks again greyelf! I am a slow learner and still need to go over the harlowe markups to fully understand your answer, but I appreciate your help and explanations!

    However, after I started looking over the Harlowe markups, I decided to go with this:
    |sevmins>[seven minutes]
    
    |threemins>[three minutes]
    
    |fivemins>[five minutes]
    
    (click: ?sevmins)[(replace: ?sevmins)[No. Try Again]]
    (click: ?threemins)[(replace: ?threemins)[Yes! Now you can move to the next puzzle. Look in the box for a [[red cap]]]]
    (click: ?fivemins)[(replace: ?fivemins)[Nope. Try Again]]
    

    It worked and is much simpler than what I was trying before. I have used this:
    (click: ?variable)[(replace: ?variable)]
    

    before, but it didn't cross my mind for some reason until after I reviewed the markups.
Sign In or Register to comment.