"If..." script and multiple conditions. Proper syntax?
waturi
06 Jun 2013, 22:23Can anyone enlighten me as to the proper syntax to use when having an "If..." script check more than one condition and using the expression field in the GUI (ie. not directly editing the code)?
I have 3 specific situations, they are:
1. If object.attribute=1 AND object has flag, objectflag, Then...
2. If object.attribute=1 AND object does not have flag, objectflag, Then...
3. If object.attribute=5 AND (object.attribute - player.attribute)<1, Then...
note, "attribute" and "objectflag" are just generic terms I use for this example. "Attribute" is an integer and "objectflag" is a...flag? (not sure exactly what a flag is...a boolean attribute?)
I think I know the syntax for checking an integer attribute but not for checking a flag.
Again, I'm looking for the proper syntax to use in the "expression" field of the GUI script editor, not the code syntax.
Thanks in advance for any help.
I have 3 specific situations, they are:
1. If object.attribute=1 AND object has flag, objectflag, Then...
2. If object.attribute=1 AND object does not have flag, objectflag, Then...
3. If object.attribute=5 AND (object.attribute - player.attribute)<1, Then...
note, "attribute" and "objectflag" are just generic terms I use for this example. "Attribute" is an integer and "objectflag" is a...flag? (not sure exactly what a flag is...a boolean attribute?)
I think I know the syntax for checking an integer attribute but not for checking a flag.
Again, I'm looking for the proper syntax to use in the "expression" field of the GUI script editor, not the code syntax.
Thanks in advance for any help.

jaynabonne
06 Jun 2013, 22:571. object.attribute=1 AND GetBoolean(object, "objectflag")
2. object.attribute=1 AND NOT GetBoolean(object, "objectflag")
3. object.attribute=5 AND (object.attribute - player.attribute)<1
If I understand you correctly...
2. object.attribute=1 AND NOT GetBoolean(object, "objectflag")
3. object.attribute=5 AND (object.attribute - player.attribute)<1
If I understand you correctly...
waturi
06 Jun 2013, 23:05Looks like it did the trick...thanks a ton.
A couple questions though...
So it looks like a flag is just a boolean attribute...would #2 work correctly if the object did not have the "objectflag" attribute at all, or only if the "objectflag" was set to false.
Also, any idea why every other attribute check is in the "object.attribute" format but boolean checks are in the "object, 'objectflag'" format
A couple questions though...
So it looks like a flag is just a boolean attribute...would #2 work correctly if the object did not have the "objectflag" attribute at all, or only if the "objectflag" was set to false.
Also, any idea why every other attribute check is in the "object.attribute" format but boolean checks are in the "object, 'objectflag'" format

jaynabonne
07 Jun 2013, 00:29GetBoolean will return false if there is a boolean false value, if the attribute is not defined, or if it's not boolean. (So basically, it only returns true if the attribute is a boolean with value true.
) It's a safe way of querying the value, if there's a chance it's not defined yet.
If you know for sure that there is a boolean attribute already defined, then you can definitely just use object.attribute directly.

