The Dink Network

Reply to Re: Returning values from external

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
May 28th, 01:29 AM
custom_robj.png
Robj
Jester Male Australia
You feed the madness, and it feeds on you. 
Sorry for double post, but to keep this separate compared to the "value return" topic. Here's what else I've learned about external.. if you delve a little deeper.

Also, personally, I think it would make sense if external indeed did return an integer value of the script number as well, just like spawn does, because through testing, it is evident that a procedure called by external runs on it's own script number, and you can do some weird and wonderful stuff. That way you could still do the stuff in your first example with pseudo variable &return, but you could also use the &temp = external("script", "procedure"); to save the script number of the procedure being called. But yeh theres work arounds. In regards to how the script numbers are handled..

e.g:
//script exttest.c attached to a sprite on the screen
void main(void)
{
 say_stop("main &current_script", &current_sprite);
 external("test", "thingy");
 
 say_stop("Main again &current_script", &current_sprite);
}


//script test.c
void thingy(void)
{
 say_stop("test &current_script", &current_sprite);
}


Tested on screen with one sprite with exttest.c attached to it: Sprite will say "main 4", "test 5, "main again 4".

------------------------------------

Here's an example of something weird you can do since it runs on its own script number.. Alter where the original script will return to after external completes (Resume operation from a different location in the original script).

e.g:

//script exttest.c attached to a sprite on the screen
void main(void)
{
 external("test", "thingy");

 say_stop("I'll never say this!", 1);
}

void continue(void)
{
 say_stop("This say line will run first!", 1);
 
 //let's run a return to allow remainder of external procedure to finish processing.
 return;
 
 say("This say line will run third!", 1);
}


//script test.c
void thingy(void)
{
 int &crap = is_script_attached(&current_sprite);
 run_script_by_number(&crap, "continue");
 say("This is the second say line that runs!", &current_sprite);
}


I won't write which order the say lines are triggered, I made it obvious in the say lines
But as seen we can call a procedure with external, than retrieve the script number of the current sprite using is_script_attached, poke it to jump to the continue proc, it'll then run until it hits a return or wait, then the external proc will finish, and the original script resumes operation from where it left off in the continue proc instead.