[Engine] WML [tunnel] delayed_variable_substitution tag

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderators: Forum Moderators, Developers

Forum rules
Before posting a new idea, you must read the following:

[Engine] WML [tunnel] delayed_variable_substitution tag

Postby Samonella » February 25th, 2017, 7:50 pm

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:
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]


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 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]

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.
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Vengeance of a Drake: an RPG
Samonella
 
Posts: 283
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: [Engine] WML [tunnel] delayed_variable_substitution tag

Postby zookeeper » February 25th, 2017, 9:54 pm

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.
User avatar
zookeeper
WML Wizard
 
Posts: 9610
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: [Engine] WML [tunnel] delayed_variable_substitution tag

Postby hvdvyve » August 12th, 2017, 8:59 pm

Could one use this code for north-south as well?
hvdvyve
 
Posts: 2
Joined: August 12th, 2017, 8:43 pm

Re: [Engine] WML [tunnel] delayed_variable_substitution tag

Postby Samonella » August 12th, 2017, 9:07 pm

hvdvyve wrote:Could one use this code for north-south as well?
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.
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Vengeance of a Drake: an RPG
Samonella
 
Posts: 283
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: [Engine] WML [tunnel] delayed_variable_substitution tag

Postby hvdvyve » August 12th, 2017, 9:36 pm

Samonella wrote:
hvdvyve wrote:Could one use this code for north-south as well?
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.


Ok thx for the code and thx for the warning. If the slowing bothers me I'll take it out afterwards. ^_^
hvdvyve
 
Posts: 2
Joined: August 12th, 2017, 8:43 pm


Return to Ideas

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests