[Engine] WML [tunnel] delayed_variable_substitution tag
Moderator: Forum Moderators
Forum rules
Before posting a new idea, you must read the following:
Before posting a new idea, you must read the following:
[Engine] WML [tunnel] delayed_variable_substitution tag
So I was trying to make a map where units can teleport across the east-west border, meaning the world basically wraps around like in a game of civilization or something. I just spent a couple hours figuring out why this didn't work:
As you can probably easily tell after reading the name of this topic, it failed because the variables didn't substitute in at the tunnel's creation time. Instead, whenever you move a unit, each tunnel then checks the values of
I tried using
This works just fine, but it's more complicated than seems necessary, and it was a royal pain in the butt to figure out the first time. If [tunnel] had a delayed_variable_substitution tag, not only would it save code like this from pointless nested events, but just seeing it on the wiki would encourage wml authors to think about when variable substitution happens. That would definitely be a good thing, since I'm sure I'm not the only one who frequently makes this kind of mistake.
Code: Select all
[event]
name=prestart
[store_map_dimensions]
[/store_map_dimensions]
[store_locations]
x=$map_size.width
terrain=!,*^X*
include_borders=no
variable=east_border.locs
[/store_locations]
{FOREACH east_border.locs i}
[tunnel]
[filter]
[/filter]
[source]
x=$east_border.locs[$i].x
y=$east_border.locs[$i].y
[/source]
[target]
x=1
y=$east_border.locs[$i].y
[/target]
[/tunnel]
{NEXT i}
[/event]
east_border.locs[$i]
, and, since i
didn't even exist at that point, the tunnels just mysteriously didn't work (even though the path-finding algorithm still took an unusually long time).I tried using
$|east_border.locs[$|i].y
(syntax that works in nested events to prevent delayed_variable_substitution) but that didn't work, so I eventually had to wrap each [tunnel] in a new event like this:
Code: Select all
[event]
name=prestart
[store_map_dimensions]
[/store_map_dimensions]
[store_locations]
x=$map_size.width
terrain=!,*^X*
include_borders=no
variable=east_border.locs
[/store_locations]
{FOREACH east_border.locs i}
[event]
name=start
delayed_variable_substitution=no
[tunnel]
[filter]
[/filter]
[source]
x=$east_border.locs[$i].x
y=$east_border.locs[$i].y
[/source]
[target]
x=1
y=$east_border.locs[$i].y
[/target]
[/tunnel]
[/event]
{NEXT i}
[/event]
The last few months have been nothing but one big, painful reminder that TIMTLTW.
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
Re: [Engine] WML [tunnel] delayed_variable_substitution tag
I'm a bit surprised that that's how it works currently. Seems very unusual, and the fact that it's undocumented would suggest it might even be unintentional. Maybe someone who's more familiar with it will know more.
Re: [Engine] WML [tunnel] delayed_variable_substitution tag
Could one use this code for north-south as well?
Re: [Engine] WML [tunnel] delayed_variable_substitution tag
If you modified it a bit, sure. Though I should warn you that (at least on my slow computer) doing this slowed down the game very significantly: the ai took quite a while to move, and it even took a second or so for the game to show which hexes a unit could move to when I selected it.hvdvyve wrote:Could one use this code for north-south as well?
The last few months have been nothing but one big, painful reminder that TIMTLTW.
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
Re: [Engine] WML [tunnel] delayed_variable_substitution tag
Ok thx for the code and thx for the warning. If the slowing bothers me I'll take it out afterwards.Samonella wrote:If you modified it a bit, sure. Though I should warn you that (at least on my slow computer) doing this slowed down the game very significantly: the ai took quite a while to move, and it even took a second or so for the game to show which hexes a unit could move to when I selected it.hvdvyve wrote:Could one use this code for north-south as well?