Variable substitution broken usin [unit] to_variable=

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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.
Post Reply
User avatar
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Variable substitution broken usin [unit] to_variable=

Post by tekelili » November 5th, 2017, 3:26 pm

I have different result using 2 similar codes that I expected work equal.

Code: Select all

[unit]
    [insert_tag]
        name=event
        variable=my_event_variable
    [/insert_tag]
[/unit]

Code: Select all

[unit]
    to_variable=my_unit_variable
    [insert_tag]
        name=event
        variable=my_event_variable
    [/insert_tag]
[/unit]
[unstore_unit]
    variable=my_unit_variable
[/unstore_unit]
I have use :debug and detected that in second case, the [filter] inside my [event] (with $x1 $y1 stuff) is not working with delayed substitution and takes unit values when unstored, making my event not work. ¿Is expected this behavior of to_variable= or is a bug?

I have used BfW 1.12.5
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II

User avatar
The_Gnat
Posts: 1537
Joined: October 10th, 2016, 3:06 am
Contact:

Re: Variable substitution broken usin [unit] to_variable=

Post by The_Gnat » November 17th, 2017, 8:04 am

I do not know very much but perhaps, maybe, it could be that it converts the unit to a variable and then modifies the unit thereby not modifying the variable...

Do you get the same error if you rearrange the order of the code:

Code: Select all

[unit]
    [insert_tag]
        name=event
        variable=my_event_variable
    [/insert_tag]
    # .... at the end
    to_variable=my_unit_variable
[/unit]
[unstore_unit]
    variable=my_unit_variable
[/unstore_unit]
(i rarely use the insert_tag so this may not be the problem)
Last edited by The_Gnat on November 17th, 2017, 8:46 am, edited 1 time in total.

User avatar
Pentarctagon
Forum Administrator
Posts: 3517
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Variable substitution broken usin [unit] to_variable=

Post by Pentarctagon » November 17th, 2017, 8:38 am

Posting all code related to this would be more helpful as well. So, what populates my_event_variable and my_unit_variable?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

User avatar
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Re: Variable substitution broken usin [unit] to_variable=

Post by tekelili » November 17th, 2017, 9:45 pm

This is extra stuff wich I considered less relevant, it is a copy paste from my addon and uses less generic names for variables and event

Code: Select all

[event]
    id=wct_epic_AMLA_XP
    name=post advance
    first_time_only=no
    [filter]
        [filter_wml]
            advances_to=$null
            [modifications]
                [trait]
                    id=epic
                [/trait]
            [/modifications]
        [/filter_wml]
    [/filter]
    [modify_unit]
        [filter]
            x,y=$x1,$y1 ##here is where variable substitution changes using to_variable
        [/filter]
        max_experience=60
    [/modify_unit]
[/event]

Code: Select all

    [unit]
        side=$unit.side
        type=$wct.hero.type
        x,y=$unit.x,$unit.y
        generate_name=yes
        random_gender=yes
        overlays="misc/hero-icon.png"
        role=just_created
        [modifications]
            [insert_tag]
                name=trait
                variable=wct.trait.heroic.trait
            [/insert_tag]
            [insert_tag]
                name=trait
                variable=wct.trait.$wct.hero.extra_trait|.trait
            [/insert_tag]
            [object]
                {WCT_RECRUIT_EXPERIENCE_PENALTY}
            [/object]
        [/modifications]
        [insert_tag]
            name=event
            variable=wct.trait.$wct.hero.extra_trait|.event ##here is where event is introduced and works fine not using to_variable
        [/insert_tag]
    [/unit]
Last edited by tekelili on November 17th, 2017, 9:56 pm, edited 2 times in total.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II

User avatar
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Re: Variable substitution broken usin [unit] to_variable=

Post by tekelili » November 17th, 2017, 9:54 pm

I am setting variable value as literal, just in case could be relevant

Code: Select all

[set_variables]
    name=wct
    mode=merge
    [literal]
        [trait]
            {WORLD_CONQUEST_II_ERA_TRAITS} ##here comes variable used in previous post
        [/trait]
        [heroes]
            {WORLD_CONQUEST_II_ERA_HEROES_TYPES}
        [/heroes]
    [/literal]
[/set_variables]
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II

gfgtdf
Developer
Posts: 1067
Joined: February 10th, 2013, 2:25 pm

Re: Variable substitution broken usin [unit] to_variable=

Post by gfgtdf » November 18th, 2017, 1:06 pm

looking at the code it seems like the 1.12 implementation of to_variable https://github.com/wesnoth/wesnoth/blob ... .cpp#L2432 just pasrses the whole wml content and operates on that. The good news is that that this was fixed in 1.13 long time ago. For 1.12, the only way to fix it it probably not to use to_variable, and just put a [store_unit] directly after that [unit]
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.

User avatar
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Re: Variable substitution broken usin [unit] to_variable=

Post by tekelili » November 18th, 2017, 3:06 pm

Ty gfgtdf, now I know exactly what is going on :D
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II

Post Reply