+1 vote
by (2.2k points)
edited by

This is my code, idk what to do to make this work. I want the statement that comes after this code to work when "let's go gambling"  is in the history but "You're hungover, sleep" is not true, do you understand what I'm getting at? I need help to make this code work, if you could help, that'd be fantastic.

(if: (history:) contains "Let's go gambling" not "You're hungover, sleep")

as well as this one 

(if: (history:) contains "Let's go gambling" (unless: (history:) contains "You're hungover, sleep"))
(if: (history:) contains "Let's go gambling" (unless:) (history:) contains "You're hungover, sleep")

both don't work and I don't know what to do

1 Answer

+2 votes
by (63.1k points)
edited by
Best answer

 Something like this is probably what you're looking for: 

(if: (history:) contains "Let's go gambling" and not (history:) contains "You're hungover, sleep")

edit. Should be

(if: (history:) contains "Let's go gambling" and not ((history:) contains "You're hungover, sleep"))

Some notes:

  • It really isn't a great idea to include punctuation in your passage names, you might want to alter them to omit the apostrophes and commas. 
  • The 'not' keyword flips an evaluation: i.e. evaluations that would normally yield true will instead yield false and vice versa. 
  • The 'and' keyword evaluates subexpressions, that is, if both expressions are true then the whole thing is true. The 'or' keyword is similar, if either one of the subexpressions is true, then the whole thing evaluates to true. Regardless, each subexpression needs to be a complete expression in its own right. For example: 
(if: $x < 2 and is not 1)

The subexpression 'is not 1' can't be evaluated on its own, even though harlowe 2.x will try to figure out what you mean. 

(if: $x < 2 and $x is not 1)
(if: $x < 2 and it is not 1)

Both subexpressions in both examples are complete and make sense. 


by (2.2k points)
I've rewritten the code with your help and it's giving me and error that says "I can only use 'not' to invert booleans, not an array", do you know why that is?

Thank you so much by the way, this was helpful because I didn't think of that at all.
by (63.1k points)

Sorry I should've mentioned I didn't test that code. I think I needed to group part of it with parens like so: 

(if: (history:) contains "Let's go gambling" and not ((history:) contains "You're hungover, sleep"))

This will force the grouped code to evaluate first, which will make it a boolean so the not operator can run on it. In other words, the problem with my initial example was order of operations. 

I'm fairly confident that should solve the issue, but I don't have access to my computer right now to test it, and won't until tonight. If that doesn't work, and no one else gets back to you first, I'll be able to help you later on. 

by (159k points)

The (history:) macro has to generate the Array it returns each time it is used because the list of Passage names it contains is not stored internally in that format, and generating that Array takes both time and resources.

If you plan to reference that (history:) Array multiple times within the same Passage I suggest you store the value within a (temporary) variable first, and then use that variable instead.

(set: _history to (history:))

(if: _history contains "Let's go gambling" and not (_history contains "You're hungover, sleep"))[..true..](else:)[...false..]

I also suggest not using punctuation characters in your Passage names. 

by (2.2k points)
ooh! thank you, I was just wondering how to make it a variable. That's helpful, thank you.