Yet another WML problem (with unit variables)

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
Noyga
Inactive Developer
Posts: 1790
Joined: September 26th, 2005, 5:56 pm
Location: France

Yet another WML problem (with unit variables)

Post by Noyga »

I tried to make some macros in order to make the cockactrices more playable in multiplayer.
When a cockactrice die, it would unstone all its victims.

I order to do this, i defined 3 units variables for each of those units :
- num_victims : the number of stoned victims from the unit
- victims_x[] and victims_y[] : the x,y position of the stoned victims

So i made 3 macros :
An macro to initialise the number of victims when the unit is recruited

Code: Select all

#define INIT_STONED_VICTIMS
[event]
	name=recruit
	first_time_only=no
	[filter]
		type=Cockatrice
	[/filter]
	[store_unit]
		[filter]
			x=$x1
			y=$y1
		[/filter]
		variable=init_unit
		kill=no
	[/store_unit]
	[set_variable]
		name=init_unit.variables.num_victims
		value=0
	[/set_variable]
	[unstore_unit]
		name=init_unit
	[/unstore_unit]
	[clear_variable]
		name=init_unit
	[/clear_variable]

[/event]
#enddef
Then a macro to record the victims when a unit is stoned :

Code: Select all

#define RECORD_STONED_VICTIMS
[event]
	name=stone
	first_time_only=no
	[store_unit]
		[filter]
			x=$x2
			y=$y2
		[/filter]
		variable=stoner_unit
		kill=no
	[/store_unit]
	[set_variable]
		name=stoner_unit.variables.victims_x[$stoner_unit.variables.num_victims]
		format=$x1
	[/set_variable]
	[set_variable]
		name=stoner_unit.variables.victims_y[$stoner_unit.variables.num_victims]
		format=$y1
	[/set_variable]
	[set_variable]
		name=stoner_unit.variables.num_victims
		add=1
	[/set_variable]
	#debug message
	[message]
		speaker=narrator
		message= "this $stoner_unit.description ($stoner_unit.x , $stoner_unit.y) has made $stoner_unit.variables.num_victims victims"
	[/message]
	[unstore_unit]
		name=stoner_unit
	[/unstore_unit]
	[clear_variable]
		name=stoner_unit
	[/clear_variable]
	
[/event]
#enddef
Then a macro to unstone all the victims when the cockactice is killed :

Code: Select all

#define FREE_STONED_VICTIMS
[event]
	name=die
	first_time_only=no
	[filter]
		type=Cockatrice
	[/filter]
	[store_unit]
		[filter]
			x=$x1
			y=$y1
		[/filter]
		variable=killed_unit
	[/store_unit]
	[while]
		[variable]
			name=killed_unit.variables.num_victims
			greater_than=0
		[/variable]
	[do]
		[set_variable]
			name=killed_unit.variables.num_victims
			add=-1
		[/set_variable]
		[unstone]
			[filter]
				x=$killed_unit.variables.victims_x[$killed_unit.variables.num_victims]
				y=$killed_unit.variables.victims_y[$killed_unit.variables.num_victims]
			[/filter]
		[/unstone]
	[/do]
	[/while]
	[unstore_unit]
		name=killed_unit
	[/unstore_unit]
	[clear_variable]
		name=killed_unit
	[/clear_variable]

[/event]
#enddef
In order to test it i just basically take a MP scenario like Charge or whatever, change the id, add the 3 macro code and just add this :

Code: Select all

{INIT_STONED_VICTIMS}
{RECORD_STONED_VICTIMS}
{FREE_STONED_VICTIMS}
Then i test it with an era where i can recruit Cockactrices (Superheroes Era)

The problem i have is that the unit don't seem to be set, in my record macro the number of victims showed by my debug message is always 1 :(
Does anybody see what is wrong ?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

I couldn't see anything wrong with the first two macros. I'll have a closer look after getting some sleep unless someone else comes up with a solution in the meanwhile.

Just in case you haven't done so, I've found it very useful in debugging WML to save the game after something didn't work when testing. Then I can just check the unit and variable parts of the savefile to see which variables aren't the way they should be, which units have their unit variables wrong, etc. It's not always convenient to have debug messages about everything everywhere.
scott
Posts: 5243
Joined: May 12th, 2004, 12:35 am
Location: San Pedro, CA

Post by scott »

You may need to run these through a format statement to express all of the dollar signs:

Code: Select all

        [filter] 
            x=$killed_unit.variables.victims_x[$killed_unit.variables.num_victims] 
            y=$killed_unit.variables.victims_y[$killed_unit.variables.num_victims] 
         [/filter] 
Just set up a dummy variable to hold the x and y. For ex.

Code: Select all

[set_variable]
name=x_loc
format=$killed_unit.variables.victims_x[$killed_unit.variables.num_victims] 
[/set_variable]
Then you use x=$x_loc in the [filter] tag.
Hope springs eternal.
Wesnoth acronym guide.
Post Reply