The Dink Network

help wanted: script bug

January 13th 2009, 02:32 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
While making a script for animal feed (works on only ducks thus far) I've come to a problem. When I have multiple feed piles active, the ducks won't go back to being ducks until all piles are eaten. Here's the script if anyone cares to look into it.

//Animal Feed seed

void main ()
{
//so it doesn't disappear
wait(200);
sp_brain(&current_sprite,0);
sp_que(&current_sprite,-10);

//big box for attracting animals
int &top = sp_y(&current_sprite,-1);
&top -= 40;
int &bottom = sp_y(&current_sprite,-1);
&bottom += 90;
int &left = sp_x(&current_sprite,-1);
&left -= 50;
int &right = sp_x(&current_sprite,-1);
&right += 90;

//smaller 'feeding' box
int &fleft = sp_x(&current_sprite,-1);
&fleft -= 20;
int &ftop = sp_y(&current_sprite,-1);
&ftop -= 20;
int &fright = sp_x(&current_sprite,-1);
&fright += 20;
int &fbottom = sp_y(&current_sprite,-1);
&fbottom += 20;

int &box;
int &duck;
int &dx;
int &dy;
int &count = 100;

//check for animals near feed to be attracted
duckcall:
wait(75);

&duck = get_rand_sprite_with_this_brain(3,0);
&dx = sp_x(&duck,-1);
&dy = sp_y(&duck,-1);
&box = inside_box(&dx,&dy,&left,&top,&right,&bottom);
if (&box)
{
if (sp_target(&duck,-1) == 0)
{
if sp_gold(&duck,-1) == 0)
{
//brain 9 needed for targeting
sp_brain(&duck,9);
sp_target(&duck,&current_sprite);
}
}
}

//feed depletion
&duck = get_rand_sprite_with_this_brain(9,0);
&dx = sp_x(&duck,-1);
&dy = sp_y(&duck,-1);

if (sp_target(&duck,-1) == &current_sprite)
{
&box = inside_box(&dx,&dy,&fleft,&ftop,&fright,&fbottom);
if (&box)
{
//say("<Nom>",&duck);
&count -= 1;
}
}

//it shrinks!
sp_size(&current_sprite,&count);

if (&count > 1)
goto duckcall;

//fixing brains and go back to business
&duck = 0;
reduck:
wait(25);
&duck = get_next_sprite_with_this_brain(9,0,&duck);
if (sp_target(&duck,-1) == &current_sprite)
{
//Target feed? It's a duck!
sp_brain(&duck,3);
//say("imaduck",&duck);
}
if (&duck > 0)
goto reduck;

//byebye feed
sp_active(&current_sprite,0);
sp_kill(&current_sprite,1);
}
January 13th 2009, 03:08 PM
dinkdead.gif
The last bit (fixing brains and go back to business, get_next_sprite_with_this_brain) is probably finding ducks feeding from the other piles and they won't get changed back because they're not targeting the right pile.
Check for inside_box again before you check the targeting and see if that works.

I like the idea!

Edit: I notice an sp_gold check, but it's not set anywhere. Is that part of it?
Also, with my idea (presuming it works) you might still have problems if the piles are near each other. Maybe set sp_gold for the ducks eating from this pile? 1 for first pile, 2 for 2nd etc. Perhaps over-complicated...
January 13th 2009, 04:16 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
Sp_gold() is to calculate whether or not the duck is headless or not (may ultimately just check for sp_pseq.) This is so headless ducks don't swarm around the feed pile like they are eating

The script checks to make sure the duck doesn't already have a target, so no problems getting confused between different piles. I did however just realize that I never reset this after the pile is gone. That problem is fixed though

The script specifically uses &current_sprite (attached to the feed pile) so I don't see how checking for the box would yield any better results.
January 13th 2009, 04:53 PM
dinkdead.gif
Yeah... ignore me. Sorry.

Anyway, I did better this time! You need to add to &duck otherwise get_next_sprite_with_this_brain is checking the same duck each time.

This works (I tested):

reduck:
wait(25);
&duck = get_next_sprite_with_this_brain(9,0,&duck);
if (sp_target(&duck,-1) == &current_sprite)
{
//Target feed? It's a duck!
sp_brain(&duck,3);
//say("imaduck",&duck);
}
if (&duck > 0)
{
&duck += 1;

goto reduck;
}

January 13th 2009, 05:32 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
Ah yes, that does work. And it is very entertaining to feed the ducks and then take them all out with one punch. Almost as entertaining as taking out a momma duck and her ducklings

It's a shame I've used get_next_sprite_with_this_brain() so many times and I still always seem to mess it up. One of these days I'll get it right