Reply to Re: Global variables
If you don't have an account, just leave the password field blank.
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(¤t_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.
//Bookshelf
void main(void)
{
int &hold = sp_editor_num(¤t_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.