The Dink Network

Reply to Returning values from external

If you don't have an account, just leave the password field blank.
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
May 27th 2020, 09:50 PM
You can return values when calling a function in another script using external.
It's 2am but I feel this is amazing and should be shared! Immediately!

For some reason this only appears to work when using &return.

// Script test.c
external("test2", "thingy");
say_stop("&return", 1);
external("test2", "thingy", 1);
say_stop("&return", 1);
external("test2", "thingy", 7);
say_stop("&return", 1);

// Script test2.c
void thingy (void)
  int &t;
  &t = 123;
  &t += &arg1;

Dink will say, as expected, "123", "124", "130".

If you assign to a variable as usual, it won't work:
// Script test.c
int &temp;
&temp = external("test2", "thingy");
say_stop("&temp", 1);
&temp = external("test2", "thingy", 1);
say_stop("&temp", 1);
&temp = external("test2", "thingy", 7);
say_stop("&temp", 1);
say_stop("wut", 1);

Weird things will happen: Dink will say "wut" and nothing else. The script execution seems to skip to the line after all these external() calls and then continue. Why the say_stop's in between don't happen I have no idea.

Tested in 1.08, Freedink 109.6 and Dink HD.
I am way too excited about this (probably because it's 2am... I mean 2.45...)