The Dink Network

Re: Spawn and external!

January 19th 2014, 06:41 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
Gah, I want to spawn a script with a loop in it, getting a variable from the main script that is attached to a sprite without halting the main script. Word.

External() apparently halts the main script until kill_this_task() or something is run from the external script.

I want to pass a variable to the spawned script from the main script. Like this here external:

void main (void)
{
int &sx = sp_x(&current_sprite, -1);
int &sy = sp_y(&current_sprite, -1);
external("rloop", "main", &sx, &sy); //&sx = &arg1, &sy = arg2

...rest of script...
}

But the loop in rloop halts the main script so I want to liiiiikeee:

spawn("rloop", "main", &sx, &sy); //&sx = &arg1, &sy = arg2

Maybe I'm too tired. My guess is taking advantage of script_attach or something since that's what spawn is using.
January 19th 2014, 06:53 PM
wizardg.gif
You could do something really weird and ridiculous instead.
create a sprite
set useless variable such as sp_gold to the vars you want remembered(&sx, &sy).
use sp_script in place of external/spawn.

And *ta-da* problem solved.
January 19th 2014, 10:13 PM
custom_coco.gif
Cocomonkey
Bard He/Him United States
Please Cindy, say the whole name each time. 
You could use spawn to do something like this, but spawn doesn't have the same arguments external does.

I usually just set some global juggle variables to whatever I want the spawned script to use. Leprochaun's sp_script solution might be better.
January 20th 2014, 05:54 AM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
So there's no easier way huh.
January 20th 2014, 06:34 AM
wizardb.gif
Kyle
Peasant He/Him Belgium
 
Sure there's some ways to do this. The easiest one is to use a global variable, one that you reserved for scripting tricks such as this. If you make use of the variable (set it to a local in the spawned script) without a wait() in between you'll never run into issues with it.

The other way is writing the data to a sprite on screen and retrieving it from that, for example in its sp_gold() or editor_seq. You could use a sp(5) or whatever to target it, as long as there are 5 sprites on the screen. I wouldn't use this method, but it's functional.

I also like Leprochaun's solution, it would work fine. If you could, try it with the globals though, it's much more reliable and doesn't count on sprites to do their job.
January 20th 2014, 12:45 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
To global or not to global, that is the question.