Invalid expression help

I was doing the random test when I got the error Invalid expression at char 44, expected no more tokens, found: CLOSE_PARENTHESIS [)]

Here is the code. But I think if I play through the game manually it seems to work fine so just wanted a second opinion to see if there was something wrong with my code or if it’s a weird randomtest glitch.
Thanks.

*selectable_if ((crush = "Daisy") and (daisyfriendship >75)) or ((crush = "Julia") and (juliafriendship >75)) or ((crush = "Emily") and (emilyfriendship >75)) #It went quite well 

Try to put another parenthesis to surround the whole conditions. Or put spaces between the “greater than >” signs and the numbers.

I think if you want to have multiple sets of possible conditions you still need to open with as many parathesis as there are conditions…
like

*if ((((((one) and (two)) or (three) and four)) or (five) and six))

or something like that.

there is a way, but I keep forgetting it

Sometimes I do it like this…

*if (crush = "Daisy")
  *selectable_if (daisyfriendship > 75) #It went quite well.

*if (crush = "Julia")
  *selectable_if (juliafriendship > 75) #It went quite well.

*if (crush = "Emily")
  *selectable_if (emilyfriendship > 75) #It went quite well.

It may be lengthy, but it’s easier on the eyes :slight_smile:

2 Likes

Could also use temp variables to simplify the conditional statement inside the choice block.

*temp dfriend (crush = "Daisy") and (daisyfriendship > 75)
*temp jfriend (crush = "Julia") and (juliafriendship > 75)
*temp efriend (crush = "Emily") and (emilyfriendship > 75)
*choice
  *selectable_if ((dfriend or jfriend) or efriend) #It went quite well
4 Likes

The parentheses always need to be grouped in pairs, and you have three sets of ((___)) with nothing distinguishing them; they’ll need to be made into a ‘set’ of two as well.

*selectable_if (((crush = "Daisy") and (daisyfriendship >75)) or ((crush = "Julia") and (juliafriendship >75))) or ((crush = "Emily") and (emilyfriendship >75)) #It went quite well 

That should work, I think – though there are a few different styles to grouping parentheses that are valid, as long as everything is in pairs.

I find the syntax highlighter really useful to keep track of my parentheses because it highlights which brackets go together when I move through the text with my caret.

2 Likes

Could someone please update the wiki with this? I think this is one of the things giving most people a headdache.

Cause it gets so messy if you wanna do the whole
‘this option should show if EITHER these two variables together, this one variable OR either of these two meet these requirements’ thing (I still can’t wrap my head around how that example would even be coded)

1 Like

The way I usually try to approach parsing these is by setting out my chain and then adding parentheses in pairs. For your example, I’d jot them down and then work through adding the parentheses like this:

Step 1 *if (A and B) or C or D or E
Step 2 *if ((A) and (B)) or (C) or (D) or (E) (one pair and three stragglers)
Step 3 *if ((A) and (B)) or ((C) or (D)) or (E) (two pairs, one straggler)
Step 4 There are a few ways this final step could go – I might reorder to make it clearer

  • *if (((C) or (D)) or (E)) or ((A) and (B)) This has all my ‘or’ parts together at the front to make it easier to keep track, and now I have two sets: set (((C) or (D)) or (E)) and set ((A) and (B)): .
  • *if (((A) and (B)) or ((C) or (D))) or (E) This keeps the original order but still keeps my ‘and’ condition grouped together correctly.

That example looks a little mystifying with all the letters, but if the variable names are clear, the stat check’s logic can be easier to follow:

The guards dash towards you, spears raised.
*choice
     #Yell, 'Halt in the name of Their Majesty, ruler of the known world!'
          *if (((monarch > 60) and (monarchs_favour)) or ((commanding > 65) or (persuasion > 75))) or (burly > 80)
               Astoundingly, they do.
6 Likes

Thanks <3
And just so I get this in my head:

for EITHER of any it’d be:

*if ((((a) or (b)) or (c)) or (d))

(if any of these applies)
And for either of sets it’d be

*if (((a) or (b)) or ((c) and (d))

if either of a or b apply, OR c and D apply at the same time.
right?

1 Like

Yes, exactly.

Yes, though your example has an extra parenthesis in the beginning. As two pairs, it’d be:

*if ((a) or (b)) or ((c) and (d))

1 Like

So for the same line I am now getting the error Invalid expression at char 99, expected no more tokens, found: NAMED_OPERATOR [or]

*selectable_if (((crush = "Daisy") and (daisyfriendship > 75)) or ((crush = "Julia") and (juliafriendship > 75)) or ((crush = "Emily") and (emilyfriendship > 75))) #It went quite well 

Maybe this might work:

*selectable_if ((crush = "Daisy") and (daisyfriendship > 75) or (crush = "Julia") and (Juliafriendship > 75) or (crush = "Emily") and (Emilyfriendship > 75)) #It went well

The set of three closing parenthesis needs to come after juliafriendship.

*selectable_if (((crush = "Daisy") and (daisyfriendship > 75)) or ((crush = "Julia") and (juliafriendship > 75))) or ((crush = "Emily") and (emilyfriendship > 75)) #It went quite well 

Try that?

1 Like