Announcement: Be excellent to each other.


Caravel Forum : DROD RPG Boards : RPG Architecture : Scripting and windows ding sound
New Topic New Poll Post Reply
Poster Message
XX_0000_0000
Level: Roachling
Rank Points: 12
Registered: 06-29-2020
IP: Logged
icon Scripting and windows ding sound (0)  
So I made this script of a basic shop:

Click here to view the secret text

...and for some reason when I choose *Leave option, windows ding sound is played, but the script itself works perfectly fine and as intended. In drodprg.log there's no entry about infinite loop, and making a simple label-loop-goto-loop script doesn't produce this sound but it sure does make it to the log.

The only way to fix this is to stick Wait 0 right before Wait for player to touch me command: no more ding sound. Now, I've found some info about Wait 0 usage on the forum, and I'm not remotely good at programming, but as I understood it stops the script at that point and continues on the next turn? But doesn't Wait for player to touch me already stop the script at that point?

If someone could clarify this I'd be very grateful, thank you!
09-19-2020 at 08:25 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
skell
Level: Legendary Smitemaster
Avatar
Rank Points: 3734
Registered: 12-28-2004
IP: Logged
icon Re: Scripting and windows ding sound (+2)  
Okay, quick lesson about how DROD processes events. This will be from the perspective of regular DROD, but the same should apply to RPG.

When you make a move, a new collection of events that have occurred is created. It starts empty. Then any event that's created is stored in that collection. The collection persists until the end of turn.

Okay, so you have command "Wait for player to touch me". What it does is it asks the event collection something like this:

"Hello good sir, do you have an event CID_PlayerBump that targets my X and Y position?"

What happens if the answer is no? It waits until the next turn and asks the question again, which repeats until the answer is Yes.

What happens if the answer is yes? It immediately runs the following script commands. Great!

But wait... What happens if in the same turn we encounter another "Wait for player to touch me"? Or the same? It asks the same collection the same question, and because the collection exists until the end of turn, if the answer was "Yes" previously it will be "Yes" until the turn ends. This is what creates an infinite loop.

In other words: if an event happened in a turn it happened for all queries about that event until the end of that turn. That can cause infinite loops, so that's why you need to put Wait 0 somewhere, so that DROD has the time to end the turn, and collect new events in the next turn.

____________________________
My website | Facebook | Twitter
09-19-2020 at 11:03 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts High Scores This architect's holds Quote Reply
XX_0000_0000
Level: Roachling
Rank Points: 12
Registered: 06-29-2020
IP: Logged
icon Re: Scripting and windows ding sound (0)  
Ah, I see! So if I got it right, this particular script encounters the same Wait for player to touch me second time after choosing *Leave option, and then it goes past it to the next command which is Cut Scene 200 and thereafter Wait 0. But shouldn't it leave the game on the cut scene and trigger the question again? I expected that removing that Wait 0 command should trigger the question again after choosing *Leave option, but it doesn't, so I am confused as to what exactly is happening here.
09-20-2020 at 12:01 AM
View Profile Send Private Message to User Show all user's posts Quote Reply
skell
Level: Legendary Smitemaster
Avatar
Rank Points: 3734
Registered: 12-28-2004
IP: Logged
icon Re: Scripting and windows ding sound (+1)  
I am less familiar with this particular corner of drod code so I might be incorrect here, but!

Answering a question is a move that takes a real but partial turn [1]. Therefore if the same question is encountered multiple times in the same turn the answer was already provided by player's move, so it runs the same branch of code that applies to the answer again. And again. And again. Until the infinite-loop protection kicks in.

Alternatively DROD just does not know how to properly handle this situation. Regardless of the source of the problem you need to avoid the following:

1. Asking multiple questions in the same turn
2. Running the code for a question multiple times in the same turn


[1] Essentially only some of game code runs on answer-turns.

____________________________
My website | Facebook | Twitter
09-20-2020 at 11:32 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts High Scores This architect's holds Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD RPG Boards : RPG Architecture : Scripting and windows ding sound
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.