creating delayed events (replacing variable with its value) issue
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.
creating delayed events (replacing variable with its value) issue
Hoy there, I am looking for solution how to create event which performs action few turns later for multiplayer.
For example I have following raze village menu item, which razes village. The unit performing the raze action cannot move or attack and after three turns it razes the village. OK so far no problem, but what if you want to start razing another village while razing one?
And here comes the issue!
I have discovered solution, which gives the action id and then creates event with responding id. But the id variable needs to be replaced with its value at this point. Which is limting. In the example code i have created solution to perform three actions at once, i can make it ten or twenty by coping that line of code which places the event, but the thing i am asking for is, if there is a possibility to overcome this limitation.
So the question is; Is there a possibility how to replace a variable with its value ?
Or alternatively do you know different way to create multiple specified events that perform some actions few turns later ?
P.S.: This is example code which i simplified from original to demonstrate the issue. There might be syntax or even logical mistakes which i dont need to be corrected.
For example I have following raze village menu item, which razes village. The unit performing the raze action cannot move or attack and after three turns it razes the village. OK so far no problem, but what if you want to start razing another village while razing one?
And here comes the issue!
I have discovered solution, which gives the action id and then creates event with responding id. But the id variable needs to be replaced with its value at this point. Which is limting. In the example code i have created solution to perform three actions at once, i can make it ten or twenty by coping that line of code which places the event, but the thing i am asking for is, if there is a possibility to overcome this limitation.
So the question is; Is there a possibility how to replace a variable with its value ?
Or alternatively do you know different way to create multiple specified events that perform some actions few turns later ?
Code: Select all
[event]
name=start,side_turn
id=raze_MI
first_time_only=no
[set_menu_item]
[filter_location]
terrain=*^V*
[filter]
side=side number
[/filter]
[not]
terrain=*^Vrzd
[/not]
[/filter_location]
[command]
#setting ID for specifying action (1-3)
{IF_VAR razeID equals 3 (
[then]
[set_variable]
name=razeID
value=1
[/set_variable]
[/then]
[elseif]
[variable]
name=razeID
greater_than_equal_to=1
[/variable]
[then]
{VARIABLE_OP razeID add 1}
[/then]
[/elseif]
[else]
[set_variable]
name=razeID
value=1
[/set_variable]
[/else]
) }
#storing unit, setting turns, placing halo and event
[store_unit]
[filter]
x=$x1
y=$y1
[/filter]
variable=razist$id
#kill=yes (not in this case)
[/store_unit]
[set_variable]
name=turn_count_raze$id
value=3
[/set_variable]
[modify_unit]
[filter]
id=razist$id.id
[/filter]
moves=0
attacks_left=0
[/modify_unit]
[item]
x=$x1
y=$y1
halo=path/to/files[1-5].png
#visible_in_fog=not (doesnt work for halo sadly)
name="razehalo"
[/item]
{IF_VAR razeID equals 1 ( [then]
{RAZE_EV 1 }
[/then])}
{IF_VAR razeID equals 2 ( [then]
{RAZE_EV 2 }
[/then])}
{IF_VAR razeID equals 3 ( [then]
{RAZE_EV 3 }
[/then])}
[/command]
[/set_menu_item]
[/event]
#define RAZE_EV ID
[event]
name= side Razist{ID}.side turn refresh
id=raze{ID}ev
{IF_VAR turn_count_raze{ID} equals 1 (
[then]
[terrain]
terrain=Vrzd
layer=overlay
x,y=razist{ID}.x,razist{ID}.y
[/terrain]
[remove_item]
x,y=razist{ID}.x,razist{ID}.y
[/remove_item]
[/then]
[else]
[modify_unit]
[filter]
id=razist{ID}.id
[/filter]
moves=0
attacks_left=0
[/modify_unit]
[/else]
)}
[remove_event]
id=raze{ID}, razist{ID}killed
[/remove_event]
{CLEAR_VARIABLE razist{ID}}
[/event]
#enddef
Re: creating delayed events (replacing variable with its value) issue
thanks, I am feeling dumb i did not find this despite the fact i have been searching before posting
Re: creating delayed events (replacing variable with its value) issue
hoy there, i wanted to get rid of some lines in the code and use unit id as a identifier for delayed events. Well i got stuck cause variable with the unit id in the name is never created. I even found creating veriables with unit id in the name in the examples in manual, so i dont get why... its most propably me being dumb in some way again xD
this creates no variables :{ but if i change the tempUnit.id for tempUnit.x it creates variable with its X coordinate in the name.
I ve been searching, if its forbidden to use any signs used by id in variable names but its just letters, dash and number, on contrary i found example creating variable with unit id in name sooo i dont get it and kindly ask you for info how this works :]
the example: https://wiki.wesnoth.org/VariablesWML/H ... s_in_names
Code: Select all
[store_unit]
[filter]
x,y={X},{Y}
[/filter]
variable=tempUnit
kill=no
[/store_unit]
[store_unit]
[filter]
x,y=$tempUnit.x,$tempUnit.y
[/filter]
variable=delEvUnit_$tempUnit.id
kill=yes
[/store_unit]
[set_variable]
name=test_$tempUnit.id
value=123
[/set_variable]
I ve been searching, if its forbidden to use any signs used by id in variable names but its just letters, dash and number, on contrary i found example creating variable with unit id in name sooo i dont get it and kindly ask you for info how this works :]
the example: https://wiki.wesnoth.org/VariablesWML/H ... s_in_names
Re: creating delayed events (replacing variable with its value) issue
okay... its the dash, which is actually a minus sign, what is causing the problem ... still me wondering if it is possible to get just the id number? cause id is unittype-number.
Re: creating delayed events (replacing variable with its value) issue
haha underlying_id is the response
Re: creating delayed events (replacing variable with its value) issue
You are not intended to create variables for units like that. Consider
[set_variable]
name=tempUnit.variables.new_value
value=123
[/set_variable]
followed by unstore.
[set_variable]
name=tempUnit.variables.new_value
value=123
[/set_variable]
followed by unstore.
- Celtic_Minstrel
- Developer
- Posts: 2241
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: creating delayed events (replacing variable with its value) issue
You can also put
[set_variable]
inside [modify_unit]
. That would change Ravana's example to this:Code: Select all
[modify_unit]
id=$tempUnit.id
[set_variable]
name=new_value
value=123
[/set_variable]
[/modify_unit]