Flags
francisstokes
12 Jun 2005, 19:25Ive looked in the quest help but i still don't understand what flags do.
felicroman
13 Jun 2005, 02:10As far as I can tell a flag is a simple binary on/off function that can be attached to a room or object for any purpose.
MaDbRiT
13 Jun 2005, 08:33Francis wrote
They don't really 'do' anything, they are just provided for your convenience when writing code.
An example might help explain that.
Assume that in a game the player has to get a camera, a roll of film and some batteries and then put the film and batteries in the camera before he can take pictures...
To have a nice convenient way to check later that he's ready to shoot pictures, as the player puts batteries in the camera you might check if the camera already has film (and vice-versa of course) and if so set a flag called 'Camera _Ready'...
Now when the player types 'take picture' rather than have to check the player has the camera AND the camera has film in it AND the camera has batteries in it - you just have to check the 'Camera_Ready' flag.
Neater and more convenient.
So, flags are just there to provide a handy way to keep track of things happening in the game, you use them for whatever you want. FWIW you can use a simple numeric variable to do this equally well, but flags are a little more elegant for storing information for tests that require a simple 'yes/no (a.k.a. 'true/false') result.
Further example:
You might additionally use a variable called "shots_left" to store (in the scenario above) how many shots are left on the roll of film. This information isn't the sort of thing a flag would be able to directly hold.
However when the 'shots_left' variable hits 0 you can turn off the "Camera_Ready" flag - so now the one test of the flag 'Camera_Ready' will (if it is true/yes) mean:
a: the camera has batteries
b: the camera has film in it
c: the film isn't used up.
Hopefully the above demonstrates the purpose and utility of flags. If it would help I can build an example showing the above fairly quickly, just ask.
Al (MaDbRiT)
Ive looked in the quest help but i still don't understand what flags do.
They don't really 'do' anything, they are just provided for your convenience when writing code.
An example might help explain that.

Assume that in a game the player has to get a camera, a roll of film and some batteries and then put the film and batteries in the camera before he can take pictures...
To have a nice convenient way to check later that he's ready to shoot pictures, as the player puts batteries in the camera you might check if the camera already has film (and vice-versa of course) and if so set a flag called 'Camera _Ready'...
Now when the player types 'take picture' rather than have to check the player has the camera AND the camera has film in it AND the camera has batteries in it - you just have to check the 'Camera_Ready' flag.
Neater and more convenient.

So, flags are just there to provide a handy way to keep track of things happening in the game, you use them for whatever you want. FWIW you can use a simple numeric variable to do this equally well, but flags are a little more elegant for storing information for tests that require a simple 'yes/no (a.k.a. 'true/false') result.
Further example:
You might additionally use a variable called "shots_left" to store (in the scenario above) how many shots are left on the roll of film. This information isn't the sort of thing a flag would be able to directly hold.
However when the 'shots_left' variable hits 0 you can turn off the "Camera_Ready" flag - so now the one test of the flag 'Camera_Ready' will (if it is true/yes) mean:
a: the camera has batteries
b: the camera has film in it
c: the film isn't used up.
Hopefully the above demonstrates the purpose and utility of flags. If it would help I can build an example showing the above fairly quickly, just ask.
Al (MaDbRiT)
Elexxorine
13 Jun 2005, 10:09how do you actually use flags? can some-one just post a bit of code to show them, thanks....
MaDbRiT
13 Jun 2005, 10:55Hi Elexxorine
Here's a very simple 'flag' usage - based loosely on the camera, film, batteries scenario I used above...
In this example I've used the afterturn to set/unset a flag called "camera_ready" according to whether the player has all three required items or not.
The "take photo" command therefore tests just the 'camera_ready' flag rather than having to test the player has all the items individually.
O.K.?
Al (MaDbRiT)
Here's a very simple 'flag' usage - based loosely on the camera, film, batteries scenario I used above...
' "Film.asl"
'
define game <test>
asl-version <350>
gametype singleplayer
start <hall>
game author <MaDbRiT>
game info <Created with QDK 3.53.>
command <take photo> {
if flag <camera_ready> then {
msg <You press the big silver button... nice shot!>
conceal <batteries>
conceal <film>
}
else msg <You don't have a working camera.>
}
afterturn {
if got <camera> and got <film> and got <batteries> then {
flag on <camera_ready>
}
else flag off <camera_ready>
}
end define
define synonyms
end define
define room <hall>
prefix <the>
define object <camera>
take
end define
define object <film>
take
prefix <a roll of >
end define
define object <batteries>
article <them>
take
end define
end define
define text <intro>
end define
define text <win>
end define
define text <lose>
end define
In this example I've used the afterturn to set/unset a flag called "camera_ready" according to whether the player has all three required items or not.
The "take photo" command therefore tests just the 'camera_ready' flag rather than having to test the player has all the items individually.
O.K.?
Al (MaDbRiT)
Elexxorine
13 Jun 2005, 12:14thanks
francisstokes
14 Jun 2005, 12:17Thats exactly what i thought they were:!:
Thats something that i wish i had known about sooner, though.Comparing about a million variables over and over was annoying.I knew there must have been an easier way.
Thats something that i wish i had known about sooner, though.Comparing about a million variables over and over was annoying.I knew there must have been an easier way.
