Author Topic: Global Variables/Flags Possible?  (Read 162 times)

0 Members and 1 Guest are viewing this topic.

Offline MusicallyInspired

Global Variables/Flags Possible?
« 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.
« Last Edit: October 12, 2021, 01:24:31 AM by MusicallyInspired »


Brass Lantern Prop Competition

Offline AGKorson

Re: Global Variables/Flags Possible?
« Reply #1 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:
  • reserved - those used by the AGI engine internally (v0-v26, and f0-f16, f20)
  • global - which were used/accessed/modified across all logic scripts (usually v27-v219 and f21-f219)
  • local - used within a specific room only (usually v220-v239 and f220-f239)
  • dynamic - used within a specific logic script, but not associated with a room (usually v240-v255 and f240-f255)
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.



Offline MusicallyInspired

Re: Global Variables/Flags Possible?
« Reply #2 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?
Brass Lantern Prop Competition

Offline doomlazer

Re: Global Variables/Flags Possible?
« Reply #3 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 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.






Offline AGKorson

Re: Global Variables/Flags Possible?
« Reply #4 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:
  • reserved variable v0 is set to ROOMNUM argument of the new.room command
  • reserved variable v1 is set to previous room number (what was in v0)
  • reserved variable v2 (ego edge code) is set to zero
  • reserved variables v4 (object touching edge) and v5 (object edge code) are set to zero
  • reserved variable v9 (unknown word number) is set to zero
  • reserved variable v16 (ego view number) is set to current ego view number
  • reserved flag f2 (input received) is reset to FALSE (but reserved flag f4 (said found match) is not modified; this appears to be a minor bug, but it usually not an issue)
  • reserved flag f5 (new room) is set to TRUE
  • if a sound is playing, it is stopped and the 'done' flag is set to TRUE

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).





SMF 2.0.14 | SMF © 2017, Simple Machines
Simple Audio Video Embedder

Page created in 0.149 seconds with 24 queries.