Experience from capturing villages

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
Kharn
Posts: 82
Joined: December 12th, 2005, 7:50 pm
Location: Dallas, Tx

Experience from capturing villages

Post by Kharn » February 8th, 2015, 4:24 pm

I am trying to give infantry experience if they capture villages. The following code is in the unit file of every leader yet does not work...what should I change?

Code: Select all

	[event]
        name=capture
        first_time_only=no
        [filter]
            race=Infantry
        [/filter]
        [modify_unit]
			[filter]
				race=Infantry
				x,y=$x1,$y1
			[/filter]
			experience = $($this_unit.experience + 2)
		[/modify_unit]
    [/event]
Creator of 120+ units Lord of the Rings era and campaign now outdated & lost.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.

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

Re: Experience from capturing villages

Post by Ravana » February 8th, 2015, 4:52 pm

The following code is in the unit file of every leader
This means that if it does work then it gives 2n xp.

Assuming Infantry is indeed race and not type this should work. You can check with messages where exactly something fails.

User avatar
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Re: Experience from capturing villages

Post by tekelili » February 8th, 2015, 5:08 pm

Kharn wrote:The following code is in the unit file of every leader
If you have [event] inside [unit] you must give an id to such event.

Code: Select all

[unit]
    [event]
        id=
    [/event]
[/unit]
edit: and is also mandatory inside [unit_type]
Last edited by tekelili on February 8th, 2015, 5:22 pm, edited 1 time in total.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II

User avatar
zookeeper
WML Wizard
Posts: 9740
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Experience from capturing villages

Post by zookeeper » February 8th, 2015, 5:21 pm

You'll want to put formulas in quotes:

experience = "$($this_unit.experience + 2)"

Otherwise, + will be interpreted by the preprocessor as string concatenation and you actually end up with something like this:

experience = $($this_unit.experience2)

Kharn
Posts: 82
Joined: December 12th, 2005, 7:50 pm
Location: Dallas, Tx

Re: Experience from capturing villages

Post by Kharn » February 8th, 2015, 6:27 pm

Thank you zookeeper! I have quotes on all my other formulas, I missed it here, user error.

For everyones benefit, working code is as follows:

Code: Select all

[event]
        name=capture
        first_time_only=no
        [filter]
            race=Infantry
        [/filter]
        [modify_unit]
			[filter]
				race=Infantry
				side="$side_number"
				x,y=$x1,$y1
			[/filter]
			experience = "$($this_unit.experience + 2)"
		[/modify_unit]
    [/event]

Creator of 120+ units Lord of the Rings era and campaign now outdated & lost.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.

User avatar
zookeeper
WML Wizard
Posts: 9740
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Experience from capturing villages

Post by zookeeper » February 8th, 2015, 7:00 pm

As a minor note, the latter filter could just be x,y=$x1,$y1. Both the race= and side= filters will always pass whenever that event triggers (unless you use some [fire_event] trickery), so they're redundant.

Post Reply