Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: SilverSpook on Tue 10/11/2015 06:33:50

Title: Best Place To Put Game Flags?
Post by: SilverSpook on Tue 10/11/2015 06:33:50
Hi, I have been wondering where the best place to put game-logic related booleans is.  For example things like "GotBottle", "FinishedMissionX", "TalkedToY".  I've been trying to keep things self-contained in rooms if possible but sometimes if it involves a conversation with a character that might not be possible. 

Do you guys usually just use global variables for those types of things, or is there some other way to handle these sorts of things?  Thanks.
Title: Re: Best Place To Put Game Flags?
Post by: Gurok on Tue 10/11/2015 06:48:00
In the Jimi Hendrix Case, I had a module for it. It's probably overkill. I think most people use plain global booleans.

Flag.ash

enum FlagType
{
fCoronerWantsEvidence,
fSearchedFishmonger,
fComparedFishCrate,
fSearchedFishStall,
fFoundBloodTrailEnd,
fBossChewedOut,
fTriedCode,
fReserved1,
fReserved2,
fReserved3
};

#define Flag_COUNT  10

struct Flag
{
import static void Set(FlagType name, bool state = true);
import static bool Get(FlagType name);
};


Flag.asc

bool Flag_Value[Flag_COUNT];

static void Flag::Set(FlagType name, bool state)
{
Flag_Value[name - 1] = state;

return;
}

static bool Flag::Get(FlagType name)
{
return(Flag_Value[name - 1]);
}


Usage:
Flag.Set(fCoronerWantsEvidence);
if(Flag.Get(fCoronerWantsEvidence)) ...

My module approach has some *debatable* advantages:
- You don't have to set up exports for each new variable (the global variables pane does this, so I guess you could just use that)
- It's better encapsulated (you can track getting/setting the values)
- It's kind of namespaced. When you call Flag.Get or Flag.Set, only the valid flag names are shown (which helps me)

ALL of these are debatable, because it's really just my personal preference. I would say most (sane) people would just prefix their global booleans to get the same namespacing effect.
Title: Re: Best Place To Put Game Flags?
Post by: SilverSpook on Tue 10/11/2015 07:24:43
Hm, thanks for the input Gurok.  Perhaps I'll think about the prefixing of globals.