[heal_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
User avatar
meowreka
Posts: 82
Joined: September 19th, 2009, 12:21 am

[heal_unit]

Post by meowreka »

code:
I have no idea how to use [heal_unit]. It doesn't work for me.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: [heal_unit]

Post by zookeeper »

No, you're just making the same mistake I pointed out in the previous thread.
User avatar
meowreka
Posts: 82
Joined: September 19th, 2009, 12:21 am

Re: [heal_unit]

Post by meowreka »

all of the code works, sans for this:

[heal_unit]
[filter]
variable=survivor
[/filter]
amount=2
[/heal_unit]

I removed the [filter] tags once and it still did nothing.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: [heal_unit]

Post by Anonymissimus »

[if][filter] and [filter]variable= don't work

should work about this way (untested)

Code: Select all

#define ABILITY_SURVIVOR
	# Canned definition of the survivor ability to be included in a
	# [specials] clause.


	# dummy weapon special used to describe the effect to the user
	# and filter on special's id
	[dummy]
		id=unit_survivor
		name= _ "survivor"
		name_inactive= _ "survivor"
		description= _ "survivor :
If this unit successfully survives an attack, they gain 2 HP."
		description_inactive= _ "survivor :
If this unit successfully survives an attack, they gain 2 HP."

	[/dummy]

[/abilities]

[event]
	name=attack_end
	first_time_only=no
	[filter_second]
		ability=unit_survivor
	[/filter_second]
	[if]
		[variable]
			name=second_unit.hitpoints
			greater_than=0
		[/variable]
		[then]
			[set_variable]
				name=second_unit.hitpoints
				add=2
			[/set_variable]
			[unstore_unit]
				variable=second_unit
				text="2"
				{COLOR_HEAL}
			[/unstore_unit]
		[/then]
	[/if]
[/event]
[+abilities]
#enddef

Last edited by Anonymissimus on October 8th, 2009, 8:40 pm, edited 1 time in total.
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
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: [heal_unit]

Post by zookeeper »

Your [then] is either always or never entered, because you haven't specified any valid condition in your [if].

Nevertheless, any healing your [heal_unit] does to the unit is probably negated by the fact that you immediately overwrite the unit by replacing the now healed unit with the one you stored before it got healed.

And in standard unit filters there's no such key as a variable=. If you want to filter for the unit at $x1,$y1 then use x,y=$x1,$y1 as the filter.
User avatar
meowreka
Posts: 82
Joined: September 19th, 2009, 12:21 am

Re: [heal_unit]

Post by meowreka »

I looked over the code I posted in my first post. It WAS wrong, but when I "fixed" it, it still doesn't function as I would like it to.

Code: Select all

#define ABILITY_SURVIVOR
# Canned definition of the survivor ability to be included in a
# [specials] clause.


# dummy weapon special used to describe the effect to the user
# and filter on special's id
[dummy]
   id=unit_survivor
   name= _ "survivor"
   name_inactive= _ "survivor"
   description= _ "survivor :
If this unit successfully survives an attack, they gain 2 HP."
   description_inactive= _ "survivor :
If this unit successfully survives an attack, they gain 2 HP."
   
[/dummy]

[/abilities]

[event]
   name=attack_end
   first_time_only=no
   [filter]
         ability=unit_survivor
	[/filter]
		[filter_wml]
               not_living=no
		[/filter_wml]

   [heal_unit]
   amount=2
   [/heal_unit]
         [unstore_unit]
            variable=unit
            text="2"
            {COLOR_HEAL}
         [/unstore_unit]
   
   {CLEAR_VARIABLE survivor}
[/event]

[+abilities]

#enddef
It doesn't seem to work when the unit is defending.. only when they are attacking.

I'm still learning this stuff, and the wiki is awful vague on a LOT of these things.
silene
Posts: 1109
Joined: August 28th, 2004, 10:02 pm

Re: [heal_unit]

Post by silene »

meowreka wrote:It doesn't seem to work when the unit is defending.. only when they are attacking.
You didn't tell the engine which unit to heal, so it decided to heal the attacker.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: [heal_unit]

Post by zookeeper »

meowreka wrote:I'm still learning this stuff, and the wiki is awful vague on a LOT of these things.
Not really, you just have to learn to not guess.

For example, what does the wiki say you can put in an [event]? It sure doesn't say anything about a [filter_wml]: instead, it says you can put in a [filter] with a standard unit filter inside it to make the event only trigger when a unit matching that filter is associated with an event of that type.

So if you want something to happen when an attack ends, and only if the attacker matches some criteria, then you make an attack_end event and put in a [filter] which contains a standard unit filter describing your criteria. Then you just go look what can go in a standard unit filter and figure out how to write a standard unit filter which describes the criteria you want. If you start to guess whether you can put this tag or that tag somewhere, it most likely won't work.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: [heal_unit]

Post by Anonymissimus »

not_living is a key describing the form of the unit, not its status (whether it is an undead unit i think)
to check whether the unit has survived you need to look after its hitpoints
(my above code is only for defense btw, but the other version is anlogous)

@zookeeper
It is really kind of you how you teach everyone, ever and ever, that wml stuff! :)
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
meowreka
Posts: 82
Joined: September 19th, 2009, 12:21 am

Re: [heal_unit]

Post by meowreka »

zookeeper wrote:
meowreka wrote:I'm still learning this stuff, and the wiki is awful vague on a LOT of these things.
Not really, you just have to learn to not guess.

For example, what does the wiki say you can put in an [event]? It sure doesn't say anything about a [filter_wml]: instead, it says you can put in a [filter] with a standard unit filter inside it to make the event only trigger when a unit matching that filter is associated with an event of that type.

So if you want something to happen when an attack ends, and only if the attacker matches some criteria, then you make an attack_end event and put in a [filter] which contains a standard unit filter describing your criteria. Then you just go look what can go in a standard unit filter and figure out how to write a standard unit filter which describes the criteria you want. If you start to guess whether you can put this tag or that tag somewhere, it most likely won't work.
Well I've learned a lot more now thanks to this than anything I've read on the wiki. It doesn't explicitly state anything like this on any of the pages I read.
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: [heal_unit]

Post by A Guy »

You put [filter_wml] inside the [filter] tag.
I'm just... a guy...
I'm back for now, I might get started on some work again.
User avatar
solsword
Code Contributor
Posts: 291
Joined: January 12th, 2009, 10:21 pm
Location: Santa Cruz, CA
Contact:

Re: [heal_unit]

Post by solsword »

Well, it does say on the wiki that [filter] inside an [event] applies to the first unit. In this case, the attacker. So your event only fires if the attacker has the ability. You need a separate event with a [filter_second] tag that heals the defender (as pointed out, just saying heal_unit without a filter isn't a good idea). Frankly, I'm surprised that it didn't heal every unit on the map. Use id=$unit.id to filter for the primary unit in an event.
The Knights of the Silver Spire campaign.

http://www.cs.hmc.edu/~pmawhorter - my website.

Teamcolors for everyone! PM me for a teamcolored version of your sprite, or you can do it yourself. If you just happen to like magenta, no hard feelings?
Post Reply