Problems with multiple hits
The animation (and noise etc) plays every time if I keep hitting this sprite, how can I make it play just once? It does disappear from sight though.
If I hit it then wait for a bit it disappears properly and is unhittable, presumably after the wait(600).
It makes no difference if I put the nohit first with a wait(1) afterwards. How can I fix this?
void hit (void)
{
playsound(61, 44100, 0, ¤t_sprite, 0);
&chickpanic = 1;
sp_nodraw(¤t_sprite, 1);
sp_nohit(¤t_sprite, 1);
freeze(¤t_sprite);
&x = sp_x(¤t_sprite, -1);
&y = sp_y(¤t_sprite, -1);
&y -= 5;
&temp = create_sprite(&x, &y, 7, 945, 1);
sp_seq(&temp, 945);
wait(600);
&chickpanic = 0;
sp_active(¤t_sprite, 0);
kill_this_task();
}
If I hit it then wait for a bit it disappears properly and is unhittable, presumably after the wait(600).
It makes no difference if I put the nohit first with a wait(1) afterwards. How can I fix this?
void hit (void)
{
playsound(61, 44100, 0, ¤t_sprite, 0);
&chickpanic = 1;
sp_nodraw(¤t_sprite, 1);
sp_nohit(¤t_sprite, 1);
freeze(¤t_sprite);
&x = sp_x(¤t_sprite, -1);
&y = sp_y(¤t_sprite, -1);
&y -= 5;
&temp = create_sprite(&x, &y, 7, 945, 1);
sp_seq(&temp, 945);
wait(600);
&chickpanic = 0;
sp_active(¤t_sprite, 0);
kill_this_task();
}
Sprite's hit procedure is run even if it's nohit is set to 1. Try this:
void hit (void)
{
if (&chickpanic == 1)
return;
&chickpanic = 1;
playsound(61, 44100, 0, ¤t_sprite, 0);
sp_nodraw(¤t_sprite, 1);
sp_nohit(¤t_sprite, 1);
freeze(¤t_sprite);
&x = sp_x(¤t_sprite, -1);
&y = sp_y(¤t_sprite, -1);
&y -= 5;
&temp = create_sprite(&x, &y, 7, 945, 1);
sp_seq(&temp, 945);
wait(600);
&chickpanic = 0;
sp_active(¤t_sprite, 0);
kill_this_task();
}
So the hit proc is simply skipped if &chickpanic is set to 1. Was this what you wanted?
void hit (void)
{
if (&chickpanic == 1)
return;
&chickpanic = 1;
playsound(61, 44100, 0, ¤t_sprite, 0);
sp_nodraw(¤t_sprite, 1);
sp_nohit(¤t_sprite, 1);
freeze(¤t_sprite);
&x = sp_x(¤t_sprite, -1);
&y = sp_y(¤t_sprite, -1);
&y -= 5;
&temp = create_sprite(&x, &y, 7, 945, 1);
sp_seq(&temp, 945);
wait(600);
&chickpanic = 0;
sp_active(¤t_sprite, 0);
kill_this_task();
}
So the hit proc is simply skipped if &chickpanic is set to 1. Was this what you wanted?
Your post was so close to being deleted, too...
That's great, thanks. Forgot about that.
It still plays the hit sound more than once though...? The normal hit sound, not the playsound one.
It still plays the hit sound more than once though...? The normal hit sound, not the playsound one.
Hmm. Try moving the sp_nohit before the if-statement. BTW, you don't need to use kill_this_task as the sprite and it's script is killed automatically by setting sp_active to 0.
"Try moving the sp_nohit before the if-statement."
I did, that's what's odd.
Sometimes kill_this_task is needed there as the script isn't killed until it gets to the next wait(), so I put it in just in case while I was writing the rest. Now there's no need for it so I probably will take it out
I did, that's what's odd.
Sometimes kill_this_task is needed there as the script isn't killed until it gets to the next wait(), so I put it in just in case while I was writing the rest. Now there's no need for it so I probably will take it out
Hmm! Try sp_nohit(&temp, 1); after the &temp sprite has been created.









