IF code and multiple var

Hi everyone, I’m having problems with a line of code.
The line looks like this:
*if (gtoken = true) and (ntoken = true) and (atoken = true) and (btoken = true) #Finish.

I even tried already:
*if ((gtoken = true) and (ntoken = true) and (atoken = true) and (btoken = true)) #Finish.

The error it gives me is: Invalid expression at char 39, expected no more tokens, found: NAMED_OPERATOR (and)
There are some conditions(it’s a character creation) that would make the ‘tokens’ turn true from false and allow the reader to go on with the story but even if the code looks legit to me it is wrong

try this

*if ((gtoken = true) and (ntoken = true)) and ((atoken = true) and (btoken = true)) #Finish.

In this case, the trick is to make the code only compares a pair for a single check.
Uhm… that means

*if ((((gtoken = true) and (ntoken = true)) and (atoken = true)) and (btoken = true)) #Finish

Yep, ninja’d.


It doesn’t work either but it gives me a new error at char 36 CLOSED_PARENTHESIS [)]

Szaal it worked ^^ may I please say that I love you? :sweat_smile:

1 Like

When used as part of an #option within a *choice, all of the checks must be within a single pair of parenthesis. So if an extra pair were wrapped around that section of @Nocturnal_Stillness’s sample, giving you something like:
*if (((gtoken) and (ntoken)) and ((atoken) and (btoken))) #Finish.
Then it should work.

Note that the extra pair of parenthesis shouldn’t be necessary outside of a *choice. In other parts of your code, it should work exactly as suggested.

1 Like

Thanks, I already chose Szaal reply for the solution but I apreciate the explanation :hugs: this is all quite new for me! :blush:

No worries. @Minnow’s right.
You just need additional parens to enclose Sam’s @Nocturnal_Stillness code to make it work. Besides, his code looks easier to the eyes, speaking of the balance between right and left…

But either code should work just fine.

1 Like

General principle: give ChoiceScript no more than two things to deal with at a time.


This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the @moderators.