I am having problems with the MOVE_UNIT macro

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
Devrailis Colandore
Posts: 76
Joined: April 22nd, 2007, 3:16 am
Location: Canada

I am having problems with the MOVE_UNIT macro

Post by Devrailis Colandore »

I'm having trouble getting the MOVE_UNIT macro to work. I copied the macro from the WMLwiki (it's MOVE UNIT 2):

Code: Select all

# Moves a unit from its current location to the given location along a
# relatively straight line displaying the movement just like [move_unit_fake]
# does.
#
# Note that setting the destination on an existing unit does not kill either
# one, but causes the unit to move to the nearest vacant hex instead.

#define MOVE_UNIT FILTER TO_X TO_Y
    [store_unit]
        [filter]
            {FILTER}
        [/filter]
 
        variable=MOVE_UNIT_temp
        kill=no
    [/store_unit]

    [scroll_to]
        x=$MOVE_UNIT_temp.x
        y=$MOVE_UNIT_temp.y
    [/scroll_to]

    [hide_unit]
        x=$MOVE_UNIT_temp.x
        y=$MOVE_UNIT_temp.y
    [/hide_unit]

    {VARIABLE_OP x_coords format ("$MOVE_UNIT_temp.x|,{TO_X}")}
    {VARIABLE_OP y_coords format ("$MOVE_UNIT_temp.y|,{TO_Y}")}

    [move_unit_fake]
        type=$MOVE_UNIT_temp.type
        x=$x_coords
        y=$y_coords
    [/move_unit_fake]

    [teleport]
        [filter]
            {FILTER}
        [/filter]

        x,y={TO_X},{TO_Y}
    [/teleport]

    [unhide_unit][/unhide_unit]

    [redraw][/redraw]
#enddef
Everything in my scenario is currently working except for this macro. When I remove it, the scenario works fine. However, when I add the macro, I get the following error message:

Missing closing tags for tag message at:

It then lists my scenario and campaign cfg files twice.

In my scenario, the code I've used is:

Code: Select all

{MOVE_UNIT description=Test Unit 2 27}
I think this means that I call on the MOVE_UNIT macro, apply it to the filter -> description=Test Unit, and move it to x=2, y=27. Test Unit is the name of the unit that I am applying the macro to. The name Test Unit works for all other tags except for the macro, so I doubt this has anything to do with the unit.

The error message says that I am missing closing tags but I've double checked the code in my campaign, scenario and macro cfgs and there doesn't seem to be any open tag issues. I've already appended the utils folder and the macro.cfg file within that folder in the #ifdef section of the campaign cfg, so the macro file should be called upon. In fact, if I change the macro to a term that does not exist, there is no error. It's only when the macro that I call matches the name of the macro in the macro file that I get the error. I verified this by changing the name of the macro in the macro file.

When the macro is removed, there is no problem at all, so I think it must be a problem with the macro file, however I can't seem to find it. Would it be possible for someone to take a look at what I might be doing wrong? Am I supposed to make any additions to the movement macro?

I've tried several things to solve the problem but nothing seems to work. I'd appreciate any help you guys can offer. Thanks in advance.
User avatar
Mist
Inactive Developer
Posts: 753
Joined: February 15th, 2007, 8:44 am
Location: Milton Keynes, UK

Re: I am having problems with the MOVE_UNIT macro

Post by Mist »

Devrailis Colandore wrote: In my scenario, the code I've used is:

Code: Select all

{MOVE_UNIT description=Test Unit 2 27}
Macro is fine, your application is buggy. I'll first tell you how preprocesor understand the macro as it's given and then you should understand the rest

Space is the separator between macro arguments, so you have :
{MOVE_UNIT - expand the macro/file MOVE_UNIT with arguments
description=Test
Unit
2
27
That gives four arguments to a macro understanding three, thus the error message.

And thus a solution :
Because space is a separator you need to change two strings 'description=Test' and 'Unit' into one by using quote marks or brackets.
{MOVE_UNIT description="Test Unit" 2 27}
{MOVE_UNIT (description=Test Unit) 2 27}
Both of above will work.
Somewhere, between the sacred silence and sleep.
Disorder.
Devrailis Colandore
Posts: 76
Joined: April 22nd, 2007, 3:16 am
Location: Canada

Post by Devrailis Colandore »

Oh wow, now that I look at it, I'm surprised I didn't catch that myself. I've spent an entire day just trying to figure it out. Thank you very much for your help, I really appreciate it.
Post Reply