Setting up multiple 'if' scripts

So there's probably a way to do this that I'm missing; it's likely really obvious too, but I'll share what I'm trying to do anyways just in case someone can help point me in the right direction.

So, the player starts off and interacts with a terminal; this terminal has 3 options - Set their name, gender & race/species. Each has its own display verb and after using one I have the script to set a variable corresponding to each respectively. IE. if the player uses the 'set name' verb then afterwards the script sets the variable for 'TerminalName' to true. I want to make it so that after the player has interacted with all three options (and thus turned all three respective variables to true) that the exit unlocks.

My question then is whether there's a way to set up an 'if' function that requires all three variables to be true to work. If all three variables are not true, then I'd like to be able to keep the exit locked so that it can display its respective 'you can't go this way' dialogue.


Io

What you're looking for is "and".

if(OneThing=True and OtherThing=True and ThirdThing=True){
//All three are true, do something
}
else{
One or more are not true, do something else
}

Hope this helps!


My question then is whether there's a way to set up an 'if' function that requires all three variables to be true to work.

The expression for the if statement would be variable1 and variable2 and variable3.

The and operator is true only if the expressions on both sides of it are true.

If you're doing more stuff with boolean values, you may also want to know about not a (which is true only if a is false) and a or b (which is true unless a and b are both false).

If there's a chance of the variables being unset, you can use GetBoolean in conjunction with and.
For example, if (GetBoolean(object1, "attributename") and GetBoolean(object2, "attributename")) {


Log in to post a reply.

Support

Forums