Howdy, Stranger!

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

Multiple selections in "if" statement

Hello everyone, I am very new to this and trying to figure things out, and I have come across something I just can't seem to find a solution to.

I have a section in the game where I want the player to be able to navigate through 4 different passages, but not be shown the options for passages that they have already visited. The code works for eliminating a single option, but I can't figure out how to tell it to consider two options in the history at once.

Here is part of what my basic code looks like:
(if: (history:) contains "Go to the Snowy Meadow")[[[Go to the Old Barn]]
[[Go to the Abandoned Homestead]]
[[Go to the Town]]]

(elseif: (history:) contains "Go to the Town")[[[Go to the Snowy Meadow]]
[[Go to the Old Barn]]
[[Go to the Abandoned Homestead]]]

That part is working fine, but how would I get it to register if the history contains both "Go to the Town" AND "Go to the Snowy Meadow", and only show the remaining two options for the player to select? Thanks in advance for anyone that can offer any help, I have looked all over and not been able to find anything that covers what I need, and experimenting with syntax hasn't gotten me very far.

Comments

  • You should state which story format you are using, as answers can be different for each one. Based on your examples I am going to assume you are using Harlowe.

    The (history:) contains "Go to the Snowy Meadow" part of your first (if:) macro is known as an expression and both the (if:) and (elseif:) macro can accept more than one expression as long as you separate each expression with an and/or keyword.
    You use and if all the expressions need to be true for something to happen, and you use or if only one of the expressions needs to be true.

    eg. General example
    (set: $var1 to "A")
    (set: $var2 to "B")
    
    (if: $var1 is "A" and $var2 is "B")[This message is displayed if both expressions are true]
    (if: $var1 is "A" or $var2 is "B")[This message is displayed if one or both expressions are true]
    
    eg. Example base on your code.
    (set: $history to (history:))
    
    (if $history contains "Go to the Town" and $history contains "Go to the Snowy Meadow")[
    Do what ever happens if both are true
    ]
    (elseif: $history contains "Go to the Snowy Meadow")[[[Go to the Old Barn]]
    [[Go to the Abandoned Homestead]]
    [[Go to the Town]]]
    
    (elseif: $history contains "Go to the Town")[[[Go to the Snowy Meadow]]
    [[Go to the Old Barn]]
    [[Go to the Abandoned Homestead]]]
    
    notes:
    a. I used a local variable to store a current copy of (history:) because you want to potentially check it multiple times and we don't know what the cost is to generate the array that the (history:) macro returns.

    b. Checking (history:) for a value takes a little longer the more passages the reader has navigated through, so you are writing a story where the reader visits the same passages over and over again (eg a RPG) then (history:) will end up containing a large number of passage names and there for will take longer to search through.
    Under these type of circumstance the screen can start to slow down and become less responsive.
  • HA! Yes, thank you very much, I have been trying to figure this out for AGES. It works now. :)
Sign In or Register to comment.