What is the syntax for variables on units?
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.
What is the syntax for variables on units?
I have an enemy who is supposed to make a different comment every time he kills a unit. I'm using a variable to track his number of kills, and then a switch statement to pick a sentence for him to say, based on the number of kills.
I want the variable stored on the unit, because there will be multiple units with different things to say.
The code I'm using is below, but doesn't work. He always says the first sentence. The variable correctly increments to 1, but it never increments to 2, no matter how many kills he gets. So, it's not saving the variable, I guess.
Thanks for any help.
I want the variable stored on the unit, because there will be multiple units with different things to say.
The code I'm using is below, but doesn't work. He always says the first sentence. The variable correctly increments to 1, but it never increments to 2, no matter how many kills he gets. So, it's not saving the variable, I guess.
Code: Select all
[event]
name=die
[filter]
side=1
[/filter]
[filter_second]
id=Wizard
[/filter_second]
first_time_only=no
[set_variable]
name=second_unit.variables.EnemiesKilled
add=1
[/set_variable]
[switch]
variable=second_unit.variables.EnemiesKilled
[case]
value=1
[message]
speaker=second_unit
message=_"first sentence"
[/message]
[/case]
[case]
value=2
[message]
speaker=second_unit
message=_"second sentence"
[/message]
[/case]
[case]
value=3
[message]
speaker=second_unit
message=_"third sentence"
[/message]
[/case]
[/switch]
[/event]
Re: What is the syntax for variables on units?
You never unstore second_unit, so incrementing the variable never gets reflected in the actual unit on the map.
Re: What is the syntax for variables on units?
Thanks.
I added this after the [/set_variable] tag and now it works:
I didn't realize you could unstore a unit without storing it first. For some reason, when I tried storing the unit, making the change, and then unstoring it, it didn't work. The variable didn't get incremented at all, so guy never spoke. Anyway, it works now, so thanks again.
I added this after the [/set_variable] tag and now it works:
Code: Select all
[unstore_unit]
variable=second_unit
[/unstore_unit]
Re: What is the syntax for variables on units?
Well, you can't. It's just that unit and second_unit are automatically stored by the game (when applicable) for your convenience so that you don't have to do it manually everywhere.Rubric wrote:I didn't realize you could unstore a unit without storing it first.
Re: What is the syntax for variables on units?
Ah okay, it's all clear to me now. Thanks again.zookeeper wrote:Well, you can't. It's just that unit and second_unit are automatically stored by the game (when applicable) for your convenience so that you don't have to do it manually everywhere.
I macro'd the above code to make it easier to use for different characters. Here it is for anyone interested.
Code: Select all
#define BRAG_ON_KILL WHOBRAGS_ID BRAG1 BRAG2 BRAG3
#
# Allow a character with id of WHOBRAGS_ID to say messages when he gets a kill. The messages are BRAG1, BRAG2, etc. and
# will be said in that order, one message per kill.
#
[event]
name=die
[filter_second]
id={WHOBRAGS_ID}
[/filter_second]
first_time_only=no
[set_variable]
name=second_unit.variables.EnemiesKilled
add=1
[/set_variable]
[unstore_unit]
variable=second_unit
[/unstore_unit]
[switch]
variable=second_unit.variables.EnemiesKilled
[case]
value=1
[message]
speaker=second_unit
message={BRAG1}
[/message]
[/case]
[case]
value=2
[message]
speaker=second_unit
message={BRAG2}
[/message]
[/case]
[case]
value=3
[message]
speaker=second_unit
message={BRAG3}
[/message]
[/case]
[/switch]
[/event]
#enddef
{BRAG_ON_KILL "Bad Guy" _"I got a kill!" _"Ha! I got another one!" _"I'm awesome."}
{BRAG_ON_KILL "Wizard" _"This is the power of Light!" _"Tremble, forces of darkness!" _"The power of Light prevails!"}