The Dink Network

kill_this_task but from external

April 8th 2018, 08:47 PM
duckdie.gif
crypto
Peasant They/Them
 
script A is a global running script. with no kill [always running]..

Script B is a key P

if i use external can i kill script A VIA P by calling a function that is not used for script A, such as use in the example below ... ask if having issue understanding what i mean ... not sure i captured it quite right

in script B
external("A", "use")

script A

void main(void)
{
top:
some stuff
goto top
}

void use(void)
{
kill_this_task();
}

thinks or can you pass the script name to kill_this_task()?
April 8th 2018, 09:29 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
external() calls a method in another script file, but it won't affect any other script 'instances' that are running using the same script file.

This means, that in your example, script B will end up killing itself.

This is a little bit odd, but it makes sense when you think of other scenarios:

1) What if no instances of the 'A' script are running? Would 'B' fail to call external?
2) What if multiple instances of the 'A' script are running?
3) What if a global running script 'C' is running, that is running a loop in the 'A' script'?

The answer to every question is the same: external doesn't affect other scripts, so external works every time.

You can do what you want, but it is a little tricky. You need to identify the 'script number' of your global running script (probably using a global variable), then you can call methods on the script associated with the 'script number'.

For example:
//Script that starts Script A
void main(void)
{
&globalscript = spawn("A");
}

//Script B
run_script_by_number(&globalscript, "use");
Of course, if you're going through the trouble of using a global variable, you could just add a condition to your main loop to exit, and that would be easier than tracking the script number.

If you really really need to conserve global variables (and you shouldn't need to; heck I made a roguelikelike in DinkC and only used like 60 variables at any given time), script B could simply loop through all script numbers and try to kill the global script, but you'd want to name the function something unique:
//Script A
void main(void)
{
top:
some stuff
goto top
}
void secret_global_use(void)
{
kill_this_task();
}

//Script B
int &temp = 1;
loop:
run_script_by_number(&temp, "secret_global_use");
&temp += 1;
if (&temp < 300 ) goto loop;
April 8th 2018, 10:46 PM
duckdie.gif
crypto
Peasant They/Them
 
ok, i follow .... maybe need a bit of reworking else where in my scripts, it's why i asked before things got to crazy to fix easily

what you say here makes sense really ..

the good news is i am already using a few global's for this .... so i may just have a if test instead that can kill the script, and set the kill with the global by pressing the p key ... i know what i'm saying . and i think you mentioned this in different words as well .... reading it over again ...

this was very useful

Thanks

And actually, if this is seen .... is there a way to poll how many vars are currently in use ? during game play ? I know you can use say if you want to put all your vars into the say command.. however when things get bigger that may not be a good option anymore ..
April 10th 2018, 12:31 AM
peasantm.gif
shevek
Peasant They/Them Netherlands
Never be afraid to ask, but don't demand an answer 
And actually, if this is seen .... is there a way to poll how many vars are currently in use ? during game play ? I know you can use say if you want to put all your vars into the say command.. however when things get bigger that may not be a good option anymore ..

I'm not sure about how to do that, but apparently you do, so that's good. What I can add is that you can debug() anything you can say(). That will send it to standard output (or perhaps standard error; I haven't checked) on GNU/Linux systems, which is the terminal from which you started it (or whatever place you redirected it). In my experience this is a good place for large amounts of text. You can also copy it into a text editor, of course.

In case you don't currently start dink from the commandline, you should go to the dmod directory and use:
freedink -g . -w
This will start the dmod in the current directory (".") in a window. See freedink --help for a full list of options.