How to make unit slowed when it is carrying a ball?
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.
"Yes" works, too.Swordy wrote:umm hello...
it's 'on', not 'yes'Code: Select all
{MODIFY_UNIT x,y=$x1,$y1 status.slowed yes}
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]
Spot the error.Code: Select all
{DEBUG_MSG (_"Side turn event)}
Thankszookeeper wrote:Spot the error.Code: Select all
{DEBUG_MSG (_"Side turn event)}

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]
First message: "Side turn event"
Second message: "|"
- Attachments
-
- Second Messge
- secondmessage.jpg (2.59 KiB) Viewed 3681 times
First, I made a mistake at the second debug message. Should be:
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 "|" ?
Code: Select all
[if]
[variable]
name=unit.length
greater_than=0
[/variable]
{DEBUG_MSG (_"Units stored")}
/if]
Question: how often do you get the message "|" ?
First read, then think. Read again, think again. And then post!
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:
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!
Thanks toms
After I have added the code, it can slow the ball-carrying unit each turn
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
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
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
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!"
After I have added the code, it can slow the ball-carrying unit each turn

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

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

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

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!"

- 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

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]|")}
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]
Code: Select all
[unstore_unit]
variable=unit[$j]
[/unstore_unit]
First read, then think. Read again, think again. And then post!
Thanks again toms
You've spend lots of time on helping me.
I'm glad with your help
After I have replaced the code, it solves the problem of disappearance but trouble comes again
It can't slow the ball-carrying unit each turn.
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.
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.
You've spend lots of time on helping me.
I'm glad with your help

After I have replaced the code, it solves the problem of disappearance but trouble comes again

It can't slow the ball-carrying unit each turn.
Sorry, I can't get the meaning of thattoms wrote:...Second, which units do you actually want to remove?...

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]
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.
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:
by:
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]
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!
It works.Thanks NeoPhileNeoPhile wrote:...{DEBUG_MSG (_"$unit[$j].description")}

Perhaps I haven't done it correctly.I have tried that but it slows all side 1 and side 2 units.toms wrote:...One suggestion that _might_ work:
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

I'm sorry for wasting much your time

And thanks everyone in this thread
