The Dink Network

Touching!

March 25th 2008, 03:32 PM
bonca.gif
Christiaan
Bard They/Them Netherlands
Lazy bum 
I have a question about the void touch (void) procedure.

Is it possible to trigger something when a sprite other than Dink touches a certain scripted object? For example, when Lyna touches a scripted wall, Dink says something.

Is this possible or anything that works like this?
March 25th 2008, 04:10 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
You would have to use a loop to check if the certain sprite is in a specific range of coordinates using inside_box.
March 25th 2008, 05:41 PM
bonca.gif
Christiaan
Bard They/Them Netherlands
Lazy bum 
Ok, how do I do that?
March 25th 2008, 06:59 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
Eh, nvm this post, I seem to be on some kind of crack
March 25th 2008, 07:02 PM
dinkdead.gif
loop:
wait(100);
int &x = sp_x(&sprite, -1);
int &y = sp_y(&sprite, -1);
int &box = inside_box(&x, &y, left, top, right, bottom);
//left, right etc set as touch area
if (&box)
{
//do stuff
}
goto loop;

Or if it's a straight area (like a wall) you could just use sp_x/y() instead of inside_box()...

loop:
wait(100);
&x = sp_x(&sprite, -1);
if (&x > ??)
{
//do stuff
}
goto loop;

...Heh, posted at the same time as Rabid.
March 25th 2008, 07:38 PM
fairy.gif
Someone
Peasant He/Him Australia
 
better to set wall brain to 11 (missile) & use damage() function for touch code
March 25th 2008, 09:03 PM
bonca.gif
Christiaan
Bard They/Them Netherlands
Lazy bum 
Thanks, but I still don't quite get it... Let's say you have 2 scripts, one for a rock, with a "box" around it.

Would that script look like your script, so like this?

void main (void)
{
loop:
wait(100);
int &x = sp_x(&sprite, -1);
int &y = sp_y(&sprite, -1);
int &box = inside_box(&x, &y, 380, 175, 515, 220);
//left, right etc set as touch area
if (&box)
{
say("hey", 1);
}
goto loop;
}

And the other script, for Lyna, when she enters the box, something happens. How would that script look like?
March 26th 2008, 05:59 AM
wizardb.gif
Endy
Peasant He/Him United States
 
You can use the same script for both actions, you just have to know Lyna's sprite number. You can either:

Do a search for Lyna's sprite

Spawn Lyna's script directly

Save Lyna's sprite number into a global in the main procedure of Lyna's script, then read it from the box script

Save Lyna's sprite number into one of Dink's attributes and then read it back in the box script

Basically:

//Lyna's script
void main( void )
{
sp_gold(1, ¤t_sprite);
}

and before the loop in the other script:

//short wait to allow lyna's script to work
wait(1);
int &girl = sp_gold(1, -1);

Then just use another smaller loop to check both Dink and the girl, by reseting &sprite