Storing unit role in a variable
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.
- alexanderthegre
- Posts: 193
- Joined: December 8th, 2011, 3:23 am
- Location: nowhere
Storing unit role in a variable
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:
It's not working. Anyone have any ideas?
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]
Last edited by alexanderthegre on March 16th, 2012, 1:51 am, edited 1 time in total.
Re: Changing abilities based off of ToD
equal_to
is not a valid relational key in WML. numerical_equals
is the way to go here.Co-Creator of The Fellowship of the Clay (BfW 1.10) ~~ Maintainer of the German Code of Conduct
How to isolate problematic WML code ~~ WML error messages and their reasons
How to isolate problematic WML code ~~ WML error messages and their reasons
- alexanderthegre
- Posts: 193
- Joined: December 8th, 2011, 3:23 am
- Location: nowhere
Re: Storing unit role in a variable
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?
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?
Re: Storing unit role in a variable
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}
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.
- alexanderthegre
- Posts: 193
- Joined: December 8th, 2011, 3:23 am
- Location: nowhere
Re: Storing unit role in a variable
No, that didn't appear to do it.
Here's my current code:
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]
- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: Storing unit role in a variable
What does it do right now?
LUA: Llama Under Apprenticeship
Hell faction: completed
Hell faction: completed
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Storing unit role in a variable
[role][filter]:
"This tag uses a StandardUnitFilter (without [filter])..."
"This tag uses a StandardUnitFilter (without [filter])..."
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
- alexanderthegre
- Posts: 193
- Joined: December 8th, 2011, 3:23 am
- Location: nowhere
Re: Storing unit role in a variable
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?
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?
Re: Storing unit role in a variable
No, roles make no sense whatsoever in this case.
- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: Storing unit role in a variable
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
Hell faction: completed
- alexanderthegre
- Posts: 193
- Joined: December 8th, 2011, 3:23 am
- Location: nowhere
Re: Storing unit role in a variable
How would I do that? (I'm sorry if it's really obvious, I did some searching on the wiki and found nothing)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
- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: Storing unit role in a variable
untested:
give it a try
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}
LUA: Llama Under Apprenticeship
Hell faction: completed
Hell faction: completed