The Dink Network

Reply to Re: Script interference

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
July 31st 2018, 12:35 PM
spike.gif
SlipDink
Peasant He/Him United States bloop rumble
2nd generation. No easy way to be free. 
@toof:

But when I talk to him, the entire script attached to him stops working. The conversation doesn't even start. Is this a limitation to the engine, or is there a workaround?

To quote the DINKC Reference v3.1 text file:
The other use of wait() pertains to the fact that the while the dink engine
tries to do many things at once, that is just an illusion. Modern computers
can run huge numbers of instructions per second, but still only one at a time.
Operating systems such as Windows have very sophisticated methods (not all of
them successful...) of making all running programs "take turns" using the CPU.
Within the dink engine, the strategy is more straightforward. Once it starts
running a script, for example, that's all it does -- until the script either
ends or it runs a command that releases the dink engine temporarily to turn
its attention to other tasks. wait() is most important of these commands.

So any wait(), even a wait(1), makes a script "yield the floor" to other
active scripts to allow them time to finish or at least get to their own
wait() points before this script is resumed. See "Part 6 - Overview of
Script Execution", for a discussion of why this is an important trick to
know and understand.]


Below is my version of your script fragment. A quarter of a second is not long for a human wait; but it is practically an eternity for DinkC and most other languages. You could probably get away with a much smaller wait, but I like to make any wait()s within loops as large as is practical, to give the computer a little more time to get other things done.

void main(void)
{
	int &rand;
loop:
	wait(250);
	&rand = random(2,1);
	if(&rand == 1)
	{
		//conversation with other npcs, using say_stop_npc();
	}
	//etc
	goto loop;
}

void talk(void)
{
	//say_stop() and the rest
}


Two other points are:
#1 You have an infinite loop in your code at present. While it should be true that the loop will be terminated when Dink moves to a screen not associated with the script, the code as it is presently written will continually repeat the say_stop_npc(); conversation. You may want to change that.
#2 There are more recent versions of the DINKC help file including a 4.0 version of the DinkC Reference available on the DN as a part of a package that includes other Dink related software, but I always look in the 3.1 text file first. I recommend you make sure to read "Part 6 - Overview of Script Execution" of the 3.1 text file soon.