Announcement: Be excellent to each other.


Caravel Forum : DROD Boards : Bugs : Scripting and Speed Potions
New Topic New Poll Post Reply
Poster Message
RuAdam
Level: Master Delver
Rank Points: 157
Registered: 08-24-2004
IP: Logged

File: Bug Demo Hold.hold (2.1 KB)
Downloaded 37 times.
License: Public Domain
icon Scripting and Speed Potions (0)  
I found a bug that appears in scripting when speed potions are used.

Here's the setup:
First character sets Tmp variable to zero. Then it does an if move check. The check is a free action. (The character is either unable to move, or as in this example, is not ordered to move at all) Finally the character will turn clockwise if Tmp is zero, and counter-clockwise if it's not.

The second character sets Tmp to one, then waits one turn.

Under normal conditions, as it's expected, the first character will rotate clockwise.
However if a speed potion is used, the character will start rotating counter-clockwise.

I'm unsure what happens exactly. But I guess the problem lies somewhere with the move check.

I've included a hold to demonstrate the bug.

Character #1
Click here to view the secret text


Character #2
Click here to view the secret text


Edit:
Forgot to mention.
Running DROD TCB 3.2.1.89

[Last edited by RuAdam at 02-19-2011 07:17 PM]
02-19-2011 at 06:48 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
TFMurphy
Level: Smitemaster
Rank Points: 3118
Registered: 06-11-2007
IP: Logged
icon Re: Scripting and Speed Potions (+2)  
It's not a completely free check. Move commands cannot be used on Half Turns. Doesn't matter if the Move does nothing: that won't be looked at until you reach a Full Turn.

That means on the Half Turn, Character #1 simply sets Temp to 0, and then waits for the next Full Turn. Meanwhile, Character #2 then sets Temp to 1 on its own turn.

On the Full Turn, Character #1 *won't* set Temp to 0 because it was waiting patiently to check the effects of the Move command. And thus, when it finds that the Move command does nothing, it'll skip on to the next command and see that Temp is 1, and thus turn counter-clockwise.

===

In short, it's not a bug. Move commands are deliberately not checked on Half Turns, and will cause the script to pause until the next Full Turn. You can use this to your advantage depending on what you want a script to do, but don't expect things to run just as they do when using Speed Potions (especially when Character 'movement order' comes into play).
02-19-2011 at 10:01 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
RuAdam
Level: Master Delver
Rank Points: 157
Registered: 08-24-2004
IP: Logged
icon Re: Scripting and Speed Potions (0)  
That does seem to explain it. But something still bothers me.

First of all I thought that scripts don't execute at all on half turns. But after some testing I managed to make an NPC disappear on a Half Turn, so I guess scripts do run on Half Turns. But I'm not quite sure why. Is there any benefit to it?

And I still don't quite get how the problem happens.
Here it is as I understand:

A Full Turn ends as such:
- Character #1 rotates in either direction, script stops there.
- Character #2 sets Tmp to 1, stops at Wait command.

On Half Turn:
- Character #1 sets Tmp to 0, stops at move check.
- Character #2 should be still waiting.

Next Full Turn:
- Character #1 finishes move check, Tmp should still be 0.
- Character #2 sets Tmp to 1, stops at Wait command.

What am I missing here?

I can see how the problem would be present if character order was reversed. But if I do reverse the order, the problem is not present. Isn't movement order messed up somehow?
02-20-2011 at 08:04 AM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
TFMurphy
Level: Smitemaster
Rank Points: 3118
Registered: 06-11-2007
IP: Logged
icon Re: Scripting and Speed Potions (+2)  
RuAdam wrote:
But after some testing I managed to make an NPC disappear on a Half Turn, so I guess scripts do run on Half Turns. But I'm not quite sure why. Is there any benefit to it?
If scripting didn't run on Half Turns, it would become very difficult to detect whether certain events occur, like if the Player moves into a particular spot, or cuts some Tar, or stabs a monster, or even rotates to face another direction: all so long as the player does these on Half Turns. This is a rather large reduction in functionality. Allowing scripting to run every turn is a far more powerful option, but does require the architect to be more aware of how Speed Potions interact with scripting. And, of course, as a compromise, certain commands cannot run on a Half Turn.

RuAdam wrote:
On Half Turn:
- Character #1 sets Tmp to 0, stops at move check.
- Character #2 should be still waiting.
There's your second misunderstanding. Wait 1 waits for 1 Player Turn, whether hasted or not. The catch is that Wait commands can't *start* on Half Turns either (except for Wait 0, which is only ever a single Player Turn). So Wait 1 would wait for 1 Half Turn if started on a Full Turn, or 2 Half Turns if started on a Half Turn. This follows for higher numbers of Waits: Wait 10 would wait for 10 Half Turns if started on a Full Turn, or 11 Half Turns if started on a Half Turn. (EDIT: I'll agree that this method of counting Waits is rather unintuitive: it would be better if it either always allowed it to work on Half Turns, or didn't count on Half Turns at all.)

So on the Half Turn, Character #2 sets Tmp to 1, then attempts to Wait, but can't start it until the next Full Turn. Wait 1 essentially forces all commands run in Character #2's scripting loop to be run on each Half Turn.

[Last edited by TFMurphy at 02-20-2011 03:24 PM]
02-20-2011 at 03:11 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
RuAdam
Level: Master Delver
Rank Points: 157
Registered: 08-24-2004
IP: Logged
icon Re: Scripting and Speed Potions (0)  
I see, well that explains it. I wasn't aware about the Wait command acting like that. (And I also agree that it's a tad awkward)

Thanks for the clarification.
02-20-2011 at 05:47 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD Boards : Bugs : Scripting and Speed Potions
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.