The Dink Network

Reply to Re: Global variables

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:
 
 
July 25th 2004, 12:23 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
Coming from a C background, I'm sure you're going to hate DinkC. As you are limited to only ~230 active variables at one time (including globals and all currently used locals attached to scripts), its generally a good idea to use editor_seq and editor_frame when dealing with a sprite remembering something.

//Bookshelf
void main(void)
{
int &hold = sp_editor_num(&current_sprite);
int &myvar = editor_seq(&hold, -1);
}

void talk(void)
{
if (&myvar == 0)
{
say("I found the Magic Thing of Thingy!", 1);
add_item("item-fst", 438, 1);
&myvar = 1;
}
else
{
say_stop("I already got the thing.", 1);
}
editor_seq(&hold, &myvar);
}

You can do this with every sprite, as each sprite has a limited memory of a sequence and frame that you can store and retrieve arbitrary values from. Retrieving that value from another sprite (on another screen) is a bit more tricky, so for this instances global variables are recommended.