Make units appear next to others

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
Yogibear
Retired Developer
Posts: 1086
Joined: September 16th, 2005, 5:44 am
Location: Hamburg, Germany

Make units appear next to others

Post by Yogibear »

Hi,

i have a unit (Robert) and by triggering a certain event i want another unit appear next to it. Here is what i tried so far:

[store_unit]
variable=robert_store
kill=yes
[filter]
description=Robert
[/filter]
[/store_unit]

[unit]
description=Slinger
user_description= _ "Slinger"
type=Thief
x=22
y=36
side=2
[/unit]

[store_unit]
[filter]
description=Slinger
[/filter]
kill=yes
variable=tempthief
[/store_unit]

[set_variable]
name=tempthief.x
value=robert_store.x - 2
[/set_variable]

[set_variable]
name=tempthief.y
value=robert_store.y - 2
[/set_variable]

[unstore_unit]
variable=tempthief
find_vacant=yes
[/unstore_unit]

[unstore_unit]
variable=robert_store
description=Robert
[/unstore_unit]

Obviously this does not work :? . In fact, the thief does not appear at all (he does so if i just remove all that store/unstore stuff but i have to fix his position then). What's the trick with this?
Smart persons learn out of their mistakes, wise persons learn out of others mistakes!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

Just create the unit at Robert's coordinates, and it'll be placed at an adjacent hex:

Code: Select all

[event]
    name=turn 4

    {STORE_UNIT_VAR description=Robert x rob_x}
    {STORE_UNIT_VAR description=Robert y rob_y}

    [unit]
        description=Slinger
        type=Thief
        x,y=$rob_x,$rob_y
        side=1
    [/unit]
[/event]
The STORE_UNIT_VAR macro from here.

Or a simpler (probably preferred) version:

Code: Select all

[store_unit]
    [filter]
        description=Robert
    [/filter]

    variable=robert_store
    kill=no
[/store_unit]

[unit]
    description=Slinger
    type=Thief
    x,y=$robert_store.x,$robert_store.y
    side=1
[/unit]
Last edited by zookeeper on February 17th, 2006, 2:39 pm, edited 1 time in total.
User avatar
appleide
Posts: 1003
Joined: November 8th, 2003, 10:03 pm
Location: Sydney,OZ

Post by appleide »

Don't know if it helps or not... But I am trying to... Are you sure... That you need to put kill=yes?
kill if 'yes' the units that are stored will be removed from play. This is useful for instance to remove access to a player's recall list, with the intent to restore the recall list later."
From my understanding of the wiki, kill=yes don't seem to be needed, when you are only modifying units.

Also, maybe use [teleport] instead of changing x and y of the unit.

I really do hope it helps... :)

EDIT: Zookeeper got there before me, so ignore this post.
Why did the fish laugh? Because the sea weed.
User avatar
Tomsik
Posts: 1401
Joined: February 7th, 2005, 7:04 am
Location: Poland

Post by Tomsik »

Code: Select all

 value=robert_store.x - 2 
try

Code: Select all

value=$robert_store.x - 2
I'm not sure "-2" will work, if it doesn't you need to change value of robert_store.x before using it.
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

Code: Select all

value=robert_store.x - 2
:?:
No. Take

Code: Select all

[set_variable]
name=tempthief.x
value=robert_store.x
[/set_variable]

[set_variable]
name=tempthief.x
add=-2
[/set_variable]
Short:

Code: Select all

{VARIABLE tempthief.x $robert_store.x}
{VARIABLE_OP tempthief.x add -2}
(these are built-in macros you don´t have to define)
First read, then think. Read again, think again. And then post!
Yogibear
Retired Developer
Posts: 1086
Joined: September 16th, 2005, 5:44 am
Location: Hamburg, Germany

Post by Yogibear »

Thanks folks :D .

My goodness, if you are used to programming c++ wml is a lot different :o .
Smart persons learn out of their mistakes, wise persons learn out of others mistakes!
Post Reply