Problem with adding variables into units and filtering them
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.
-
- Posts: 25
- Joined: February 29th, 2012, 2:04 pm
- Location: Taiwan
Problem with adding variables into units and filtering them
Hi all,
It's me again, I really find myself with poor WML skill and out of talent...
Anyway, I try to create some object to every unit who "equip" it, and I also want to add a variable on these unit for record so that I can add a filter to prevent them equip twice. This time my question is, I've tried [store_unit], [set_variable] to put a variable into these specific units, but when I use :inspect command to check them, their [variables] always shows empty. How do I access to these specific unit to store variable and make filter by their variable? Thank you.
https://imgur.com/a/IhFae
(Here is another dumb question, how do I upload image by using [img].[/img])
here is my WML: (one more question, these code arrange step by step like a ladder in my UMC dev, but why after I paste them onto here, they show up in a mess??)
It's me again, I really find myself with poor WML skill and out of talent...
Anyway, I try to create some object to every unit who "equip" it, and I also want to add a variable on these unit for record so that I can add a filter to prevent them equip twice. This time my question is, I've tried [store_unit], [set_variable] to put a variable into these specific units, but when I use :inspect command to check them, their [variables] always shows empty. How do I access to these specific unit to store variable and make filter by their variable? Thank you.
https://imgur.com/a/IhFae
(Here is another dumb question, how do I upload image by using [img].[/img])
here is my WML: (one more question, these code arrange step by step like a ladder in my UMC dev, but why after I paste them onto here, they show up in a mess??)
Code: Select all
[option]
message= {MENU_IMG_TXT2 attacks/trample.png ("<span color='green'>" + _ "Iron Horseshoe" + "</span>x$inventory[$side_number].ironhorseshoe") "Move +1" }
[show_if]
[variable]
name=inventory[$side_number].ironhorseshoe
greater_than=0
[/variable]
[and]
[have_unit]
x,y=$x1,$y1
type=Horseman,Knight,Lancer,Cavalier,Grand Knight,Paladin,Cavalryman,Cavalier,Dragoon
[/have_unit]
[/and]
[/show_if]
[command]
[if]
[have_unit]
x,y=$x1,$y1
[filter_wml]
[variables]
name=unit.variables.ironhorseshoe
equals=yes
[/variables]
[/filter_wml]
[/have_unit]
[then]
[message]
speaker=unit
message= _ "I already have one"
[/message]
[/then]
[else]
[set_variable]
name=inventory[$side_number].ironhorseshoe
sub=1
[/set_variable]
[object]
silent=yes
[effect]
apply_to=movement
increase=1
[/effect]
[/object]
[store_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=ironhorseshoe
[/store_unit]
{VARIABLE $this_unit.variables.ironhorseshoe yes}
#not sure if [unstore_unit] is needed
[unstore_unit]
variable=ironhorseshoe
[/unstore_unit]
[/else]
[/if]
[/command]
[/option]
Re: Problem with adding variables into units and filtering t
{VARIABLE $this_unit.variables.ironhorseshoe yes} remove $
(Here is another dumb question, how do I upload image by using [img].[/img]) link should end with .png
'(one more question, these code arrange step by step like a ladder in my UMC dev, but why after I paste them onto here, they show up in a mess??) mixed tabs and spaces
(Here is another dumb question, how do I upload image by using [img].[/img]) link should end with .png
'(one more question, these code arrange step by step like a ladder in my UMC dev, but why after I paste them onto here, they show up in a mess??) mixed tabs and spaces
Re: Problem with adding variables into units and filtering t
Code: Select all
[filter_wml]
[variables]
# WRONG name=unit.variables.ironhorseshoe
# WRONG equals=yes
# SHOULD BE...
ironhorseshoe=yes
# DONE!
[/variables]
[/filter_wml]
Code: Select all
[store_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=ironhorseshoe
[/store_unit]
# WRONG {VARIABLE $this_unit.variables.ironhorseshoe yes}
# SHOULD BE...
{VARIABLE ironhorseshoe.variables.ironhorseshoe yes}
# DONE!
[unstore_unit]
variable=ironhorseshoe
[/unstore_unit]
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
-
- Posts: 25
- Joined: February 29th, 2012, 2:04 pm
- Location: Taiwan
Re: Problem with adding variables into units and filtering t
Thanks Ravana & Sapient!!! You do solve my problem, although it still difficult for me to figure out how it works...
Here is another question with Variable.
When I use command [recall], I try to locate a specific landplace near my ship(x,y).
I use :inspect to look into the "x,y" of this variable landplace, and it do have the right input (x,y). But recall always end with unit appears near at my leader. How come?
Here is another question with Variable.
Code: Select all
[set_menu_item]
id=Landing_Down_{DIRECTION}
description=_ "Landing Unit"
[show_if]
[have_unit]
x,y=$x1,$y1
side=$side_number
ability=transport_humans
[/have_unit]
[have_location]
terrain=Gg,Gs
[filter_adjacent_location]
x,y=$x1,$y1
side=$side_number
ability=transport_humans
adjacent={DIRECTION}
[/filter_adjacent_location]
[/have_location]
[/show_if]
[command]
[store_unit]
[filter]
x,y=$x1,$y1
ability=transport_humans
[/filter]
variable=ship
[/store_unit]
[store_locations]
terrain=Gg,Gs
[filter_adjacent_location]
x,y=$x1,$y1
side=$side_number
ability=transport_humans
adjacent={DIRECTION}
[/filter_adjacent_location]
variable=landplace
[/store_locations]
#situation1 {VARIABLE temp_x $landplace.variables_x}
#situation1 {VARIABLE temp_y $landplace.variables_y}
--------------------
#situation2 {VARIABLE temp_x $landplace.variables.{DIRECTION}_x}
#situation2 {VARIABLE temp_y $landplace.variables.{DIRECTION}_y}
--------------------
#situation3 {VARIABLE temp_x $landplace_x}
#situation3 {VARIABLE temp_y $landplace_y}
[unstore_unit]
variable=ship
[/unstore_unit]
{CLEAR_VARIABLE ship}
{CLEAR_VARIABLE landplace}
{CLEAR_VARIABLE temp_x}
{CLEAR_VARIABLE temp_y}
[/command]
[/set_menu_item]
I use :inspect to look into the "x,y" of this variable landplace, and it do have the right input (x,y). But recall always end with unit appears near at my leader. How come?
Code: Select all
[recall]
id={target_unit_id}
x,y=$temp_x,$temp_y
[/recall]
- Pentarctagon
- Project Manager
- Posts: 5564
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Problem with adding variables into units and filtering t
The [recall] wiki documentation says that units are placed at those coordinates rather than next to the leader. Since you are giving an x and y coordinate and the unit is still appearing next to the leader, I would guess that
$temp_x,$temp_y
do not contain valid x and y coordinates.99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
-
- Posts: 25
- Joined: February 29th, 2012, 2:04 pm
- Location: Taiwan
Re: Problem with adding variables into units and filtering t
Hi Pentarctagon,
Thanks for your explaination!!After I change WML to this, problem resolves!
Thanks for your explaination!!After I change WML to this, problem resolves!
Code: Select all
{VARIABLE temp_x $landplace.x}
{VARIABLE temp_y $landplace.y}