Problem with the creation of an effect

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
jaeslin
Posts: 14
Joined: May 1st, 2020, 5:56 pm

Problem with the creation of an effect

Post by jaeslin »

Hi,
I was trying to make a "mark" effect where the marked unit stays marked for one turn and during that turn all damage made to that unit is doubled. I have a problem where the unit has the "mark" ability displayed but when it hits, nothing happens (no problem with my [dummy]). I think the problem lies in this code which is in a mark.cfg file that I call in the scenario with {~add-ons/campaign/utils/mark.cfg}.
Here it is :

Code: Select all

[event] 
    name=attacker hits
    first_time_only=no
    [filter_attack]
        special=mark
    [/filter_attack]
    [if]
        [variable]
        name=second_unit.marked
        equals=yes
        [/variable]
        [else]
            [set_variable]
                name=second_unit.variables.marked
                value=yes
            [/set_variable]
            [unstore_unit]
                variable=second_unit
                {COLOR_HARM}
                text= _ "marked"
            [/unstore_unit]
        [/else]
    [/if]
[/event]
[event] 
    name=defender hits
    first_time_only=no
    [filter_second_attack]
        special=mark
    [/filter_second_attack]
    [if]
        [variable]
        name=unit.marked
        equals=yes
        [/variable]
        [else]
            [set_variable]
                name=unit.variables.marked
                value=yes
            [/set_variable]
            [unstore_unit]
                variable=second_unit
                {COLOR_HARM}
                text= _ "marked"
            [/unstore_unit]
        [/else]
    [/if]
[/event]

[event] 
    name=attacker hits 
    first_time_only=no
    [harm_unit] 
        [filter_second] 
            [filter_wml]
                [variables]
                    marked="yes"
                [/variables]
            [/filter_wml]
        [/filter_second]
        amount=damage inflicted
        kill=yes
        fire_event=yes     
        animate=yes
    [/harm_unit]
[/event]
[event] 
    name=defender hits 
    first_time_only=no
    [harm_unit] 
        [filter] 
            [filter_wml]
                [variables]
                    marked="yes"
                [/variables]
            [/filter_wml]
        [/filter]
        amount=damage inflicted
        kill=yes
        fire_event=yes     
        animate=yes
    [/harm_unit]
[/event]
[event]
    name=turn end
    first_time_only=yes
    [set_variable]
        [filter_wml]
            [variables]
                marked="yes"
            [/variables]
        [/filter_wml]
        name=unit.variables.marked
        value=no
    [/set_variable]
[/event]
I don't understand where the error is in here...
Thanks very much for any answer !

User avatar
Ravana
Forum Moderator
Posts: 2442
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Problem with the creation of an effect

Post by Ravana »

[filter_wml] is not recognized in [set_variable], [harm_unit] without [filter] does not do anything. There are some such schema issues.

Then "amount=damage inflicted" is not number, "name=second_unit.marked" never exists.

User avatar
lhybrideur
Posts: 137
Joined: July 9th, 2019, 1:46 pm

Re: Problem with the creation of an effect

Post by lhybrideur »

And I think it should be

Code: Select all

name=turn end
first_time_only=no

jaeslin
Posts: 14
Joined: May 1st, 2020, 5:56 pm

Re: Problem with the creation of an effect

Post by jaeslin »

Thanks for your answers! I indeed had some glitches. I tinkered a bit with the code and now I am in a dead end... The unit is "marked" but damage isn't doubled. The unit stays marked the whole time. Those are the two main problems.
Here is the code ( the [print] are there to test the filters, which work) :

Code: Select all

[event] 
    name=attacker hits
    first_time_only=no
    [filter_attack]
        special=mark
    [/filter_attack]
    [if]
        [variable]
            name=second_unit.marked
            equals=yes
        [/variable]
        [else]
            [set_variable]
                name=second_unit.variables.marked
                value=yes
            [/set_variable]
            [unstore_unit]
                variable=second_unit
                {COLOR_HARM}
                text= _ "marked"
            [/unstore_unit]
        [/else]
    [/if]
[/event]
[event] 
    name=attack
    first_time_only=no
    [filter_second]
        [filter_wml]
            [variables]
                marked=yes
            [/variables]
        [/filter_wml] 
    [/filter_second]
    [print]
        text="ilsfdhklsfbld"
    [/print]
    [modify_unit] # this here doesn't work
        [filter]
            has_weapon=$weapon
        [/filter]
        [effect] 
            apply_to=attack
            name=$weapon.name
            increase_damage=100%
        [/effect]
    [/modify_unit]
