Community

AGI Programming => AGI Syntax Help => Topic started by: MusicallyInspired on October 12, 2021, 01:21:01 AM

Title: Global Variables/Flags Possible?
Post by: MusicallyInspired on October 12, 2021, 01:21:01 AM
I've tried setting variables and flags but they don't persist between rooms. I even tried setting them in LOGIC 0 but that doesn't do anything different. Is this even possible? I mean, it's gotta be right? Is there some special way to define them maybe? I can't find any information on this anywhere. I'm trying to reference games but it's not entirely clear. They're setting flags and variables all over the place and checking them in different rooms and it seems to work fine there...I don't know what I'm doing wrong.
Title: Re: Global Variables/Flags Possible?
Post by: AGKorson on October 12, 2021, 11:07:17 AM
Most AGI games (especially fan games that use the common templates) have a logic that runs with each new room call that resets/clears a range of flags and variables- usually from 220 -255. If you want a variable/flag to persist across rooms, don't use one from that block. Or modify/get rid of the reset script.

A bit of history - original source code from Sierra reveals that they treated flags and variables as one of four scopes:
Keep in mind that in fact there is only one scope for all flags and variables in AGI- that's 'global', i.e. all variables and flags are visible to all logic scripts and the game engine at all times. The scopes described above are an entirely artificial construct used by Sierra (and fanmade) game programmers to make it easier to manage them. Which is why they needed to include a script to reset/clear them every time a new room was encountered.


Title: Re: Global Variables/Flags Possible?
Post by: MusicallyInspired on October 12, 2021, 07:46:47 PM
So flags/variables are natively global unless a logic script is made to clear them? This is interesting because the flags and variables were numbered 40. And they still got wiped. I should also mention this is for a highly modified SQ2 base game. Maybe it works differently in that regard for that game and it wipes different ranges of variables/flags. I'll have to dig more into this. Which Logic script is it in the template game that does this?
Title: Re: Global Variables/Flags Possible?
Post by: doomlazer on October 12, 2021, 08:17:46 PM
This is interesting because the flags and variables were numbered 40. And they still got wiped.

I'm still learning, so take this with a grain of salt: f40 looks like it's used by SQ2 for Sound()'s fDONE (http://agiwiki.sierrahelp.com/index.php?title=Sound) flag. So even though it's not wiping the flags in the 40-50 range on room change, the game might be changing your flags for different reasons.





Title: Re: Global Variables/Flags Possible?
Post by: AGKorson on October 12, 2021, 10:43:15 PM
Good catch. When a new.room command is encountered, any sound that is playing is stopped, which will reset the flag associated with the sound. When a sound is stopped for ANY reason, its flag is reset. If no sound is playing, no flag would get reset.

The complete list of affected flags and variables when a new.room command is executed are:

Any other changes that you see are because there's a specific line of code somewhere in your logics that's doing the change.

In the template games, the reset logic is usually logic #92 (lgc.RoomInit).