0 votes
by (120 points)

Okay, so I understand how to set variables. Not a problem. HOWEVER. when defining my variables for example:

(set: $gender to male)

fine, right? [it is fully possible that this is where the mistake lies in which case I am an idiot]

But when attempting to recall that variable by using this: 

So you are a $gender 

it tells me the variable is undefined. But when i defined the variable as such:

(set: $gender to blue)
So you are a (if: $gender is blue)[male]

it works fine. So i tried using:

(set: $gender to male)
(if: $gender is male)[male]

and it still told me that the 'male' was not defined. It has done this with everything that wasnt defined as a color.

Am I doing something wrong ?

2 Answers

+1 vote
by (310 points)

I believe you just need quotes around "male":

(set: $gender to "male")
(print: $gender)

That worked when I tested it.

0 votes
by (159k points)

Please use the Question Tags to state the name and full version number of the Story Format you are using, as answers can vary based on this information. Based on the macro syntax of your example (and the fact that this is the default story format) I will assume you are using Harlowe v2.1.0

FYI: The values you assign to a $variable can be of different data-types, some of the ones that Harlowe supports are listed here. One of those data-types is String which you are using in your 2 of your 4 examples, the other data-type you are using is Harlowe's special Colour type.

1. In your first example you are trying to assign a String (literal) value of male to the $gender story variable, and as explained by @sirjohnthetall (and the Harlowe documentation), a String value need to be wrapped in either single or double quotes. So that example should look like either of the following.

(set: $gender to 'male')

(set: $gender to "male")

2. In your forth example you again assign the String (literal) value of male to the $gender story variable, and then you try to compare the current value in $gender to see if it equals that String value. You again need to wrap both of those String literals in quotes. So your example needs to be changed to any of following.

Both String literals wrapped in single quotes.
 
(set: $gender to 'male')
(if: $gender is 'male')[male]

Both String literals wrapped in double quotes.

(set: $gender to "male")
(if: $gender is "male")[male]

One String literal wrapped in single quotes, the other in double.

(set: $gender to 'male')
(if: $gender is "male")[male]

(set: $gender to "male")
(if: $gender is 'male')[male]

... you will notice in the third & forth of the above examples that the type of quote (single or double) you use is interchangeable, meaning you can use one type of quote to assign the String value and use the other type when doing the comparison.
However for consistency & readability sake I strongly suggest you pick one type of quote and use it exclusively in your code.

...