The Dink Network

problems with move() and wait()

November 1st 2010, 04:27 PM
peasantfr.gif
Made a script to let dink move to the left until he runs into something. In order to let dink not keep running against something and not reaching the left of the screen I made a loop to keep checking if dink is still moving. If not I just move him left to his current location overwriting the movement to the entire left of the screen. Here is the code I used, but Dink just keeps running against something instead of stopping his movement.

move(1, 4, 0, 0);

loop:

&dinkx = sp_x(1, -1);
wait(10);
&dinkx2 = sp_x(1, -1);

if (&dinkx != &dinkx2)
{
goto loop;
}

move(1, 4, &dinkx2, 0);


The problem is that the wait(10) for some reason doesn't work. I put say lines in between to see when the script stops and if I put a say-line in front of the wait Dink says it, but if I put it after the wait he doesn't say it. So I am pretty sure it has something to do with the waitline, I just don't understand why it doesn't work.

Does anyone know why it does not work (or another way to make it work)? Thanks in advance.
November 1st 2010, 04:46 PM
custom_iplaydink.gif
iplaydink
Peasant He/Him Sweden
Hmm.. 
What actually happens? Does the game crash or something?
I assume that you've tried increasing the wait?

Anyway it might be a good idea to do something like this:
move(1, 4, 0, 0);

loop:

&dinkx = sp_x(1, -1);
wait(10);
&dinkx2 = sp_x(1, -1);

if (&dinkx != &dinkx2)
{
goto loop;
}

&dinkxy2 += 5;
move(1, 6, &dinkxy2, 0);
sp_dir(1, 4);
//Otherwise dinks actual  x coordinate could be less
//Than dinkxy2 even though you force him to walk in  direction 4
//to that location, So he tries to go forward backwards, you get it? 
//it could screw things up...


EDIT: It's a very clever script if you get it to work! I remember trying something like that for three amulets but I never figured out a way to stop the sprite... But I was a really bad scripter back then...
November 1st 2010, 04:59 PM
peasantfr.gif
Yes I tried longer wait times. What happens is that if dink runs into a table for example he keeps running against it because he get stopped by the hardness as intended. Dink still tries to reach his destination so he keeps wallking against table but staying on the same point. So you have to restart because you can't do anything anymore.

Because the part where I try to find out if Dink is still moving doesn't work and therefor Dink doesn't stop moving he just keeps walking against the table.

The last movement is just to stop Dink from running against the table to make by making his end destination his current destination (which is &dinkx2). So he won't get stuck there I think, anyway that point in the script is not even reaced at the moment.

EDIT: yes scratcher I meant &dinkx2 instead of &dinkxy2, I changed it. See I made that mistake in the original script aswell, but unfortunatly that doesn't solve the problem (&dinkxy 2 does not exist)
November 1st 2010, 05:09 PM
spike.gif
&dinkx2 != &dinkxy2 ?
November 1st 2010, 05:19 PM
custom_iplaydink.gif
iplaydink
Peasant He/Him Sweden
Hmm.. 
Scratcher is right I just noticed that too and tried this script, runs like a charm..
	int &dinkx;
	int &dinkx2;
	freeze(1);
	move(1, 4, 0, 0);
	
	loop:
	&dinkx = sp_x(1, -1);
	wait(100);
	&dinkx2 = sp_x(1, -1);
	
	if(&dinkx != &dinkx2)
	{
		goto loop;
	}
	
	&dinkxy2 += 5;
	move(1, 6, &dinkx2, 0);
	sp_dir(1, 4);
	unfreeze(1);


But you probably have the vars declared somewhere else so comment them out.

EDIT: Would you mind if I borrowed parts of this script for a puzzle in Agatha, I just got an awesome idea...
November 1st 2010, 05:31 PM
peasantfr.gif
Hmm.. strange that it works for you. Strange thing is that I thought I had it working correctly before, but after copying it for the other 3 directrions I found out it didn't work anymore. Tried it several times now so it was not a one time glitch... Gonna try it again and if it doesn't work restart everything.

I don't mind if you use them for a puzzle iplaydink.
Think it might be the same kind of puzzle I designed the script for.
And as I edited in the previous post the dinkxy2 was a typo, changed that in the script already.
November 1st 2010, 05:37 PM
spike.gif
When is the script run/what is it attached to?

Scripts sometimes die if you use any type of wait command, the die procedure is the most notable example. sp_active() and sp_kill() work the same way, though it's probably kind of obvious that a script dies if you use those. =)
November 1st 2010, 05:46 PM
peasantfr.gif
script is attached to "999" I did that to be able to check if the script is running by checking if sprite 999 has a script attached to save a global. That was to prevent spawning the script multiple times. But what you say about the wait() killing the script is probably the reason. Tried a wait at the start of the script and it also kills the script.

EDIT: think I need to put it in the script attached to the screen then. But since there is a lot in that script already I wanted to make a seperate script for the movement of Dink.
November 1st 2010, 06:17 PM
peasantfr.gif
Oke, got it working now I put it in the script of the screen instead of a seperate script. Thanks for all the help Scratcher and iplaydink.

PS iplaydink, since you intend on using it I'll PM you the entire script.
November 2nd 2010, 05:24 AM
fairy.gif
ToKu
Peasant He/Him Austria
Think positiv. Say NO. 
I noticed that you have a blank after your if.

My expirience is that most of the times the dink engine will behave wrong in a case like this (well sometimes its going to be ok. Don't ask me why)

So just write if(&dinkx != &dinkx2) and it will work.
November 2nd 2010, 08:03 AM
peasantfr.gif
Didn't know that could give problems. Think I need to check all my scripts than cause I think I did that more often. Actually in the entire script where this is a part of I just checked and had to remove a space about 20 times, but with the spaces it did work good. Anyway if it can cause problems by other peoples dink engine I'll make sure there are no spaces behind the if. Thanks for the tip.

EDIT: Just deleted all spaces behind all if's. Found that even in the pillbug script which I copied from the original Dink (and slightly altered) are spaces behind the if. So if your Dink engine has problems with a space behind the if, it should have that problem aswell with the original Dink (checked and saw different scripts in the original Dink with a space behind the if). I think it doesn't matter if there is a space behind the if, but I removed them all so it should not give any problems.
November 2nd 2010, 09:08 AM
fairy.gif
ToKu
Peasant He/Him Austria
Think positiv. Say NO. 
Well that's the trouble with this. Often it works. But when not you are searching for hours - which I did the first time I stumbled across this.

I had a really simple script then (luckily) and I didn't want to believe it when I found the bug.

BTW: Did it help in your case?
November 2nd 2010, 09:43 AM
peasantfr.gif
It was not the problem in my case, the problem was that the wait command let the script die. By putting the script somewhere else I solved the problem.
November 3rd 2010, 01:45 PM
spike.gif
Yeah, looks like attaching a script to a nonexistant sprite stops the script. A bit of a shame, what you described above would have been a pretty neat trick.

It should still work if the script is attached to an existing sprite, but that would require some micromanagement (monitoring exactly what you attach it to).

EDIT: Maybe not. I tried this a little bit, but I couldn't get is_script_attached to recognize a script had been added with script_attach. For shame!