switch not working
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.
switch not working
In updating a ai force move macro I came upon this problem.
What the macro is supposed to do is move a unit to a location by moving it by the amount that it usually moves by depending where the unit is.
The macro looks like this:
The macro that uses it looks like this (the important bit is right at the bottom):
It's put in to the scenario like this:
It use is explaned here.
What the macro is supposed to do is move a unit to a location by moving it by the amount that it usually moves by depending where the unit is.
The macro looks like this:
Code: Select all
#define J_MOVE_AI ID
[store_unit]
[filter]
id={ID}
[/filter]
variable=stored_ai
kill=no
[/store_unit]
[switch]
variable=stored_ai.y
[case]
value="8"
[move_unit]
id={ID}
to_x=2
to_y=16
[/move_unit]
[modify_unit]
[filter]
id={ID}
[/filter]
moves=0
[/modify_unit]
[/case]
[case]
value="7"
[move_unit]
id={ID}
to_x=2
to_y=15
[/move_unit]
[modify_unit]
[filter]
id={ID}
[/filter]
moves=0
[/modify_unit]
[/case]
[case]
value="6"
[move_unit]
id={ID}
to_x=2
to_y=14
[/move_unit]
[modify_unit]
[filter]
id={ID}
[/filter]
moves=0
[/modify_unit]
[/case]
[case]
value="5"
[move_unit]
id={ID}
to_x=2
to_y=13
[/move_unit]
[modify_unit]
[filter]
id={ID}
[/filter]
moves=0
[/modify_unit]
[/case]
[case]
value="4"
[move_unit]
id={ID}
to_x=2
to_y=12
[/move_unit]
[modify_unit]
[filter]
id={ID}
[/filter]
moves=0
[/modify_unit]
[/case]
[case]
value="3"
[move_unit]
id={ID}
to_x=2
to_y=16
[/move_unit]
[modify_unit]
[filter]
id={ID}
[/filter]
moves=0
[/modify_unit]
[/case]
[case]
value="2"
[move_unit]
id={ID}
to_x=2
to_y=16
[/move_unit]
[modify_unit]
[filter]
id={ID}
[/filter]
moves=0
[/modify_unit]
[/case]
[else]
[move_unit]
id={ID}
to_x=2
to_y=17
fire_event=yes
[/move_unit]
[modify_unit]
[filter]
id={ID}
[/filter]
moves=0
[/modify_unit]
[set_variable]
name=snapped
value=no
[/set_variable]
[/else]
[/switch]
[clear_variable]
name=stored_ai
[/clear_variable]
#enddef
Code: Select all
#define J_SNAPPING_EVENTS FIRST_ID SECOND_ID AI_TENT_X AI_TENT_Y
[event]
name=attacker hits
first_time_only=no
[filter]
id={FIRST_ID}
[/filter]
[filter_attack]
name=lance
[/filter_attack]
[set_variable]
name=lancea
rand="0..2"
[/set_variable]
[if]
[variable]
name=lancea
greater_than=0
[/variable]
[then]
[object]
silent=yes
[effect]
apply_to=remove_attacks
type=pierce
[/effect]
[/object]
[message]
id={FIRST_ID}
message=_"Aw, my lance has snapped."
[/message]
[store_unit] #to stop the unit attack
[filter]
id={FIRST_ID}
[/filter]
variable=stored_sir_a
kill=yes
[/store_unit]
[unstore_unit]
variable=stored_sir_a
[/unstore_unit]
[clear_variable]
name=stored_sir_a
[/clear_variable]
[fire_event]
name=lance_snapped
[/fire_event]
[/then]
[else]
[/else]
[/if]
[/event]
[event]
name=lance_snapped # a separate event is needed so that you only get the below
# message the first time so it doesn't get on your nerves
[message]
speaker=narrator
image=wesnoth-icon.png
message=_"To get another lance, you will have to go to your starting position"
[/message]
[/event]
[event]
name=attacker hits
first_time_only=no
[filter]
id={SECOND_ID}
[/filter]
[filter_attack]
name=lance
[/filter_attack]
[set_variable]
name=lanceb
rand="0..2"
[/set_variable]
[if]
[variable]
name=lanceb
greater_than=0
[/variable]
[then]
[object]
silent=yes
[effect]
apply_to=remove_attacks
type=pierce
[/effect]
[/object]
[message]
id={SECOND_ID}
message=_"Aw, my lance has snapped."
[/message]
[store_unit] #to stop the unit attack
[filter]
id={SECOND_ID}
[/filter]
variable=stored_sir_b
kill=yes
[/store_unit]
[unstore_unit]
variable=stored_sir_b
[/unstore_unit]
[clear_variable]
name=stored_sir_b
[/clear_variable]
[/then]
[/if]
[/event]
[event]
name=side 2 turn refresh
first_time_only=no
[filter_condition]
[variable]
name=snapped
boolean_equals=yes
[/variable]
[/filter_condition]
{J_MOVE_AI {SECOND_ID}}
[/event]
#enddef
Code: Select all
{J_SNAPPING_EVENTS Sir_Miles Sir_Hector 2 17}
Last edited by matsjoyce on September 16th, 2011, 3:26 pm, edited 1 time in total.
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: switch not working
You never explained your problem. "Doesn't work" is not enough. Describe what it's supposed to do, and what it actually does. However, the switch and cases are unnecessary, so you can do away with them, and maybe that will fix what's broken. You can do:...and just write the repeated section once, because that should work for all the cases (though I didn't test it to make sure).
Code: Select all
to_y="$($stored_ai.y+8)"
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: switch not working
What it's supposed to do is make an ai unit move normally to a destination it would not normally move to. If you want to see the map it's the jousting map in my add-on Jousting.
- beetlenaut
- Developer
- Posts: 2867
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: switch not working
...and I suppose we are to assume that it doesn't do anything at all?
I looked through it more carefully, and see a potential problem. The macro is called if the variable "snapped" is set to "yes", but the only place I can see where that can happen is in the macro, and only in the [else] block too. Either you didn't post all the code here, or the macro will never be called.
I looked through it more carefully, and see a potential problem. The macro is called if the variable "snapped" is set to "yes", but the only place I can see where that can happen is in the macro, and only in the [else] block too. Either you didn't post all the code here, or the macro will never be called.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: switch not working
If you're looking to assign units a destination and have them move naturally towards it, I had the similar problem and:
And that made it work.Bob_The_Mighty wrote:battlestar, you can assign unit.goto_x and unit.goto_y to each unit that is travelling.
LUA: Llama Under Apprenticeship
Hell faction: completed
Hell faction: completed
Re: switch not working
Thanks battlestar, I've got it working now.
Another question: I'm trying to make a terrain that heals like a village but gives defence like a normal flat tile.
Here's the code:And the _main.cfg section:And it dosen't seem to work. It appears in the editor but if I try to load the map this happens: Any ideas?
Another question: I'm trying to make a terrain that heals like a village but gives defence like a normal flat tile.
Here's the code:
Code: Select all
#textdomain wesnoth-j
[terrain_type]
symbol_image=grass/green
id=healing_grass
name= _ "Healing grass"
string=^Vmz
aliasof=Gg
heals=8
editor_group=J
[/terrain_type]
[terrain_graphics]
map="
, *
* , *
, 1
* , *
, *"
[tile]
pos=1
type=*^Vmz
set_flag="base"
[/tile]
[image]
name=grass/green1
base=90,146
[/image]
[/terrain_graphics]
#{OVERLAY *^Vmz grass/green1} this doesn't seem to make any difference
Code: Select all
#ifdef EDITOR
[binary_path]
path="data/add-ons/Jousting"
[/binary_path]
[editor_group]
id=J
name= _ "Jousting"
icon="group_custom"
[/editor_group]
{~add-ons/Jousting/utils/terrain/terrain.cfg}
#endif
-
- Posts: 252
- Joined: March 30th, 2011, 8:38 pm
- Location: The UK
Re: switch not working
I think (this is just a think) that If you put alias of (whatever the string of a flat is) and put the heals=yes tag in it would work.
(Please note I'm not great at this and the 'heals' tag might be something else look in the terrain definitions under villages you should be able to see.)
(Please note I'm not great at this and the 'heals' tag might be something else look in the terrain definitions under villages you should be able to see.)
- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: switch not working
With WML you can try [heal_unit] with [filter_location]'s terrain=
LUA: Llama Under Apprenticeship
Hell faction: completed
Hell faction: completed
- Alarantalara
- Art Contributor
- Posts: 789
- Joined: April 23rd, 2010, 8:17 pm
- Location: Canada
Re: switch not working
You need to include the terrain in the campaign as well. So copy the binary path (if not already present) and {~add-ons/Jousting/utils/terrain/terrain.cfg} into the part of your _main.cfg that lies within the #ifdef <CAMPAIGN_NAME>.
Edit: since I guess you may have based your entry off of my tutorial on such subjects, I've also edited in an additional note to make it clear that the terrain files must also be included like any other WML.
Edit: since I guess you may have based your entry off of my tutorial on such subjects, I've also edited in an additional note to make it clear that the terrain files must also be included like any other WML.
Re: switch not working
Thanks got it working
. Two other questions:

- When the ai moves of it, it heals 10 not 8.
- How could you stop the ai staying on it until it has full health?
- Alarantalara
- Art Contributor
- Posts: 789
- Joined: April 23rd, 2010, 8:17 pm
- Location: Canada
Re: switch not working
Assuming you're still using movement code much like the earlier code you have in this thread, it's because the AI didn't actually move there so it counts as resting.
You may be able to just set "resting" to no in the same way you set moves to 0 to solve the problem.
There are lots of ways to get the AI to move off of the healing area.
For instance:
Change the terrain so it's gone, removing the incentive to stay after enough healing. Replace it whenever your existing move to heal area code runs.
Write something using FormulaAI/LuaAI that completely controls the AI's actions (basically write rules of when to heal and when to attack - they could also replace your WML movement back fixing the first problem at the same time since the AI would be moving the unit)
Write more WML to move it off. (The AI should attack if its adjacent to the enemy even if it can't move)
Of these, the second offers the most power/control. You may find the other two easier to write, though.
You may be able to just set "resting" to no in the same way you set moves to 0 to solve the problem.
There are lots of ways to get the AI to move off of the healing area.
For instance:
Change the terrain so it's gone, removing the incentive to stay after enough healing. Replace it whenever your existing move to heal area code runs.
Write something using FormulaAI/LuaAI that completely controls the AI's actions (basically write rules of when to heal and when to attack - they could also replace your WML movement back fixing the first problem at the same time since the AI would be moving the unit)
Write more WML to move it off. (The AI should attack if its adjacent to the enemy even if it can't move)
Of these, the second offers the most power/control. You may find the other two easier to write, though.