The Dink Network

Reply to Re: Variable scope and set_callback_random()

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:
 
 
February 14th, 10:46 PM
custom_simon.gif
SimonK
Peasant He/Him Australia
 
Hmmm, I tried that example of code and maybe something has changed between Dink 1.08 and DinkHD, as if I assign that code to a key script, I get Dink saying

&x, &y

then

4, 6

rather than the "4, 8" and then "2, 6" mentioned

========================

This was what Redink1 posted about 1.08 and scope

* Variables are now dynamicly scoped.

It basically allows you to reference local variables defined in previous functions, so you wouldn't have to resort to global variables like &save_x and &save_y (most of the time).

You can do something like this:

void main(void)
{
int &x = 4;
int &y = 6;
bob();
say_stop("&x, &y", 1);
}

void bob()
{
int &y = 8;
function();
}

void function(void)
{
say_stop("&x, &y", 1);
&x / 2;
}

This would result in Dink saying "4, 8" and then "2, 6".