Problem With Variables
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
-
- Posts: 22
- Joined: October 25th, 2013, 1:44 am
Problem With Variables
I am trying to create an option so that the player can choose the gender of their character, and that the choice will affect how the character is referenced, i.e. she/he, her/him, etc. I have tried various coding methods, but they all yield the same result: the character is always referenced as female. Here is my code:
If I change the code to two separate [if] [then] clauses instead of an [if] [then] [else] clause, the character is always referenced as male. I posted the most unnecessarily complex version of the code I have written. My reasoning behind trying it this way was that the game might like numerical variable values better than text values. The other, seemingly redundant variable that is defined is used to modify the player's gender in a [modify_unit] tag, which I did not post, as it is not the concern at the moment.
Code: Select all
[message]
speaker=narrator
message= _ "What is your character's gender?"
[option]
message= _ "Female"
[command]
[set_variable]
name=gender_0
value=0
[/set_variable]
[/command]
[/option]
[option]
message= _ "Male"
[command]
[set_variable]
name=gender_0
value=1
[/set_variable]
[/command]
[/option]
[/message]
[if]
[variable]
name=gender_0
value=0
[/variable]
[then]
[set_variable]
name=gender_1
value=0
[/set_variable]
[/then]
[else]
[set_variable]
name=gender_1
value=1
[/set_variable]
[/else]
[/if]
[if]
[variable]
name=gender_0
value=0
[/variable]
[then]
[set_variable]
name=subject_0
value=she
[/set_variable]
[set_variable]
name=subject_1
value=She
[/set_variable]
[set_variable]
name=object
value=her
[/set_variable]
[/then]
[else]
[set_variable]
name=subject_0
value=he
[/set_variable]
[set_variable]
name=subject_1
value=He
[/set_variable]
[set_variable]
name=object
value=him
[/set_variable]
[/else]
[/if]
Re: Problem With Variables
value
is not a valid comparison key to use in [variable]
; try using equals
instead.Also, what is the point of the
gender_1
variable? As far as I see, it is the same as the gender_0
variable.Re: Problem With Variables
So I think the problem is that in the if statment you have
when you should have
I find that this syntax is much less confusing if you use macros. The way I would write the above block is
The most useful macros to know are probably {IF_VAR}, {VARIABLE_CONDITIONAL}, {VARIABLE}, {VARIABLE_OP} and I guess {FOREACH} comes in handy sometimes.
Code: Select all
[if]
[variable]
name = gender_0
value = 0
[/variable]
...
Code: Select all
[if]
[variable]
name = gender_0
equals = 0
[/variable]
...
Code: Select all
[message]
speaker=narrator
message= _ "What is your character's gender?"
[option]
message= _ "Female"
[command]
{VARIABLE gender_0 0}
[/command]
[/option]
[option]
message= _ "Male"
[command]
{VARIABLE gender_0 1}
[/command]
[/option]
[/message]
{VARIABLE gender_1 1}
{VARIABLE_OP gender_1 sub gender_0}
# The prevoius two lines set gender_1 to 1 - gender_0, the opposite value
{IF_VAR gender_0 equals 0 (
[then]
{VARIABLE subject_0 "she"}
{VARIABLE subject_1 "She"}
{VARIABLE object "her"}
[/then]
[else]
{VARIABLE subject_0 "he"}
{VARIABLE subject_1 "He"}
{VARIABLE object "him"}
[/else]
)}
-
- Posts: 22
- Joined: October 25th, 2013, 1:44 am
Re: Problem With Variables
Thank you very much for your help! I shall try to learn how to use the macros.