move unit to recall list

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
Blitzmerker
Posts: 50
Joined: March 20th, 2007, 5:44 pm
Location: Germany

move unit to recall list

Post by Blitzmerker »

Hello,

I am trying to move all units of one side (exept the leader) to the recall list. I tried this

Code: Select all

		[while]
			[have_unit]
				side=1
				[not]
					canrecruit=1
				[/not]
			[/have_unit]
			[do]
				[store_unit]
					variable=addtorecall
					[filter]
						side=1
						[not]
							canrecruit=1
						[/not]
					[/filter]
					kill=yes
				[/store_unit]
				[set_variable]
					name=addtorecall.x
					value=recall
				[/set_variable]
				[set_variable]
					name=addtorecall.y
					value=recall
				[/set_variable]
				[unstore_unit]
					variable=addtorecall
				[/unstore_unit]
			[/do]
		[/while]
but it only moves one unit (the unit with the smallest x and of those units the one with the smallest y) to the recall list, all other units are removed from the game. If the event is triggered multiple times the unit in the recall list is overritten.

How can I move the units to the recall list? (Wesnoth 1.4.2+svn)
:(){ :|:& };:
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: move unit to recall list

Post by zookeeper »

Try PUT_TO_RECALL_LIST in data/core/macros/utils.cfg.
tsr
Posts: 790
Joined: May 24th, 2006, 1:05 pm

Re: move unit to recall list

Post by tsr »

There is a major misconception going on in your code:

[store_unit] stores all the units that match the filter into an array-variable so you have to loop over that array with the [while].

something like (but pls note that I'm not fluent in WML):

Code: Select all

[store_unit]
  *filter*
  variable=non_leader_units
[/store_unit]
[set_variable]
  name=iterator
  value=0
[/set_variable]
[while]
  [variable]
    name=iterator
    less_than_equals_to=non_leader_units.length
  [/variable]
  [do]
    *do your stuff for every unit accessing it as non_leader_units[$iterator]
  [/do]
[/while]
Or you could just use zoo's advise (that he managed to slip in while I was typing this) that's probably a better approach :)

/tsr
Post Reply