The Dink Network

Scripting and WDE questions.

August 25th 2007, 04:14 PM
dinkdead.gif
Is there a way to make something happen if the player does nothing? For example if I want something to happen if the player presses no buttons for five seconds. I've been looking through DinkC reference but I can't find anything that helps.

Also, in WDE+ is there a way to copy and paste a whole screen: sprites, tiles, hardness, the lot?

Thanks
August 25th 2007, 05:46 PM
pillbug.gif
pillbug
Peasant He/Him United States
Love! True love! 
I can answer question 2. Right click one a blank spot on the screen, and hit copy. Then, on a blank screen, (the blank ones, with all black, no sprites, no tiles, etc) right click and hit paste. That should do it.
August 25th 2007, 05:59 PM
slimeb.gif
DaVince
Peasant He/Him Netherlands
Olde Time Dinkere 
About question 1, just place a wait(500) command in the main() function for any character or screen script, and it'll only execute the stuff in there until after five seconds.
August 25th 2007, 11:17 PM
sob_scorpb.gif
Hades
Peasant He/Him Australia
Remember you're unique, just like everyone else. 
wait(5000) for 5 seconds, I think that should work.
August 26th 2007, 03:38 PM
dinkdead.gif
Ok, that 2nd one was a bit of a stupid question
Thanks Pillbug

For the other question, I didn't mean just for nothing to happen for 5 seconds, what I meant was if nothing is happening, then something should happen.
To clarify , I'm trying to make a script that runs throughout the D-Mod where if Dink is left idle for however long (5-10 seconds), then he'll say or do something.
August 28th 2007, 05:25 PM
dinkdead.gif
Hmmm. Is there a way to detect if Dink is currently moving? I presume sp_speed is used to check what Dink's speed is set at, not what speed he is currently doing, is that right?
August 28th 2007, 05:43 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
Hmm, you'd probably be best to store the sp_x and sp_y of Dink, and if they change, you'll know that he moved.
August 30th 2007, 06:12 PM
dinkdead.gif
I'll ask this here rather than make a new thread:
If I want to attach a script to sprite 1000 so it will always be running, should I use sp_script or script_attach? I'm not quite sure of the difference.
What I want is to attach my script to sprite 1000 when starting or loading a game, so I don't mean as script_attach is normally used, in a cutscene for example.
August 30th 2007, 06:31 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
Use script_attach(1000);
sp_script(&sprite, "script"); gives the declared sprite a declared script. I don't think you want that here.
August 30th 2007, 08:58 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
script_attach(1000); Attaches the current script to 1000 (i.e. it will survive screenlocks, &current_sprite no longer makes sense, etc).
I'm not sure if sp_script(1000, "script"); works, but an equivalent is spawn("script");.

I think that in this case you want spawn();. Please keep in mind that just putting that in the main() proc of a savebot will screw things up slightly. You'll want the spawn() to only happen when you actually load a game, not when you just enter the screen.
August 31st 2007, 04:59 AM
dinkdead.gif
Great, that looks like just what just what I want.

Regarding what Redink1 said, how would I store the sp_x and sp_y of Dink, so that I can reference them after a wait();? I can only work out how to get the current position of Dink.
August 31st 2007, 07:07 AM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
I made a sample script that should help you. The only bug I could see happening is if Dink moved and ended up in the exact same coordinate That's highly unlikely though

//script starts
void main( void )
{
int &dx;
int &dy;
int &cur_x;
int &cur_y;

loop:
//we store his coordinates here
&dx = sp_x(1, -1);
&dy = sp_y(1, -1);

wait(5000);

//5 seconds later we get his coordinates again
//this is so we can compare them to see if he moves
&cur_x = sp_x(1, -1);
&cur_y = sp_y(1, -1);

if (&cur_x = &dx)
{
if (&cur_y = &dy)
{
//signifies that dink hasnt moves in 5 seconds
//what ever you want to happen, put in here
}
}
goto loop;
}

September 1st 2007, 02:24 PM
dinkdead.gif
I see. I thought of using two variables for the same thing but I presumed that when I used them in an if statement I would just be comparing the same thing to itself. Now I see if I set one before a wait then it remembers it from then when I come to use it... Thank you!!
September 1st 2007, 04:47 PM
dinkdead.gif
Grr... Still can't get the blasted thing to work!
What am I doing wrong? This is what I have so far (incorporating Rabid's script):
void main( void )
{
int &xpos;
int &ypos;
int &cur_x;
int &cur_y;
int &isfrozen;
loop:
&isfrozen = sp_freeze(1, -1);

if (&isfrozen == 0)
{
&xpos = sp_x(1, -1);
&ypos = sp_y(1, -1);

wait(7000);

&cur_x = sp_x(1, -1);
&cur_y = sp_y(1, -1);

if (&cur_x == &xpos)
{
if (&cur_y == &ypos)
{
say_stop("It works!", 1);
}
}
}
goto loop;
}

I attach this to a sprite and test it on that screen but nothing happens. I thought that maybe during Dink's idle sequence his depth dot moves around so to test this I changed it all to &current_sprite but it made no difference.
September 1st 2007, 06:18 PM
pillbug.gif
pillbug
Peasant He/Him United States
Love! True love! 
Try not attaching it to a sprite, but to the screen.
September 2nd 2007, 03:57 PM
dinkdead.gif
I don't believe it... It works! That actually makes a difference?

It works... to a point. I still need to do some fixing: When I froze Dink to test that part of it the game itself froze after a few seconds(ie. need ctrl+alt+del). When I tried again task manager wouldn't show up so I had to restart and my desktop was at 640x480 so it messed up all my nicely sorted icons .
This is one of my first scripts - maybe that's my mistake!
September 2nd 2007, 06:53 PM
spike.gif
In Dink, some time needs to pass inside the loop. In your script, the wait(); command will run only if Dink is unfrozen, effectively freezing the entire game when he's not.

loop:
wait(1);
goto loop;

works (although such a rapid loop may be laggy)

loop:
goto loop;

doesn't.
September 3rd 2007, 04:44 PM
dinkdead.gif
Ok that fixes it, thanks.
There's only one small bug I can find now, which is if Dink was still for a bit before getting frozen then my script is already in it's wait(); so he still says "It works!" while frozen.
I suppose I could check sp_freeze again but it's probably overkill as it's unlikely to happen during a game (not to mention using up 6 variables).

Thanks all!