Make message speaker $unit or $second_unit during attack

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
H-Hour
Posts: 222
Joined: April 14th, 2010, 12:27 pm

Make message speaker $unit or $second_unit during attack

Post by H-Hour »

I have an event that fires when one of a side's units is involved in an attack (either the attacker or the one attacked). I would like this unit to be the speaker of a [message].

I have tried assigning the unit to a variable and using that, but it doesn't seem to work.

Code: Select all

[event]
	name=attack
	[filter_condition]
		[variable]
			name=unit.side
			equals=4
		[/variable]
		[or]
			[variable]
				name=second_unit.side
				equals=4
			[/variable]
		[/or]
	[/filter_condition]
	[if]
		[variable]
			name=unit.side
			equals=4
		[/variable]
		[then]
			[set_variable]
				name=ayndun_unit
				equals=unit
			[/set_variable]
		[/then]
		[else]
			[set_variable]
				name=ayndun_unit
				equals=second_unit
			[/set_variable]
		[/else]
	[/if]
	[message]
		speaker=ayndun_unit
		message = _ "..."
	[/message]
	{CLEAR_VARIABLE ayndun_unit}
[/event]
Does anyone know how I can do this?
User avatar
Ravana
Forum Moderator
Posts: 2950
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Make message speaker $unit or $second_unit during attack

Post by Ravana »

Try equals=(second_)unit.id
H-Hour
Posts: 222
Joined: April 14th, 2010, 12:27 pm

Re: Make message speaker $unit or $second_unit during attack

Post by H-Hour »

Thanks Ravana! That was indeed part of the problem. I also realized I was using the wrong syntax. I needed to use "value" instead of "equals", and use $ to reference the variable. The final working code is:

Code: Select all

	[event]
		name=attack
		[filter_condition]
			[variable]
				name=unit.side
				equals=4
			[/variable]
			[or]
				[variable]
					name=second_unit.side
					equals=4
				[/variable]
			[/or]
		[/filter_condition]
		[if]
			[variable]
				name=unit.side
				equals=4
			[/variable]
			[then]
				[set_variable]
					name=ayndun_unit
					value=$unit.id
				[/set_variable]
			[/then]
			[else]
				[set_variable]
					name=ayndun_unit
					value=$second_unit.id
				[/set_variable]
			[/else]
		[/if]
		[message]
			speaker=$ayndun_unit
			message = _ "..."
		[/message]
		{CLEAR_VARIABLE ayndun_unit}
	[/event]
Post Reply