If you know for sure that there is a boolean attribute already defined, then you can definitely just use object.attribute directly.
HegemonKhan
07 Jun 2013, 01:22Indeed, "flags" are booleans (and booleans are basically true~false string attributes), so let me try to explain these concepts:
(I'm too lazy to give the GUI~Editor instructions, as they're a lot of work to do, so this is why I'm just giving a conceptual understanding, and for my examples, I'm going to use quasi code, as again it is much faster to do so lol, so hopefully you'll be able to follow along, despite me using my examples in more code form than in the GUI~Editor form)
let's say that you see a key to open up a door, but the key is out of your reach.
if you.string_label_"walking",
then you can't get the key
~~
if you.string_label_"flying",
then you can get the key
vs
if you.boolean_label_"walking" = true,
then you can't get the key
if you.boolean_label_"walking" = false,
then you can get the key
~~
if you.boolean_label_"flying" = false,
then you can't get the key
if you.boolean_label_"flying" = true,
then you can get the key
by using boolean's true or false, we can quickly and easily change~set ("FLAG") it (true->false or false->true). But, as you can hopefully see, in using a string attribute, we don't have this ability to "FLAG", as we don't have the "= true or false" on string attributes.
------
you.boolean_label_"flying" = false
you.verb_drink.object_flying_potion -> set ("FLAG"): you.boolean_label_"flying" = true
now that you're ("FLAGGED" as) "flying", you can get the key
-----------------------------------------------
a similar usage, but without using the boolean's true~false, is simply with a string attribute:
you.flying,
since you're (string attributed with) "flying", you can get the key
------------
do you see, how sometimes you want to use an attribute with true~false (via boolean attributes) vs just an attribute (via a string) ???
-----------
a string attribute is like: "I~IT AM DOING THIS" .... such as: you.flying (I~IT = you) (AM DOING THIS = flying)
a boolean attribute is like: "I~IT AM DOING THIS YES:TRUE or NO:FALSE"... and so you need the usage of "if" along with it: if (you.flying=true or false), then do whatever script. (I~IT = you) (AM DOING THIS = flying) (and then "are you truly flying... or are you not flying?" = YES:TRUE or NO:FALSE)
HK EDIT: actually, you can use "if" with string attributes too, such as: if (you.flying), but the conditional is whether you've got the attribute ("flying") or not, contrasting with a boolean attribute, of whether not only if you've got that attribute, but also of whether it is true or not too.
---------
if that is a bit confusing, then this might be a much simplier example:
on~off (much easier to understand than with the concepts of "walking" vs "flying")
a string attribute: computer.on -> the computer is turned on
a boolean attribute (way method 1): computer.on=true -> the computer is turned on
a boolean attribute (way method 2): computer.off=false -> the computer is turned on
a string attribute: computer.off -> the computer is turned off
a boolean attribute (way method 1): computer.off=true -> the computer is turned off
a boolean attribute (way method 2) : computer.on=false -> the computer is turned off
let's say we've got a computer turned off, so we SET ("FLAG") the computer's attribute to this:
a string attribute: computer.off -> The computer is turned off
a boolean attribute (way method 1): computer.off=true -> The computer is turned off
a boolean attribute (way method 2): computer.on=false -> The computer is turned off
now, we press the computer's power button, and so we're changing or SETTING ("FLAGGING") the computer's attribute to this (see below), so that the game engine recognizes that the computer is now on (and we can write the "if" scripts for it too. for example: if computer.on=true, then you play games on the computer):
a string attribute: computer.on -> the computer is turned on
a boolean attribute (way method 1): computer.off=false -> the computer is turned on
a boolean attribute (way method 2): computer.on=true -> the computer is turned on
(I'm too lazy to give the GUI~Editor instructions, as they're a lot of work to do, so this is why I'm just giving a conceptual understanding, and for my examples, I'm going to use quasi code, as again it is much faster to do so lol, so hopefully you'll be able to follow along, despite me using my examples in more code form than in the GUI~Editor form)
let's say that you see a key to open up a door, but the key is out of your reach.
if you.string_label_"walking",
then you can't get the key
~~
if you.string_label_"flying",
then you can get the key
vs
if you.boolean_label_"walking" = true,
then you can't get the key
if you.boolean_label_"walking" = false,
then you can get the key
~~
if you.boolean_label_"flying" = false,
then you can't get the key
if you.boolean_label_"flying" = true,
then you can get the key
by using boolean's true or false, we can quickly and easily change~set ("FLAG") it (true->false or false->true). But, as you can hopefully see, in using a string attribute, we don't have this ability to "FLAG", as we don't have the "= true or false" on string attributes.
------
you.boolean_label_"flying" = false
you.verb_drink.object_flying_potion -> set ("FLAG"): you.boolean_label_"flying" = true
now that you're ("FLAGGED" as) "flying", you can get the key
-----------------------------------------------
a similar usage, but without using the boolean's true~false, is simply with a string attribute:
you.flying,
since you're (string attributed with) "flying", you can get the key
------------
do you see, how sometimes you want to use an attribute with true~false (via boolean attributes) vs just an attribute (via a string) ???
-----------
a string attribute is like: "I~IT AM DOING THIS" .... such as: you.flying (I~IT = you) (AM DOING THIS = flying)
a boolean attribute is like: "I~IT AM DOING THIS YES:TRUE or NO:FALSE"... and so you need the usage of "if" along with it: if (you.flying=true or false), then do whatever script. (I~IT = you) (AM DOING THIS = flying) (and then "are you truly flying... or are you not flying?" = YES:TRUE or NO:FALSE)
HK EDIT: actually, you can use "if" with string attributes too, such as: if (you.flying), but the conditional is whether you've got the attribute ("flying") or not, contrasting with a boolean attribute, of whether not only if you've got that attribute, but also of whether it is true or not too.
---------
if that is a bit confusing, then this might be a much simplier example:
on~off (much easier to understand than with the concepts of "walking" vs "flying")
a string attribute: computer.on -> the computer is turned on
a boolean attribute (way method 1): computer.on=true -> the computer is turned on
a boolean attribute (way method 2): computer.off=false -> the computer is turned on
a string attribute: computer.off -> the computer is turned off
a boolean attribute (way method 1): computer.off=true -> the computer is turned off
a boolean attribute (way method 2) : computer.on=false -> the computer is turned off
let's say we've got a computer turned off, so we SET ("FLAG") the computer's attribute to this:
a string attribute: computer.off -> The computer is turned off
a boolean attribute (way method 1): computer.off=true -> The computer is turned off
a boolean attribute (way method 2): computer.on=false -> The computer is turned off
now, we press the computer's power button, and so we're changing or SETTING ("FLAGGING") the computer's attribute to this (see below), so that the game engine recognizes that the computer is now on (and we can write the "if" scripts for it too. for example: if computer.on=true, then you play games on the computer):
a string attribute: computer.on -> the computer is turned on
a boolean attribute (way method 1): computer.off=false -> the computer is turned on
a boolean attribute (way method 2): computer.on=true -> the computer is turned on