Howdy, Stranger!

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

Party recognition issue

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

  • First of if you want to check if a variable is a certain number you need to use
    (if: $party is 2)
    
    rather than (if: $party = 2)
    Now i'm not sure if this is what you want, but you can try this:
    Main screen:
    (set: $party to 1)
    
    Meeting second member:
    (set: $party to $party + 1)
    
    Encounter screen:
    (if: party >= 2)[(goto: "X screen")]
    (else:)[(goto: "Y screen")]
    
    Hope this helps.
  • You need to state which story format you are using, as answers can be different for each one. xamaxific's answer is assuming you are using Harlowe.
    If party = 2 on encounter, move on to X screen.
    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).
  • Thanks, y'all. This is helpful and I think there are some subtle differences in what I was doing that will help. I will be sure to circle back once I have time to try a fix to see if this worked. And yes, using Harlowe.
  • OK, so I've tried this, as well as some variations, with no luck. I saved out the file and attached it here.

    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?
  • In the Fight! passage you have left off the dollar sign $ at the start of the $party variable name in the (if:) macro.

    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.
  • It wasn't working even with that change THEN I had an epiphany! Because the game was sending the user back through the crossroads, it was resetting the party to 1 right after setting it to +1 before they moved up to the next area.

    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.
  • In Javascript (and TwineScript) a single equals sign = is use used if you want to assign a value to a variable, and a double (or triple) equals sign == (or ===) is used if you want to compare that two values are equal (and of the same datatype).
    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.
    (set: $var to "value")
    (if: $var is "value")[var equals value]
    

    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.
  • Thanks. This is helpful information to know. I've never written any code in my life aside from HTML/CSS.

    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.
Sign In or Register to comment.