The Dink Network

Reply to Re: Custom procedures, return, script_used() etc.

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:
 
 
January 26th 2008, 07:35 PM
fairy.gif
Someone
Peasant He/Him Australia
 
I'm not sure, but I'm led to believe 1.08 modified local function calls to act like external(). It does make a difference because local variables can't be accessed, &current_sprite may not work as desired, and there if you were to have a function call itself you may run out of script numbers. It might be possible to call a function locally using set_callback_random, but I haven't tried it.

I'm not sure what you mean by "exit the script". Does it not exit the script when it exits the procedure? Exit does not mean kill. Unless you mean return is causing it to exit a locally called function and return to the calling function. But as you've found they are on different script numbers even if it's called "locally"..

Functions that take variables are very useful. Of course the same effect could be done with global variables in v1.07 but arguments make it easier. It's useful for when you want to do multiple things that are almost identical.

E.g. if you wanted to make 3 bombs, but in different positions.

//bomb.c
void make_bomb(void)
{
create_sprite(&arg1,&arg2,17,?,1);
//sp_strength etc
}

then call
external("bomb","make_bomb",100,200);
external("bomb","make_bomb",300,200);
external("bomb","make_bomb",500,200);

MouseDink uses functions with arguments if you still doubt how useful it is. See the globalX.c files. For example I have code to determine which direction (out of the standard 8 directions) one sprite is relative to another. You can imagine that whenever I want to find this the code is identical except for the sprite numbers for the two sprites, so I can pass them in an argument and use the same code for any use. I also used it determine the gradient of the line between two sprites, as well as to calculate hit damages..

Another use is to pass an indicator of the calling script (sender). E.g. in MouseDink I've got a function that I want to be run slightly different if it's called when the player first starts the game and when he loads a new game. So I sent a 0 for new game and 1 for load game (or something like that) and I can have the code execute slightly differently depending on what script calls it.