Modifying traits on existing units [SOLVED]
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.
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Modifying traits on existing units [SOLVED]
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.
Edit: My third post contains two solutions.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: Modifying traits on existing units
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.beetlenaut wrote:The unit works like it still has its original traits.
Another possibility is to use the lua function wesnoth.add_modification or the [modify_unit] tag (which relies on the aforementioned function).
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Modifying traits on existing units
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
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: Modifying traits on existing units [SOLVED]
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.
My campaign: Swamplings - Four centuries before the founding of Wesnoth, the first wolf rider emerges from a tribe of lowly swamp goblins.
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Modifying traits on existing units [SOLVED]
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 (1.9 only), e.g.:
That should replace the unit's first trait with the healthy trait.
Code: Select all
[modify_unit]
[filter]
# SUF
[/filter]
[modifications]
{TRAIT_HEALTHY}
[/modifications]
[/modify_unit]
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Modifying traits on existing units [SOLVED]
That works! Wipe out the value you affected before unstoring the unit. (For example: clear max_hitpoints when you add resilient.)boru wrote:Zookeeper's post in this thread may be helpful.
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: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
Just like my method: in looks only. It is a lot shorter though.Anonymissimus wrote:That should replace the unit's first trait with the healthy trait.
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.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: Modifying traits on existing units [SOLVED]
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.beetlenaut wrote:Is everything in the WLP automatically available in 1.9 then?
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].