The Wonderful World of Flags!
Displaying 1-20 of 22 total.
12 next
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Zip

Right, more fun redundant code from the master of timewasting.

Flag Handling Beta

In Sully:
int grueFlags[1000];

In Parallel 7:
#define maxflags 	1000

int flag[maxflags];

In Duskbane:
int flags[100];

In Milk:
int nFlags[100];
Basically, all this redundant data, for what is pretty much just a bool, was offending my sensibilities. So I wrote some bitwise flag handling. Now you can have 1000 flags for the price of 32, and 100 for the price of 4. (Yes, I know a few ints aren't really that important... but I CARE)

So, you don't set a value anymore (and flags are bool only - use multiples for more complex situations), but there are four simple functions to deal with them, for each you pass a flag number:
int FlagLook(int flgl_num) // Returns 1 if the flag is on, 0 for off

void FlagSet(int flgs_num) // Sets a flag to true
void FlagClear(int flgc_num) // Sets a flag to false
void FlagToggle(int flgt_num) // Toggles the value of a flag
I'd recommend having a big list of flag defines, with the name explaining the situation of each flag, so you don't forget what each number does.

Zip

Posted on 2004-08-09 19:46:27

andy

The RAM you are "wasting" by using a whole int to store a boolean value is worth significantly less than a roll of toilet paper. ;)

Posted on 2004-08-10 03:17:24

Zip

Man, you're (as in 'you are', rather than the possesive 'your', or the noun 'yore', or the film 'Yor') talking to the guy who made a define for minus one here. The brain knows, but the heart don't care.

Zip

Posted on 2004-08-10 03:29:14

andy

Programming as a form of mental masturbation is nothing new. Have fun!

Just be sure that you can distinguish the masturbatory aspect from the utilitarian. ;)

Posted on 2004-08-10 05:28:44

geronimo

or don't: weeee!

Posted on 2004-08-10 06:18:40

resident

I have a suggestion - given that flags are so commonly used, wouldn't it be an useful to create a standard method of dealing with them as part of Verge itself? Especially if, for example, you could create an entity like system, where you can create - but not delete - flags on the fly?

like: CreateFlag("Got Milk?");

Maybe not. Just seems like it'd be handy to me - if a lot of effort for something which is fairly readibly accomplishable at the moment.

Posted on 2004-08-10 08:08:51

mcgrue

Way back in the day I also thought this would be a good idea. Like the v2 day. I forget why I never created a flag system based on string handles.

I, or anyone really, could probably whip up a functional system with a fair modicum of foolproofing to avoid some potentially clumsy situations involving misspelling ;)

Posted on 2004-08-10 15:28:00

resident

Quote:Originally posted by mcgrue

I forget why I never created a flag system based on string handles.

You couldn't be bothered?

It would certainly by my excuse of choice for not actually ever accomplishing much :D

Posted on 2004-08-10 16:04:36 (last edited on 2004-08-10 16:05:09)

Zip

Using numbers and a list of flag defines is preferable in my book, as any errors the compiler will spit at you, rather than just doing funky shit in game.
#define FLAG_REACHED_4LVL 22


if (FlagLook(FLAG_REACHED_LVL4)) ... // Compiler spits
However:
FlagSet("Reached level 4");

...
FlagLook("Reached 4th level"); // Always returns false in game

Add spelling errors, case sensitivity and the rest, I see a world of pain if the number of flags gets large. Plus the fact that the set/check would be far more complicated, and probably require a tree.
With this system, you can just have one header file with all your flags neatly listed, and it's just as clear what the flag does.

Zip

Posted on 2004-08-10 16:42:28

Gayo

I thought about doing something like this once, but Grue yells at me every time I try to save memory. In this case I'm not entirely convinced it's the best way to handle things, simply because I really like to have plot flags with more than two states sometimes.

Posted on 2004-08-10 20:18:40

Zip