[/event]
[event] 
    name=attack ends
    first_time_only=no
    [filter_second]
        [filter_wml]
            [variables]
                marked=yes
            [/variables]
        [/filter_wml] 
    [/filter_second]
    [print]
        text="ilsfdhklsfbld"
    [/print]
    [modify_unit] # this here doesn't work
        [filter]
            has_weapon=$weapon
        [/filter]
        [effect]
            apply_to=attack
            name=$weapon.name
            increase_damage=-50%
        [/effect]
    [/modify_unit]
[/event]
[event]
    name=turn
    first_time_only=no
    [foreach] # this here doesn't work
        array=unit
        [do]
            [set_variable]
                name=unit[i].variables.marked
                value=no
            [/set_variable]
        [/do]
    [/foreach]
[/event]
Thanks !

User avatar
Ravana
Forum Moderator
Posts: 2442
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Problem with the creation of an effect

Post by Ravana »

Not the real problem, but name=second_unit.marked should be name=second_unit.variables.marked

It would not be visible in damage calculations, but you could [harm_unit] the extra damage when attacker/defender hits. Say if it is important that damage calculation works correctly.

As far as I remember, event name=turn does not exist. But even then, after setting variable you need to unstore the unit. But array=unit is not defined either. So the process would work by store unit - change variable - unstore unit.

User avatar
lhybrideur
Posts: 137
Joined: July 9th, 2019, 1:46 pm

Re: Problem with the creation of an effect

Post by lhybrideur »

Yes the easiest way would probably be to have a harm_unit with amount=damage

I think the correct name is "turn refresh"

User avatar
beetlenaut
Developer
Posts: 2475
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Problem with the creation of an effect

Post by beetlenaut »

lhybrideur wrote:
May 12th, 2020, 1:39 pm
I think the correct name is "turn refresh"
Or maybe "turn end". It depends on how you want it to work. With turn end, you also get the side_number variable, which might be helpful.

It's hard to fully debug code you can't run, but I found two more problems besides the ones already mentioned:

In [modify_unit], "has_weapon" filters on the weapon's name, but you are referencing its container. (Actually though, has_weapon is deprecated, so you should use [has_attack] instead.)

In the [foreach] loop, using the index_var ("i") to access the array won't let you modify it. According to the wiki, you need to use this_item.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide

jaeslin
Posts: 14
Joined: May 1st, 2020, 5:56 pm

Re: Problem with the creation of an effect

Post by jaeslin »

Thanks to you all. A harm_unit would have been easier but the double damage would would have been done after the original attack, like a second stroke, which was not as pretty as a modify_unit. Thanks for your debugging, I indeed had problems with the foreach. The effect now works how I like it. I will continue testing it to see if anything goes wrong in special situations.
Here is the final code :

Code: Select all

[event] 
    name=attacker hits
    first_time_only=no
    [filter_attack]
        special=mark
    [/filter_attack]
    [if]
        [variable]
            name=second_unit.variables.marked
            equals=yes
        [/variable]
        [else]
            [set_variable]
                name=second_unit.variables.marked
                value=yes
            [/set_variable]
            [unstore_unit]
                variable=second_unit
                {COLOR_HARM}
                text= _ "marked"
            [/unstore_unit]
        [/else]
    [/if]
[/event]
[event] 
    name=attack
    first_time_only=no
    [filter_second]
        [filter_wml]
            [variables]
                marked=yes
            [/variables]
        [/filter_wml] 
    [/filter_second]
    [modify_unit]
        [filter]
            [has_attack]
                name=$weapon.name
            [/has_attack]
        [/filter]
        [effect]
            apply_to=attack
            name=$weapon.name
            increase_damage=100%
        [/effect]
    [/modify_unit]
[/event]
[event] 
    name=attack end
    first_time_only=no
    [filter_second]
        [filter_wml]
            [variables]
                marked=yes
            [/variables]
        [/filter_wml] 
    [/filter_second]
    [modify_unit]
        [filter]
            [has_attack]
                name=$weapon.name
            [/has_attack]
        [/filter]
        [effect]
            apply_to=attack
            name=$weapon.name
            increase_damage=-50%
        [/effect]
    [/modify_unit]
[/event]
[event]
    name=turn end
    first_time_only=no
    [store_unit]
        [filter]
            [filter_wml]
                [variables]
                    marked=yes
                [/variables]
            [/filter_wml] 
        [/filter]
        variable=marked_units
    [/store_unit]
    [foreach]
        array=marked_units
        [do]
            [set_variable]
                name=this_item.variables.marked
                value=no
            [/set_variable]
            [unstore_unit]
                variable=this_item
                {COLOR_HARM}
                text= _ "unmarked"
            [/unstore_unit]
        [/do]
    [/foreach]
    [clear_variable]
        name=marked_units
    [/clear_variable]
[/event]

Thanks for your answers !

Post Reply