[SOLVED] Problem with variable $unit and an event calling itself with [fire_event]
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.
[SOLVED] Problem with variable $unit and an event calling itself with [fire_event]
I have an event on post_advance that calls another custom event. This custom event randomizes a gift, and first checks that the gift can be granted. In this case, I want to check if the unit that just advanced has a melee weapon available. If not, the same event is repeated again until a filter is randomly fulfilled and the gift is obtained.
It seems to filter only the first unit, but not subsequent ones that level up in the same turn. Or maybe it's filtering them all causing false positives. I have a problem with the variable unit or maybe i'm using that wrong. Could someone tell me what I'm doing wrong?
Code: Select all
[event]
name=post_advance
id=aww_09_trigger_post_advance_amla_extra_bonus
first_time_only=no
[filter_condition]
{AWW_ENABLED_FEATURE_09}
{AWW_TEST_WAS_AMLA}
[/filter_condition]
[fire_event]
name=aww_09_bonus_selection
[primary_unit]
id=$unit.id
[/primary_unit]
[/fire_event]
[/event]
[event]
name=aww_09_bonus_selection
first_time_only=no
[filter_condition]
{AWW_ENABLED_FEATURE_09}
{AWW_TEST_WAS_AMLA}
[/filter_condition]
{VARIABLE_OP rand_bonus rand(1..17)}
[switch]
variable=rand_bonus
## Max melee/ranged damage/hits :
[case]
value=1,10,12,14
[if]
[not]
[have_unit]
[has_attack]
id=$unit
range=melee
[/has_attack]
[/have_unit]
[/not]
[then]
[fire_event]
name=aww_09_bonus_selection
[primary_unit]
id=$unit.id
[/primary_unit]
[/fire_event]
[/then]
[else]
[modify_unit]
[filter]
x=$x1
y=$y1
[/filter]
[object]
id=aww_amla_melee_damage_object
take_only_once=no
duration=forever
silent=yes
[effect]
apply_to=attack
range=melee
increase_damage=1
[/effect]
[/object]
#name=$this_unit.name+"'"
[/modify_unit]
{AWW_FLOAT_TEXT_CURRENT_SIDE_UNIT _"melee"+": "+_"damage"+"+1" {AWW_COLOR_AMLA}}
[message]
speaker=unit
message= _ "Melee damage +1"
[/message]
[unstore_unit]
variable=unit
[/unstore_unit]
[/else]
[/if]
[/case]
[case]etc...
Last edited by Toranks on November 10th, 2022, 8:16 pm, edited 1 time in total.
Re: Problem with variable $unit and an event calling itself with [fire_event]
I finally managed to filter correctly by changing the filter method. Instead of unit, position x and y.
Also, id or x,y= must be inside [have_unit] not inside [has_attack], another mistake I made.
I leave it here as an example, it will surely be useful when someone searches the forum for something similar:
Also, id or x,y= must be inside [have_unit] not inside [has_attack], another mistake I made.
I leave it here as an example, it will surely be useful when someone searches the forum for something similar:
Code: Select all
[event]
name=post_advance
id=aww_09_trigger_post_advance_amla_extra_bonus
first_time_only=no
[filter_condition]
{AWW_ENABLED_FEATURE_09}
{AWW_TEST_WAS_AMLA}
[/filter_condition]
[fire_event]
name=aww_09_bonus_selection
[primary_unit]
x,y=$x1,$y1
[/primary_unit]
[/fire_event]
[/event]
[event]
name=aww_09_bonus_selection
first_time_only=no
[filter_condition]
{AWW_ENABLED_FEATURE_09}
{AWW_TEST_WAS_AMLA}
[/filter_condition]
{VARIABLE_OP rand_bonus rand(1..17)}
[switch]
variable=rand_bonus
## Max melee/ranged damage/hits :
[case]
value=1,10,12,14
[if]
[not]
[have_unit]
x,y=$x1,$y1
[has_attack]
range=melee
[/has_attack]
[/have_unit]
[/not]
[then]
[fire_event]
name=aww_09_bonus_selection
[primary_unit]
x,y=$x1,$y1
[/primary_unit]
[/fire_event]
[/then]
[else]
[modify_unit]
[filter]
x=$x1
y=$y1
[/filter]
[object]
id=aww_amla_melee_damage_object
take_only_once=no
duration=forever
silent=yes
[effect]
apply_to=attack
range=melee
increase_damage=1
[/effect]
[/object]
[/modify_unit]
{AWW_FLOAT_TEXT_CURRENT_SIDE_UNIT _"melee"+": "+_"damage"+"+1" {AWW_COLOR_AMLA}}
[message]
speaker=unit
message= _ "Melee damage +1"
[/message]
[/else]
[/if]
[/case]
Last edited by Toranks on November 10th, 2022, 8:50 pm, edited 2 times in total.
Re: Problem with variable $unit and an event calling itself with [fire_event]
The code is too complicated for me to parse, but maybe this will help?
And then, when testing whether or not to assign a gift, filter for status. And then, when they receive a melee weapon, change the status.
This approach might be easier to de-bug and get the code working.
Anyhow, good luck. The idea sounds nifty. I am imagining units only carrying bows being given a random melee weapon from a list upon advancement.
Edit: Oh, you solved the problem. Congrats.
A customWiki:
Status: One can add other keys to [status], but they must have boolean values, and they will not do anything meaningful on their own (but can be checked from events and acted upon accordingly). For example, a scenario can set unit.status.my_custom_key to 'yes' or 'no'.
status
called something like has_melee
could keep track of whether or not a melee weapon is held by a unit, including any unit who receives a melee weapon as a gift. Perhaps unit placed
could be used to assign the status.And then, when testing whether or not to assign a gift, filter for status. And then, when they receive a melee weapon, change the status.
This approach might be easier to de-bug and get the code working.
Anyhow, good luck. The idea sounds nifty. I am imagining units only carrying bows being given a random melee weapon from a list upon advancement.
Edit: Oh, you solved the problem. Congrats.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.