Yeah, but I'm used for mockery for doing silly things. I did thoing about the multiple state thing, but decided the how point of a flag was you can do a basic true/false query on it. Anything requiring multiple states should have extra flags instead:
#define FLAG_DAVE_MET 56

#define FLAG_DAVE_JOIN 57
#define FLAG_DAVE_LEFT 58
Or something...

Zip

Posted on 2004-08-10 20:38:40

andy

Strings are much better than #defines: A dump of such a flag list is a bunch of strings, which is MUCH easier for a human to parse.

Also, this means that no work has to be done anywhere if you want to add another flag. Just set the thing and you're done.

Human resources are far and away more valuable than machine resources. ;)

Posted on 2004-08-11 03:27:49 (last edited on 2004-08-11 03:28:28)

Zip

Rights for machines! They have feelings too! Anyway, I disagree, the debug of string would easily lose any time you gained by not typing a few defines. A bool is a bool, making it a string just causes all sorts of complications you shouldn't have to face. Sure, a nice text dump would be a bonus, but far from a clinching feature. Feel free to write one if you want though - I'm bored of defending such a chuck-away project.

Zip

Posted on 2004-08-11 04:06:05

resident

Quote:Originally posted by Zip

Using numbers and a list of flag defines is preferable in my book, as any errors the compiler will spit at you, rather than just doing funky shit in game.
#define FLAG_REACHED_4LVL 22


if (FlagLook(FLAG_REACHED_LVL4)) ... // Compiler spits
However:
FlagSet("Reached level 4");

...
FlagLook("Reached 4th level"); // Always returns false in game

Add spelling errors, case sensitivity and the rest, I see a world of pain if the number of flags gets large. Plus the fact that the set/check would be far more complicated, and probably require a tree.
With this system, you can just have one header file with all your flags neatly listed, and it's just as clear what the flag does.

Zip

Meh, you could trap that pretty easily at startup - just check to see if there are any flags checked that have never been defined. Anything that's never been defined is probably an error, and should be reported.

Posted on 2004-08-11 10:07:33

mcgrue

Quote:Originally posted by resident


Meh, you could trap that pretty easily at startup - just check to see if there are any flags checked that have never been defined. Anything that's never been defined is probably an error, and should be reported.


Yes, that'd be about the long and short of it.

Posted on 2004-08-11 14:35:08

Mythril

Quote:Originally posted by resident
Meh, you could trap that pretty easily at startup - just check to see if there are any flags checked that have never been defined. Anything that's never been defined is probably an error, and should be reported.

But wouldn't that only give an error when the checking function actually run? Since you probably can't make your function give errors on compile when it's handling strings?

(Although you're of course supposed to bugtest every part of your code...)

Posted on 2004-08-11 15:15:16

Interference22

Cue the debate on exactly when you should stop optimising your code and how convenient a game should be to make.

Bitshifting and whatnot is all good and well but NOTHING beats the convenience of "flag[22] = 1;". I mean, it's less than ten LETTERS for chrissake, plus easy to remember and a DODDLE to check for errors. Zip, there is such a thing as trying too hard, dude!

Posted on 2004-08-11 23:29:00

Ness

Zip...that code actually scared me.....so many bitshifts and modulus just for a bunch of booleans?

Posted on 2004-08-12 01:23:46

andy

Human resources are much more valuable than machine resources. :)

If the computer has to do more work, so be it. Easy way, all the way.

Posted on 2004-08-12 03:10:20

resident

Quote:Originally posted by Mythril

Quote:Originally posted by resident
Meh, you could trap that pretty easily at startup - just check to see if there are any flags checked that have never been defined. Anything that's never been defined is probably an error, and should be reported.

But wouldn't that only give an error when the checking function actually run? Since you probably can't make your function give errors on compile when it's handling strings?

(Although you're of course supposed to bugtest every part of your code...)

It'd probably have to be done as part of the compile process.

Posted on 2004-08-12 14:33:13


Displaying 1-20 of 22 total.
12 next
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.