Using "and" and "or"

Hi guys, this one is doing my head in. I just can’t seem to make it work and am getting errors. It’s to allow choices to be selected based on what’s in your inventory (under the *choice menu)

By itself this works for an option
ie: *selectable_if (unicornhair = “Unicorn Hair”) # Trade with Garmr
(also with the ring variable by itself is ok).

However when I try to do this
*selectable_if ((unicornhair = “Unicorn Hair”) OR (Ring = “Ruby Ring”)) #I will not trade with the likes of you.

or this:
*Selectable_if ((unicornhair != “Unicorn Hair”) AND (Ring != “Ruby Ring”)) #I have nothing to trade with you.

It simply wont work. I’ve tried with and without the double brackets but it really doesn’t like it. Can someone see what I’ve done wrong and how to fix it?
Thanks!

“It simply won’t work” doesn’t tell me much. What errors are you actually getting?

Sorry, thought I must be doing something obviously silly with the command.

With the double brackets its
faillicence line 93: Invalid expression at char 33, expected OPERATOR, was: VAR [OR]

with the single brackets it’s showing
faillicence line 93: Invalid expression at char 29, expected no more tokens, found: CLOSE_PARENTHESIS [)]

Switch and and or to lower case (was not aware that was a thing). That fixed it for me.

Also general recommendation: use only lowercases in variable names, due to a few weird circumstances. Pretty much all the code in CS should be lowercase.

2 Likes

You’re the best @Reaperoa. Thank you!

Didn’t realise that uppercase had the potential to mess things up like that

Some notes on your formatting -

  1. Do you have a reason to capitalize your string variables (the stuff between the ""s?) You can trip yourself up by getting capitalization non-standard, so after not seeing the point for months, I just had to edit all of my variables to lowercase.

  2. Is there a reason why unicornhair=“Unicorn Hair”, rather than unicornhair being true or false? If there isn’t more than one type of unicornhair, a boolean might save you some trouble. Then you can use *if (unicornhair) to check whether it exists in your inventory, without typing out the whole thing.

  3. You don’t need to capitalize any commands, and it might cause problems if you do. *selectable_if is also one that should be lowercase.

(I repeated some of @Reaperoa’s advice, oops. It’s good advice though.)

Just cause I can, I’ll link my guide here too. It includes a bit on making your variables easier to use (through booleans and all the little rules). It still a work in progress, but most of the early stuff is there.

Thanks for the link @Reaperoa :smile:

@Sashira I didn’t realise that lower case/capitals made a difference since it was working for other commands in either, will be trying to keep it all to a lower case from now.

This is my first go at coding and I was trying to keep it simple (although maybe I haven’t). I didn’t quite get the true/false thing so that’s why I had it written out the way I did. At the moment, there’s only one variable per item (ie it’s either “Unicorn Hair” or empty ("") since I’m also using it to show up in the inventory without having to add in extra variables for each item. (Also why it’s capitalised, although I guess I could just put a !${ } bracket into the inventory to make sure lower case variables are then capitalised which is probably a better idea for future use.

I was going to have 3 variables for “unicornhair” but since it had practically no impact on the story line I abandoned it. I may have to look into the true/false command more to prevent future issues though.

Thanks for the info, appreciate it :slight_smile: