The Dink Network

return;

February 9th 2010, 05:57 AM
sob_scorpy.gif
DinkDude95
Peasant He/Him Australia
The guy with the cute D-Mod. 
What exactly does the 'return;' command do? And where should I use it? I've never quite understood it, and there's nothing in the DinkC Reference about it.
February 9th 2010, 08:50 AM
peasantmb.gif
yeoldetoast
Peasant They/Them Australia
Oh, NOW YOU'VE DONE IT! 
It probably does the same as it does in C which is end your function, and returns control to the calling function, if it is main function, then your program ends. Something like that anyway.
February 9th 2010, 09:00 AM
custom_iplaydink.gif
iplaydink
Peasant He/Him Sweden
Hmm.. 
It leaves the script so any commands after wont be read.
February 9th 2010, 09:10 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
"return;" stops running the script:

void talk( void )
{
  say_stop("The next line has return on it",1);
  return;
  say_stop("I'll never say this line!",1);
}


It is commonly used whenever you use a lot of ifs.

void talk( void )
{
  if (&story == 0)
  {
    say_stop("Oh, my, story is 0!",1);
    return;
  }
  if (&story == 1)
  {
    say_stop("Right now, story is 1!",1);
    say_stop("Let's set it to 2.",1);
    &story = 2;
    return;
  }
  if (&story == 2)
  {
    say_stop("Story is 2!",1);
    return;
  }
  say_stop("Story is not 0, 1, or 2",1);
}


If I hadn't used "return;" everywhere, Dink would have said the last line whenever you talked to whatever this script is attached to. Even worse, when &story is 1, it'd set &story to 2, and it'd immediately say that "Story is 2!" as well. Which is something you often don't want.
February 9th 2010, 09:20 AM
custom_skull.gif
Skull
Peasant He/Him Finland bloop
A Disembodied Sod 
Oh man. The [code] just looks so awesome on Opera.
February 9th 2010, 09:26 AM
custom_iplaydink.gif
iplaydink
Peasant He/Him Sweden
Hmm.. 
Print-screen?
February 9th 2010, 09:53 AM
slimeg.gif
metatarasal
Bard He/Him Netherlands
I object 
That's the traditional use of return;

With Dink v1.08 return can actually return values as well...
February 9th 2010, 10:32 AM
custom_iplaydink.gif
iplaydink
Peasant He/Him Sweden
Hmm.. 
I didn't know. Example?
February 9th 2010, 10:50 AM
slimeg.gif
metatarasal
Bard He/Him Netherlands
I object 
Example:

void talk(void)
{
eight();
int &var = &return;
say("Eight equals &var",&current_sprite);
}

void eight(void)
{
return(8);
}
February 9th 2010, 11:53 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Yeah, and it works with external() too!

Oh, hey, feature request for any maybe future versions of Dink:

Please accept things like "int &var = eight();". It seems like something you'd want to work... In the perfect world, there should be no difference in the usage of self-defined functions and built-in functions.

And while at it, fix "make_global_function", even though I currently don't really know how broken it is.

Enh, I should look into getting the source compiled myself, so I can add these things <_<
February 9th 2010, 11:56 AM
custom_skull.gif
Skull
Peasant He/Him Finland bloop
A Disembodied Sod 
What's this "make_global_function"?

Sorry for my n00bishness.
February 9th 2010, 01:05 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
It's something that's apparently broken (though I don't know how, exactly), but what it *should* do is something like this:

// imagine this to be in main.c somewhere

make_global_function("functions","procname");

// from now on, you can use:
procname();

//instead of:
external("functions","procname");


I haven't experimented with it, but using external is still recommended.

Yeah... I'm being vague >_> <_<
February 10th 2010, 02:19 AM
sob_scorpy.gif
DinkDude95
Peasant He/Him Australia
The guy with the cute D-Mod. 
Thank you to all. I am now much more enlighted. I had a hunch about what return; did, but I wasn't quite sure.

You guys rule.