So i have one working IF statement where I am using if player has inventory item but now i am trying to do another against a Bool variable setting, here's what I have so far:
function oCar_Look()
{
if (caropen = false) {player.Say("That's my car, it's locked");}
else {player.Say("It's unlocked!");}
}
Not 100% sure what the actual question is, but I think the following should work:
if (caropen==false) player.Say("That's my car, it's locked");
else if (caropen==true) player.Say("It's unlocked!");
(You don't need to nest the player.Say insice {} because you're only using a single action for the IF statement.
If you're wondering why it doesn't work - you're using the assignment (=) operator, when you should use the comparison (==) instead.
function oCar_Look()
{
if (caropen == false) player.Say("That's my car, it's locked");
else player.Say("It's unlocked!");
}
Also be sure if the bool value 'caropen' exists and is set.
I'll add that you can change caropen==false to !caropen as putting a ! in front of a bool will make it negative.
Yes, double == to check if true/false... Regardless of that... show us your if player has inventory script...
Great thanks for your swift responses I will use the == and clean up my {}
Here's the shortest version:
function oCar_Look()
{
if (caropen) player.Say("It's unlocked!");
else player.Say("That's my car, it's locked");
}
Wow I never realised there were so many different ways to achieve the same thing!
Quote from: CaptainD on Fri 09/11/2018 12:23:16
Wow I never realised there were so many different ways to achieve the same thing!
Well, some results above are achieved with
redundant operations.
"If" statement tests the result of boolean expression.
When you do "if (var)" that expression is calculated as boolean value of a variable.
When you do "if (var == true), then
two operations are performed: 1) boolean value of a variable, 2) comparing boolean value to another boolean value, and result is tested by "if".
It's like, you may do "x = 2 + 2;" or "x = 4", the result is same but in one case you are doing excessive calculation.
Same with "if/else if", if your condition in the "else if" is strictly the inverse of the first condition under "if", then its redundant and "else" will suffice.
Very informative, thankyou very much CW!