Storing unit role in a variable

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
alexanderthegre
Posts: 193
Joined: December 8th, 2011, 3:23 am
Location: nowhere

Storing unit role in a variable

Post by alexanderthegre »

I'm making an era (yeah, another one), and I've hit a brick wall: The units are liminal, and need to change from 'illuminates' to a self-explanatory custom 'darkens' depending on the time of day. The code I've got looks something like this:

Code: Select all

#define DO_MODIFY_ADD
[modify_unit]
	[filter]
		type=# Special unit type
	[/filter]
	[modifications]
		mode=add
#enddef

#define DO_MODIFY_REMOVE
[modify_unit]
	[filter]Changing abilities based off of ToD
		type=# Special unit type
	[/filter]
	[modifications]
		mode=remove
#enddef


[event]
	name=new_turn
	[store_time_of_day]
		variable=TOD
	[/store_time_of_day]
	[if]
# Day
		[variable]
			name=TOD.lawful_bonus
			equal_to=25
		[/variable]
		[then]
			{DO_MODIFY_ADD}
			[abilities]
				{ABILITY_DARKENS}
			[/abilities]
			[/modifications]
			[/modify_unit]
			{DO_MODIFY_REMOVE}
			[abilities]
				{ABILITY_ILLUMINATES}
			[/abilities]
			[/modifications]
			[/modify_unit]
		[/then]
	[/if]
	[if]
# Night
		[variable]
			name=TOD.lawful_bonus
			equal_to=-25
		[/variable]
		[then]
			{DO_MODIFY_REMOVE}
			[abilities]
				{ABILITY_DARKENS}
			[/abilities]
			[/modifications]
			[/modify_unit]
			{DO_MODIFY_ADD}
			[abilities]
				{ABILITY_ILLUMINATES}
			[/abilities]
			[/modifications]
			[/modify_unit]
		[/then]
	[/if]
	[if]
# Day
		[variable]
			name=TOD.lawful_bonus
			equal_to=0
		[/variable]
		[then]
			{DO_MODIFY_REMOVE}
			[abilities]
				{ABILITY_DARKENS}
			[/abilities]
			[/modifications]
			[/modify_unit]
			{DO_MODIFY_REMOVE}
			[abilities]
				{ABILITY_ILLUMINATES}
			[/abilities]
			[/modifications]
			[/modify_unit]
		[/then]
	[/if]
[/event]
It's not working. Anyone have any ideas?
Last edited by alexanderthegre on March 16th, 2012, 1:51 am, edited 1 time in total.
Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: Changing abilities based off of ToD

Post by Ceres »

equal_to is not a valid relational key in WML. numerical_equals is the way to go here.
User avatar
alexanderthegre
Posts: 193
Joined: December 8th, 2011, 3:23 am
Location: nowhere

Re: Storing unit role in a variable

Post by alexanderthegre »

I don't want to clog up the WML workshop forum with my questions, so I'm posting this one here:

I'm trying to write code that switches a unit's side for 1 turn.
I've got the switching down, and have stored the unit's side number in a role.
Is there any way that I can assign the unit's side to equal its role?
User avatar
The_Other
Posts: 189
Joined: February 3rd, 2012, 10:05 pm
Location: UK

Re: Storing unit role in a variable

Post by The_Other »

This is based on something I made, I haven't tested this variation of it though.
Also, my WML isn't too great, so there may be some good reason why this won't work...

{MODIFY_UNIT x,y=$x1,$y1 side $units_role}
Nothing is true; everything is permissible.
User avatar
alexanderthegre
Posts: 193
Joined: December 8th, 2011, 3:23 am
Location: nowhere

Re: Storing unit role in a variable

Post by alexanderthegre »

No, that didn't appear to do it. :(

Here's my current code:

Code: Select all



#define ABILITY_CHARMED
[dummy]
	id=charmed
	name="charmed"
	female_name= _ "female^charmed"
	description="Charmed:
This unit is momentarily taken over by the Demons. It will return to its origional side at the end of turn."
[/dummy]
#enddef

[event]
	name=attacker hits
        first_time_only=no
	[filter]
		type=# Unit type
	[/filter]

	{STORE_UNIT_VAR x,y=$x1,$y1 side charmer_side}
	{STORE_UNIT_VAR x,y=$x2,$y2 side charmed_side}

	{MODIFY_UNIT x,y=$x2,$y2 variables.real_side $charmed_side}
	{MODIFY_UNIT x,y=$x2,$y2 side $charmer_side}
	{MODIFY_UNIT x,y=$x2,$y2 moves 4}
	{MODIFY_UNIT x,y=$x2,$y2 attacks_left 1}

	[role]
		[filter]
			x,y=$x2,$y2
		[/filter]
		role=$charmed_side
	[/role]		

	[object]
		silent=yes
		duration=forever
		[filter]
			x,y=$x2,$y2
		[/filter]
		[effect]
			apply_to=new_ability
			[abilities]
				{ABILITY_CHARMED}
			[/abilities]
		[/effect]
	[/object]

[/event]

[event]
	name=turn end
	first_time_only=no
	[role]
		[filter]
			ability=charmed
		[/filter]
		role=null
	[/role]
	{MODIFY_UNIT (ability=charmed) side $units_role}
	[object]
		silent=yes
		duration=forever
		[filter]
			ability=charmed
		[/filter]
		[effect]
			apply_to=remove_ability
			[abilities]
				{ABILITY_CHARMED}
			[/abilities]
		[/effect]
	[/object]
[/event]
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: Storing unit role in a variable

Post by battlestar »

What does it do right now?
LUA: Llama Under Apprenticeship
Hell faction: completed
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Storing unit role in a variable

Post by Anonymissimus »

[role][filter]:
"This tag uses a StandardUnitFilter (without [filter])..."
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
alexanderthegre
Posts: 193
Joined: December 8th, 2011, 3:23 am
Location: nowhere

Re: Storing unit role in a variable

Post by alexanderthegre »

I removed the [filter] from the role tag, and it still doesn't appear to be working. :?
Currently it will remove the ability, and that's it.

Is using roles the best way to acomplish this, or is there some other way?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Storing unit role in a variable

Post by zookeeper »

No, roles make no sense whatsoever in this case.
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: Storing unit role in a variable

Post by battlestar »

Looks like you're trying to store the original side in the units_role, and that variable will be under the specific unit, not as a stand-alone variable. You probably need to store the unit into a variable like "temp_unit_var", then use $temp_unit_var.units_role instead of $units_role
LUA: Llama Under Apprenticeship
Hell faction: completed
User avatar
alexanderthegre
Posts: 193
Joined: December 8th, 2011, 3:23 am
Location: nowhere

Re: Storing unit role in a variable

Post by alexanderthegre »

battlestar wrote:Looks like you're trying to store the original side in the units_role, and that variable will be under the specific unit, not as a stand-alone variable. You probably need to store the unit into a variable like "temp_unit_var", then use $temp_unit_var.units_role instead of $units_role
How would I do that? (I'm sorry if it's really obvious, I did some searching on the wiki and found nothing)
User avatar
battlestar
Posts: 690
Joined: January 1st, 2007, 7:12 am

Re: Storing unit role in a variable

Post by battlestar »

untested:

Code: Select all

[store_unit]
	[filter]
		ability=charmed
	[/filter]
	variable=charmed_units_store
[/store_unit]
{FOREACH i charmed_units_store}
	   {MODIFY_UNIT (id=$charmed_units_store[$i].id) side $charmed_units_store[$i].units_role} 
	   # etc etc
{NEXT i}
give it a try
LUA: Llama Under Apprenticeship
Hell faction: completed
Post Reply