Error running script: Error compiling expression

Olzme
22 Feb 2014, 01:25
Hello!

I'm having a bit of trouble figuring out the syntax of an if statement which I'm trying to write for a variable condition on the player object.
At the beginning of the game I ask the player if they are male or female, and later in the game I write an if statement that if the player is male, it displays one message, and if the player is female, it displays a different message.
However I'm getting an error which reads:
" Error running script: Error compiling expression 'player.gender = male': Unknown object or variable 'male' "


I'm thinking it's because I incorrectly set the "are you male or female" question result variable - if someone could look at the code I uploaded and tell me what I'm doing wrong, it'd be greatly appreciated.

Thanks in advance.

george
22 Feb 2014, 01:32
player.gender probably is a string, so just try putting quotes around male in the if check. Like player.gender = "male"

Liam315
22 Feb 2014, 05:42
george wrote:player.gender probably is a string, so just try putting quotes around male in the if check. Like player.gender = "male"


This. Whenever you reference a string in if statements, it must in "quotation marks like these."

HegemonKhan
22 Feb 2014, 08:13
the above two posters are right (though let me also go check your code, just to make sure, after I write this post ~ I'll add an edit to this post, if I spot any other possible problem solely, or on top of the problem mentioned by the other two posters before me):

let me add a bit more commentary (explanation) to what they said:

1. make sure you have:

Object.Attribute = Expression_or_Value
Object_name.gender = Value
Object_name.gender = male // actually it has to be: "male", but I get to this explanation further down... so ignore the lack of the needed quotation marks here around 'male'

as if you just have the Attribute (it's called a "Variable" for quest's terminology here):

Variable = Expression_or_Value
Variable_name = Value
gender = male

you can't use ('load') it anywhere else, as it's not 'saved', as it's not attached to an Object.

2. you must put the quotation marks on the Value, as the Value's is of the Attribute's Type of a 'String', and those quotation marks TELL THE QUEST ENGINE that the Value is indeed a 'String' Type of Value as the Attribute is a 'String' Type. So, you want it to look like this (it's bolded):

it's annoying to remember... not easy to do so... (also, the other exception is if your Attribute Type is an 'Integer', then you also do *NOT* put the quotation marks around the number, "4" -> ERROR!, "4" = 'String' :: Attribute Type = 'int' -> String = Integer~int ... HUH?!... ERROR!)

(this is just to help you understand the syntax better)
Object.Attribute = Expression_or_Value
Object_name.Attribute_name = "Value"
Object_name.gender = "Value"
Object_name.gender = "male" // or: "female"

if you don't use the quotation marks, the QUEST ENGINE (IS PROGRAMMED TO RECOGNIZE IT AS an actual OBJECT with that as its Name Attribute, and not merely as a 'String' Type Value for an String Type Attribute), and thus is searching for an Object with having that (ie: male) as it's Object Name (ID) Attribute, hence the ERROR of finding no such actual Object called 'male'.

3. lastly, I wouldn't use 'gender', as this (along with 'article' too) is already a built-in Attribute for grammer usage (he,she,her,him,it), and it gets overriden by your ' Object.gender = "male" ', and thus you no longer have this built-in grammer Attribute.

http://quest5.net/wiki/Gender
http://quest5.net/wiki/Article

I personally like to do this labeling system:

Attribute Name:

gender_string
~OR~
gender_x

HK.gender_string = "male"

msg ("HK is a " + HK.gender_string + ".")
// outputs: HK is a male.

msg (HK.gender + " is a " + HK.gender_string + ".")
// outputs: He (or: 'It' ~ not sure which is used, lol ~ I hate grammer! lol) is a male.

Olzme
22 Feb 2014, 19:59
Thank you so much everyone! I changed the attribute name and included the quotations and everything seems to be fine now.