Giving xp to leader for every killed unit

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
Anagkai
Posts: 58
Joined: February 12th, 2012, 10:05 am

Giving xp to leader for every killed unit

Post by Anagkai »

The following code should give xp to my leader, whenever I kill a unit, that is with any of my units. It doesn't work though, there's probably a problem with the variables or the filters.

Code: Select all

	[event]
		name=die
		[filter]
			level=2,3
		[/filter]
		[filter_second]
			side=1
		[/filter_second]
		[modify_unit]
			[filter]
				id=Henry
			[/filter]
			{VARIABLE_OP ($this_unit.experience) add ($unit.level)}
		[/modify_unit]
	[/event]
Any tips are appreciated.
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)
Shiki
Developer
Posts: 348
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: Giving xp to leader for every killed unit

Post by Shiki »

You change at the end a variable, but… that variable is never going to have any effect, and also only exists inside the modify_unit tag, and will be cleared afterwards.
You could add a line like experience=$this_unit.experience afterwards to use it.

You can also use the Wesnoth Formula Language: experience=$($this_unit.experience+$unit.level)

In other places where one manipulates unit variables (e.g. $unit), one could use [unstore_unit] to change the actual unit afterwards.
Try out the dark board theme.
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Giving xp to leader for every killed unit

Post by Ravana »

I doubt you can actually use actionWML inside modify_unit, which means VARIABLE_OP does nothing.
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Giving xp to leader for every killed unit

Post by beetlenaut »

You can use Wesnoth Formula Language, but I recommend doing it this way: store Henry, do the variable operation on stored_Henry.experience, then unstore Henry. It's very powerful technique that you should know. (Actually, this is exactly what [modify_unit] does, but that tag only handles simple cases.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Post Reply