Modifying traits on existing units [SOLVED]

The place to post your WML questions and answers.

Moderator: Forum Moderators

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
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Modifying traits on existing units [SOLVED]

Post by beetlenaut »

I can erase a unit's traits or add new ones by operating on unit.modifications.trait with [set_variables]. These new traits show up under the unit's picture like they should, and the inspector shows the unit having them under [modifications] like it should. But, these new traits are completely ignored! The unit works like it still has its original traits. Is this a bug? Shouldn't you be able to modify traits? (Version 1.9.1.)

Edit: My third post contains two solutions.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
silene
Posts: 1109
Joined: August 28th, 2004, 10:02 pm

Re: Modifying traits on existing units

Post by silene »

beetlenaut wrote:The unit works like it still has its original traits.
The engine has no way to know that the traits you manually added were not already there at the time the unit was stored (and hence not already taken into account). You have to manually apply the modifications with [set_variable] too.

Another possibility is to use the lua function wesnoth.add_modification or the [modify_unit] tag (which relies on the aforementioned function).
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Modifying traits on existing units

Post by beetlenaut »

Okay. Thanks. I think I can get away with [set_variable] this time. I'll learn lua eventually, but not today.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
boru
Posts: 788
Joined: November 19th, 2009, 11:02 pm

Re: Modifying traits on existing units [SOLVED]

Post by boru »

Zookeeper's post in this thread may be helpful.
“It is written in my life-blood, such as that is, thick or thin; and I can no other.” - J.R.R. Tolkien

My campaign: Swamplings - Four centuries before the founding of Wesnoth, the first wolf rider emerges from a tribe of lowly swamp goblins.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Modifying traits on existing units [SOLVED]

Post by Anonymissimus »

I promise to you that you are already using lots of lua even if you don't know about that beetlenaut. :P [modify_unit] is indeed your best option (1.9 only), e.g.:

Code: Select all

		[modify_unit]
			[filter]
				# SUF
			[/filter]
			[modifications]
				{TRAIT_HEALTHY}
			[/modifications]
		[/modify_unit]
That should replace the unit's first trait with the healthy trait.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Modifying traits on existing units [SOLVED]

Post by beetlenaut »

boru wrote:Zookeeper's post in this thread may be helpful.
That works! Wipe out the value you affected before unstoring the unit. (For example: clear max_hitpoints when you add resilient.)
Anonymissimus wrote:I promise to you that you are already using lots of lua even if you don't know about that beetlenaut. [modify_unit] is indeed your best option
If I don't have to do anything special to make it work, I'm just using WML. Is everything in the WLP automatically available in 1.9 then?
Anonymissimus wrote:That should replace the unit's first trait with the healthy trait.
Just like my method: in looks only. It is a lot shorter though.

I also figured out that you can TRANSFORM_UNIT (into the unit it already is, if you want), and the stats are adjusted properly. I was planning on transforming the unit anyway, so if I hadn't been testing each piece of the code separately, it would have just worked, and I never would have noticed a problem. :roll:
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
silene
Posts: 1109
Joined: August 28th, 2004, 10:02 pm

Re: Modifying traits on existing units [SOLVED]

Post by silene »

beetlenaut wrote:Is everything in the WLP automatically available in 1.9 then?
You are mistaken; the [modify_unit] tag doesn't have anything to do with WLP, it's a standard tag of the engine. Just because it is coded in Lua doesn't mean it isn't standard.

For instance, the following tags from the engine are written in Lua: [chat], [gold], [store_gold], [clear_variable], [store_unit_type_ids], [store_unit_type], [fire_event], [disallow_recruit], [set_recruit], [store_map_dimensions], [unit_worth], [wml_action], [lua], [music], [command], [if], [while], [switch], [scroll_to], [scroll_to_unit], [unit_overlay], [remove_unit_overlay], [store_turns], [store_unit], [sound], [store_locations], [hide_unit], [unhide_unit], [modify_unit], [move_unit], [objectives], [show_objectives], [item], [removeitem].
Post Reply