remove a trait to WML

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
Ruvaak
Posts: 37
Joined: February 3rd, 2019, 2:53 pm

remove a trait to WML

Post by Ruvaak » April 12th, 2019, 4:59 pm

Hello,


From my understanding, [traits] and [object] works in similar ways, stored in [modifications] tags of unit.

There is a [remove_object] (which sometimes creates bugs, like resetting completely or partially unit/attack default values, for a reason I still didn't understood), but apparently not a [remove_trait] (can be a feature suggestion, BTW).

Is there a simple reason, without having to loop all traits to find the one having a good idea ?
Loops in WML on units properties can be very slow.

Thanks !
Last edited by Ruvaak on April 12th, 2019, 11:59 pm, edited 1 time in total.
Creator of Advanced Wesnoth Wars mod

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

Re: remove a trait to WML

Post by Ravana » April 12th, 2019, 5:53 pm

Both traits and objects are designed to be permanent (which is why removing them can have side effects). It was only after people had indeed removed objects manually that it was accepted to add such tag to core.

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

Re: remove a trait to WML

Post by gfgtdf » April 12th, 2019, 7:52 pm

The underlying Lua function also works with traits iirc.
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
Ruvaak
Posts: 37
Joined: February 3rd, 2019, 2:53 pm

Re: remove a trait to WML

Post by Ruvaak » April 13th, 2019, 12:09 am

Hi both,

@ravana. I see. The thing is, I'm working on option to disable/enable certains mods options ingame, so removing abilities/objects/traits than was created on units. But if the core code was not designated that way, i can understand the problem.


@gfgtdf, I didn't understood. There is a LUA function doing that ?

Meanwhile, I guess having a [remove_trait] can be useful for mods. I could use the effects in an object, but the stats changes will not be displayed for the user. I guess it's the exact same mechanics than for objects. I will do it anyway, in wml or lua.
Creator of Advanced Wesnoth Wars mod

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

Re: remove a trait to WML

Post by gfgtdf » April 13th, 2019, 10:01 am

> There is a LUA function doing that ?

Yes but actually [remove_object] might also be able to remove traits, did you try it? like for example [remove_object] object_id="loyal" to remove the loyal trait. Otherwise you can always use the wesnoth.remove_modification lua function.


> like resetting completely or partially unit/attack default values, for a reason I still didn't understood

I tries to update the wiki page:

https://wiki.wesnoth.org/DirectActionsW ... _object.5D
https://wiki.wesnoth.org/DirectActionsW ... fy_unit.5D
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
Ruvaak
Posts: 37
Joined: February 3rd, 2019, 2:53 pm

Re: remove a trait to WML

Post by Ruvaak » April 13th, 2019, 12:32 pm

gfgtdf wrote:
April 13th, 2019, 10:01 am

Yes but actually [remove_object] might also be able to remove traits, did you try it? like for example [remove_object] object_id="loyal" to remove the loyal trait.

Yes, I tried, didn't worked. (v1.14.7)

When I defined the trait, I didn't put in using [modifications] (because I noticed sometimes this would just *replace* an existing trait instead of adding it, and because I saw in unit profile that the traits/object was created in the good part, using modify_unit).


Can be the reason ? I will try later with "standards" traits.

Code: Select all

    [modify_unit]
        [filter]
           ...
       [/filter]
       
       [trait]
         id=aww_trait_gifted
         male_name= _"epic"
         female_name= _"female^epic"
        
          [effect]
              apply_to=movement
              increase=20%
          [/effect]
          [effect]
            apply_to=attack
            increase_attacks=20%
            increase_damage=20%
          [/effect]
      [/trait]
  [/modify_unit]
    
    
    
     [remove_object]
        [filter]
            ...
        [/filter]
        object_id=aww_trait_gifted
    [/remove_object]
    

I saw your text in the wiki, it's a good start, thank you !
Creator of Advanced Wesnoth Wars mod

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

Re: remove a trait to WML

Post by gfgtdf » April 13th, 2019, 5:36 pm

When you use [trait] in [modify_unit] you should not write [modifications], your code is correct exedct that [remove_object] does not seem to work with traits, you have to use the lua wesnoth.remove_modification, alterntiveley you can define your own wml tag that removes traits.
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
Celtic_Minstrel
Developer
Posts: 1488
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: remove a trait to WML

Post by Celtic_Minstrel » April 13th, 2019, 10:37 pm

As gfgtdf says, you can't do it in WML, you need to use Lua.

Instead of the [remove_object] tag, you can use something like the following code (untested, might have syntax errors):

Code: Select all

[lua]
	code=<<wesnoth.remove_modifications(wesnoth.get_units(wml.get_child(..., "filter"))[1], {id = "aww_trait_gifted"}, "trait")>>
	[args]
		[filter]
			...
		[/filter]
	[/args]
[/lua]
If you need to do it in many places, you could also define a custom WML tag instead of copy-pasting the [lua] tag everywhere.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

User avatar
Ruvaak
Posts: 37
Joined: February 3rd, 2019, 2:53 pm

Re: remove a trait to WML

Post by Ruvaak » April 14th, 2019, 3:35 pm

Thanks all,

I did a lua function similar to similar object, with the 3rd parameter Celtic_Minstrel show me, and it works :

Code: Select all

function wesnoth.wml_actions.aww_remove_trait(cfg)
	local trait_id = cfg.trait_id
	for _,unit in ipairs(wesnoth.get_units(cfg)) do
		wesnoth.remove_modifications(unit, {id = trait_id}, "trait")
	end
end

in my event :

Code: Select all

    [aww_remove_trait]
        [filter]
            ...
        [/filter]
        trait_id=aww_trait_gifted
    [/aww_remove_trait]


Post Reply