I'm sure this is simple, but I'm very new to Twine and hoping someone is willing to help.
I want to have scenarios where the number of party members needs to = 2 in order to pass a section of the game.
How I've currently done it:
Set party to 1 in main screen.
Set party to 2 once you meet the second member.
If party = 2 on encounter, move on to X screen.
If party < 2 on encounter, move to Y screen (game over).
Right now though it's displaying both options upon encounter and giving an error message that the script needs to be boolean.
Hmmkay. How would you all accomplish what I am trying to do here? If it helps to upload my HTML file I can, just on my mobile right now so don't have it.
Thanks so much for anyone who responds!!
Comments
Now i'm not sure if this is what you want, but you can try this:
Main screen: Meeting second member: Encounter screen: Hope this helps.
The reason this line of code does not work is because in Javascript (which TwineScript is based on) the equal sign = is used to indicate assignment.
So your if macro was telling the story format to do the following:
a. Change the value of the party variable to 2
b. Check if the result of point A was true, which causes an error.
As xamaxific suggested it can be better to use the to and is keywords for assignment and equals, that way you won't confuse = with either == or === (assignment with comparison).
The modules in question really are:
- Act I: Escape the Forest (where the initial party value is set to 1)
- Investigate bushes (where it is set to 2)
- Fight! (where the value matters)
- Killed by caterpillar (where the fight option sends you even if you've investigated the bushes and acquired Marshy)
- Acquired the blue ocarina (where the fight option SHOULD send you if you've investigated the bushes)
I'm going to later try applying this same mechanic to the fight with the Captain of the Guard and then need to figure out inventory stuff because having done the caterpillar fight and putting the ocarina in your inventory will be required to leave this first level of the game... but, baby steps.
Thoughts?
This results in the (if:) macro trying to compare a variable named party to the value of 2, the variable does not exist so Harlowe creates it and gives it a default value of zero, which obviously does not equal 2 so the (else:) macro is used.
So I moved the (set: $party to 1) to the "Behind Me" passage thinking I had solved all my problems. But alas, for some reason it is still resolving to the "else" logic in "Fight!" every single time even though I'm sure to go "Investigate Bushes" first so that party should be set to +1 and therefore be >= 2.
see: JavaScript Comparison and Logical Operators
It is a common mistake to confuse = with == so it is generally a good idea to use the TwineScript to and is keywords instead.
Both of the (if:) macros in your Let's do this. Star power! passage are incorrect:
a. (if: $party = 2) should be (if: $party == 2) if you want to use equal signs.
I suggest using (if: $party is 2) instead.
b. (if: $party = <2) should be (if: $party <= 2) with no space character between the < and the = characters.
It turns out in the earlier scenario where I was having issues even after having addressed the later scenario's errors that haven't been fixed yet there, that the "else" command was causing the problem. For some reason it always went to the "else" passage even if the party was set to 2. BUT when I killed "else" and just said:
(if: $party is 2)[(goto: "Acquired blue ocarina.")]
(if: $party is 1)[(goto: "Killed by caterpillar.")]
Then everything works fine.
Glad to have solved it and appreciate all your input helping out a n00b.