📧 Message Board Archive

REAL scripting question
Does anyone know if it is possible to make a sprite created by a script 'target' another sprite created by a script?



--WC
Re: REAL scripting question
: Does anyone know if it is possible to make a sprite created by a script 'target' another sprite created by a script?

: --WC

How about using a global var in the second sprite;

&glvar = &current_sprite;

//the global is now set to that sp.#

then in the first sp;

wait(1);

sp_target(&current_sprite,&glvar);

I did this sort of thing in the Bane demo (the rand-  scripts). Works fine.
Re: REAL scripting question
: Does anyone know if it is possible to make a sprite created by a script 'target' another sprite created by a script?

: --WC



everything is possible:



int &target1 = create_sprite(blablabla)

int &target2 = create_sprite(blablabla)

sp_target(&target1, &target2)
Re: REAL scripting question
nope, wont work. Ok, here is what I did, maybe someone can figure it out.



SCRIPT



//huge cut sceen

int &guard = create_sprite(620, 68, 0, 293, 1);

int &p1 = create_sprite(159, 331, 0, 857, 10);

int &p2 = create_sprite(206, 351, 0, 857, 10);



//stuff here to make them walk and attack



//now, we want to guard to attack every baddy left on the screen



goto attacker;



attacker:



int &attack = get_rand_sprite_with_this_brain(9, &current_sprite);



sp_target(&guard, &attack);



wait(5000);



goto attacker;
Re: REAL scripting question
: attacker:

: int &attack = get_rand_sprite_with_this_brain(9, &current_sprite);

: sp_target(&guard, &attack);

: wait(5000);

: goto attacker;



Okay, what brain is the guard? 9 or 10? It looks like you have a problem either way. I'm assuming this script snipet is not attached to the guard, since it refers to him as &guard, not &current_sprite. So if he's brain 9 he is not excluded from the get_rand_sprite_with_this_brain command and could end up targeting himself. If he's brain 10, he can't target (at least in the sense of "chase") anyone at all.



Unless what that script is attached to is also brain 9 then you may be able to fix it like this:

int &attack = get_rand_sprite_with_this_brain(9, &guard);
Hm....mabey.....
: nope, wont work. Ok, here is what I did, maybe someone can figure it out.

: SCRIPT

: //huge cut sceen

: int &guard = create_sprite(620, 68, 0, 293, 1);

: int &p1 = create_sprite(159, 331, 0, 857, 10);

: int &p2 = create_sprite(206, 351, 0, 857, 10);

: //stuff here to make them walk and attack

: //now, we want to guard to attack every baddy left on the screen

: sp_target(&guard, &p1);

here:

if (&enemy_sprite == 0)

   {

   sp_target(&guard, &p2);

   return;

   }

wait(1000);

goto here;

}
Ya, thats even easier... <sup>[NT]</sup>
[No message content]
Ya, but it don't work <sup>[NT]</sup>
[No message content]
Re: Ya, but it don't work &nbsp;
//super script by theprophet, lol :)



int &checker;

&guard = create_sprite

&baddy1 = create_sprite

&baddy2 = create_sprite



sp_brain(&guard, 10);

sp_brain(&baddy1, 9);

sp_brain(&baddy2, 9);

//add some info like base_attack and speed

//Ok lets begin the anti-baddy script



sp_hitpoints(&guard, 100);

sp_hitpoints(&baddy1, 100);

sp_hitpoints(&baddy2, 100);



sp_target(&guard, &baddy1);

wait(1);

main:

&checker = sp_hitpoints(&baddy1, -1);

wait(1000);

if (&checker <= 0)

{

goto killbad2;

}

goto main;



killbad2:

sp_target(&guard, &baddy2);

main2:

&checker = sp_hitpoints(&baddy2, -1);

wait(1000);

if (&checker <= 0)

{

goto endid;

}

goto main2;



endid:

say_stop("Those guys were weak!", &guard);



No, it should work...except
You need to assign brain 9 to the attacker in order for that sprite to use sp_target. If those create_sprite commends are in main(), you might put a small time waiting, i.e. wait(100);, to let all sprites be created.
Re: No, it should work...except
Global variables are the rock solid way to refer to sprites created by scripts, and across other scripts. The original Dink had a number of globals that Seth/Pap used in bar room scenes etc. &temphold, &temphold1, &temphold2... I think they were called.



And I've found if you have one script controlling all sprites, if you write your own prodcedures (ie procedures other than hit, die, touch and attack which should be fine) I find that the local script variables aren't recognised by the new procedures. I'm not sure how using gotos impacts on this, other than if the goto sends the script to a customised procedure then the variable ain't recognised.

Re: No, it should work...except
I got it working, but now it seems to crash when it creates the darn sprite. I give up for the day, RedInk has looked at it and can't find the bug anywhere.



--WC
Re: No, it should work...except
: I got it working, but now it seems to crash when it creates the darn sprite. I give up for the day, RedInk has looked at it and can't find the bug anywhere.

: --WC



It crashes when the sprite's created?? Are there already too many sprites on screen? Do you have the sprite say something that is too long (more than the 256 characters?). Is the script file over 32 kb? (hey, it could happen!)

It's probably none of these, but you never know. If RedInk doesn't even know, maybe you should e-mail Seth. Have you looked at the debug log? Of course you have, stupid me.



Anyway, I might try some other script this afternoon and see if it works.