How to make unit slowed when it is carrying a ball?

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.
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

Swordy has already pointed it out.

This is a debug message: {DEBUG_MSG (_"Narrator says something")} It's a predefined macro.
First read, then think. Read again, think again. And then post!
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

Swordy wrote:umm hello...

Code: Select all

{MODIFY_UNIT x,y=$x1,$y1 status.slowed yes}
it's 'on', not 'yes' ;)
"Yes" works, too.

Toms,

I have added that macro in the code but error has occured.

You said that debug message macro is predefined but I can't find it in the utils.cfg.
Do you mean I have to code it before?

I don't know whether it is wrong or not.

Code: Select all


[event]
   name=side turn
   first_time_only=no

 {DEBUG_MSG (_"Side turn event)} 

      [store_unit]
      variable=unit
         [filter]
side=1,2
         [/filter]
      [/store_unit]


      [if]
         [variable]
         name=unit
         greater_than=0
         [/variable]

 {DEBUG_MSG (_"Units stored")} 

      [/if]

      {FOREACH unit j}

 {DEBUG_MSG (_"|$unit[$j]|")}

      [if]
         [variable]
         name=unit.variables.has_ball1
         equals=yes
         [/variable]

 {DEBUG_MSG (_"...")}

         [then]
{MODIFY_UNIT x,y=$x1,$y1 status.slowed on}
            [message]
            speaker=unit
            message= _ "It is heavy!"
            [/message]
            [unstore_unit]
            variable=unit
            [/unstore_unit]
         [/then]
      [/if]
      {NEXT j}
[/event]
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

Code: Select all

{DEBUG_MSG (_"Side turn event)} 
Spot the error.
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

zookeeper wrote:

Code: Select all

{DEBUG_MSG (_"Side turn event)} 
Spot the error.
Thanks :D

Code: Select all

[event]
   name=side turn
   first_time_only=no

 {DEBUG_MSG (_"Side turn event")}

      [store_unit]
      variable=unit
         [filter]
side=1,2
         [/filter]
      [/store_unit]


      [if]
         [variable]
         name=unit
         greater_than=0
         [/variable]

 {DEBUG_MSG (_"Units stored")}

      [/if]

      {FOREACH unit j}

 {DEBUG_MSG (_"|$unit[$j]|")}

      [if]
         [variable]
         name=unit.variables.has_ball1
         equals=yes
         [/variable]

 {DEBUG_MSG (_"...")}

         [then]
{MODIFY_UNIT x,y=$x1,$y1 status.slowed on}
            [message]
            speaker=unit
            message= _ "It is heavy!"
            [/message]
            [unstore_unit]
            variable=unit
            [/unstore_unit]
         [/then]
      [/if]
      {NEXT j}
[/event] 
After I added the code above, only 2 messages appear.
First message: "Side turn event"
Second message: "|"
Attachments
Second Messge
Second Messge
secondmessage.jpg (2.59 KiB) Viewed 3681 times
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

First, I made a mistake at the second debug message. Should be:

Code: Select all

 [if] 
        [variable] 
         name=unit.length
         greater_than=0 
         [/variable] 
 {DEBUG_MSG (_"Units stored")} 
/if]
Second, you cannot use MODIFY_UNIT there, because the unit is already stored. Use {VARIABLE unit[$j].status.slowed on} instead of the modify unit macro.

Question: how often do you get the message "|" ?
First read, then think. Read again, think again. And then post!
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

toms wrote: ...Question: how often do you get the message "|" ?
It appears each turn.
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

You are using 1.1.7, where no | is required in messages before a dollar sign. (to insert a variable value) If you remove it, you won't get a message any more. there is something wrong with the variable.
Now, the (hopefully) correct WML:

Code: Select all

[event] 
   name=side turn 
   first_time_only=no 
#removed the message coz' the event fires
      [store_unit] 
      variable=unit 
      kill=yes
         [filter] 
         side=1,2 
         [/filter] 
      [/store_unit]
##just a debug message!!!
      [if] 
         [variable] 
         name=unit.length
         greater_than=0 
         [/variable] 
 {DEBUG_MSG (_"Units stored")} 
      [/if] 

      {FOREACH unit j} 

 {DEBUG_MSG (_"$unit[$j]|")} 

      [if] 
         [variable] 
         name=unit[$j].variables.has_ball1
         equals=yes 
         [/variable] 

         [then] 
     {DEBUG_MSG (_"...")} 
          {VARIABLE unit[$j].status.slowed on}
            [message] 
            speaker=unit 
            message= _ "It is heavy!" 
            [/message] 
          [/then] 
         [/if] 
            [unstore_unit] 
            variable=unit 
            [/unstore_unit] 
      {NEXT j} 
[/event]
First read, then think. Read again, think again. And then post!
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

Thanks toms
After I have added the code, it can slow the ball-carrying unit each turn :D
but something weird happens.

Situation 1

At the beginning of turn 1, a blank message appeared.

After I had clicked on the screen 2 times,
the blank message and the side 2 leader disappeared together :shock:
but side 1 and side 3 leader remained here.

After that, I used the side 1 leader to get the ball(slowed) and didn't recruit anyone.
Then,end turn.

At the beginning of turn 2, a blank message appeared.
Then, a "..." message appeared.
Then, a blank message appeared again.
Then, a "..." message appeared again.
After that, side 1 leader(carrying a ball) remained slowed :D and side 3 leader was still here but side 2 leader had gone forever.

Situation 2

At the beginning of turn 1, a blank message appeared.

After I had clicked on the screen 2 times,
the blank message and the side 2 leader disappeared together :shock:
but side 1 and side 3 leader remained here.

After that, I used the side 1 leader to recruit a Elvish Archer, a Elvish Fighter, a Elvish Scout and a Horseman.
Then, use the side 1 leader to get the ball(slowed).
Then,end turn.

At the beginning of turn 2, a blank message appeared.

After I had clicked on the screen 5 times,
the blank message, the side 1 leader, Elvish Fighter, Elvish Scout and Horseman disappeared at the same time
but Elvish Archer and side 3 leader remained here(Side 2 leader had gone forever).
Then, "You have been defeated!" :shock:
Attachments
Situation_2_with_recruitment_replay.zip
Situation 2 with recruitment replay
(985 Bytes) Downloaded 223 times
Situation_1_without_recruitment_replay.zip
Situation 1 without recruitment replay
(1016 Bytes) Downloaded 223 times
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

:shock:
Yes, thats really weird. The main problem is to figure out what is causing these weird things.
I just know that this makes the blank message:

Code: Select all

{DEBUG_MSG (_"$unit[$j]|")}
Just remove it for the first, or better comment it out.

Second, which units do you actually want to remove? The code stores sides 1 and 2, but you talk about leaders only and the side 3. Please clarify.

Then, I spot one more mistake yet. This is wrong:

Code: Select all

[unstore_unit]
variable=unit
[/unstore_unit]
Replace it with:

Code: Select all

[unstore_unit]
variable=unit[$j]
[/unstore_unit]
Do this stuff and then tell what errors you still get.
First read, then think. Read again, think again. And then post!
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

Thanks again toms
You've spend lots of time on helping me.
I'm glad with your help :D

After I have replaced the code, it solves the problem of disappearance but trouble comes again :cry:
It can't slow the ball-carrying unit each turn.
toms wrote:...Second, which units do you actually want to remove?...
Sorry, I can't get the meaning of that :oops:
I try to explain what I want to make.

In this scenario, side 1 and side 2 are on the same team and they fight against side 3.
(All sides can recruit.)
Side 1 and side 2 units can carry the unconscious unit(the ball) and transfer it to each other.
Then, the "ball"-carrying unit gets slowed.
The "ball"-carrying unit will move to a certain hex(temple) to unload the unconscious unit.Then, the unconscious unit will become a usable unit and the "ball"-carrying unit will become normal.

Code: Select all

[event]
   name=side turn
   first_time_only=no
#removed the message coz' the event fires
      [store_unit]
      variable=unit
      kill=yes
         [filter]
         side=1,2
         [/filter]
      [/store_unit]
##just a debug message!!!
      [if]
         [variable]
         name=unit.length
         greater_than=0
         [/variable]
 {DEBUG_MSG (_"Units stored")}
      [/if]

      {FOREACH unit j}

 {DEBUG_MSG (_"$unit[$j]|")}

      [if]
         [variable]
         name=unit[$j].variables.has_ball1
         equals=yes
         [/variable]

         [then]
     {DEBUG_MSG (_"...")}
          {VARIABLE unit[$j].status.slowed on}
            [message]
            speaker=unit
            message= _ "It is heavy!"
            [/message]
          [/then]
         [/if]
[unstore_unit]
variable=unit[$j]
[/unstore_unit]
      {NEXT j}
[/event]
Here's the process of the test:

At the beginning of turn 1, a blank message appeared.

After I had clicked on the screen 2 times,the blank message disappeared.
(All units were still here)

After that, I used the side 1 leader to recruit a Elvish Archer, a Elvish Fighter, a Elvish Scout and a Horseman.
Then, use the side 1 leader to get the ball(slowed).
Then,end turn.

After that, I used the side 2 leader to recruit a Horseman and a Knight.
Then,end turn.

At the beginning of turn 2, a blank message appeared.
After I had clicked on the screen 8 times,
the blank message disappeared but the ball-carrying unit(side 1 leader) didn't get slowed.
All units were still here.
NeoPhile
Posts: 155
Joined: July 22nd, 2004, 4:33 am
Location: Halifax, NS, Canada
Contact:

Post by NeoPhile »

Just a random guess, but I might know why you're getting blank messages. Instead of {DEBUG_MSG (_"$unit[$j]|")}, try {DEBUG_MSG (_"$unit[$j].description")}
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

The unit is probably not slowed because the has_ball variable does not work. I found no mistake though.

One suggestion that _might_ work:

1) Save a copy of the scenario somewhere else (for security)

2) Replace all {VARIABLE unit.variables.has_ball1 yes} by {VARIABLE_OP has_ball1 format $unit.description}

3) Replace this code:

Code: Select all

 [if] 
         [variable] 
         name=unit[$j].variables.has_ball1 
         equals=yes 
         [/variable] 
          [then] 
     {DEBUG_MSG (_"...")} 
          {VARIABLE unit[$j].status.slowed on} 
            [message] 
            speaker=unit 
            message= _ "It is heavy!" 
            [/message] 
          [/then] 
         [/if]
by:

Code: Select all

 [if] 
        {VARIABLE_OP temp_description format unit[$j].description}
         [variable] 
         name=$temp_description
         equals=$has_ball1
         [/variable] 

         [then] 
     {DEBUG_MSG (_"...")} 
          {VARIABLE unit[$j].status.slowed on} 
            [message] 
            speaker=unit 
            message= _ "It is heavy!" 
            [/message] 
          [/then] 
         [/if]
First read, then think. Read again, think again. And then post!
savagust
Posts: 56
Joined: November 19th, 2005, 4:00 am

Post by savagust »

NeoPhile wrote:...{DEBUG_MSG (_"$unit[$j].description")}
It works.Thanks NeoPhile :D
toms wrote:...One suggestion that _might_ work:
Perhaps I haven't done it correctly.I have tried that but it slows all side 1 and side 2 units.
However, it enlightens me.I have found another way to do that.

I added a dummy side for the ball-carrying unit and this dummy side is under human control and on the same team of unit's original side.

For example,
side 1 for the unit's original side and side 4 for the dummy side.

Whenever a unit carries the ball, it becomes side 4.
After the ball-carrying unit has unloaded the ball, it becomes side 1 again.

In the "side turn" event, all units in side 4 gets slowed.

After I had tried that, one problem occurred.

When side 1 leader got the ball, it became side 4 leader.
Then, there were two side 4 leaders.
After pressed "End Turn", one of them disappeared.

It seems that one side with two leaders is not allowed.
However, this problem can be solved by killing the dummy side in the "prestart" event.

I'm not sure that whether it is a good way or not because it also changes the leader's side, but it works now.

Thanks very much, toms
You've help me a lot :D
I'm sorry for wasting much your time :oops:

And thanks everyone in this thread :)
Post Reply