Complex Bitflags

17 de julho de 2011

Tutorial feito em inglês por QHeretic que é muito útil para economizar tempo e linhas de configuração com variáveis no RPG Maker 2000 através do uso de bitflags. O autor fala que é especialmente interessante no caso de Custom Meny Systems (menus customizados para este maker) mas existem outras possibilidades. Provavelmente pode ser adaptado para o RPG Maker 2003 também.

Been a while since I posted a new tip, but it just recently dawned on me that the use of bitflags could save using hundreds of seperate configuration variables, for, lets say a custom menu system (CMS).

This tip is especially for you custom menu designers, however, and can cram a whole load of configuration options into one variable, as opposed to using 10-20 for very trivial things. If you are familiar with how a bitflag works, you’ll better understand this tip then. However, if you don’t, the system works based on an exponential increasing rate, starting with 2. Lets say you take 2, then the next exponential 4, then 8, then 16, and so forth. These are your ‘flags’ within a variable.

Now lets say we have 5 options to choose from on your menu. All of which are either ON or OFF choices (who knows, lets say things like…)

1. Complicated Spell Effects [ON OFF] (2)
2. Enemy Animations [ON OFF] (4)
3. Short Summons [ON OFF] (8)
4. Help [ON OFF] (16)
5. Music [ON OFF] (32)

Each option on the config menu has a ‘bitflag’ value, and they are represented as an increasing exponential value. Now lets say we turn 2 and 5 ON, thats 4 and 32…add them then together and get 36. Your config variable would now be 36.

Now…later on in the game when you need RM2k to read this config bitflag, you do the opposite of what you did to create it, subtract, starting with the highest value, (in this case it is 32). If it is less than the TOTAL of the bitflag then activate that option, so this would turn music ON as it read off the bitflag, and subtract 32 from it, leaving 4. Next we try to subtract 16 from whats left but get a negative number, so this option stays in the OFF position, next we try 8, but the same deal happens so that also stays off. We try 4 now, and option two can now be turned ON. Finally, we try 2, but with 0 left, it also leaves a negative.

All it involves is addition and subtraction. Now you can use multiple option bitflags and have each option after the 2nd equal the next exponential value instead of having a TRUE/FALSE option.

1. Option #1 [Custom Default Auto]
2. Option #2 [Custom Default Auto]
3. Option #3 [Custom Default Auto]

Default generally would be the 0 value for each choice, and would not add to the flag at all. Now going from left to right, top to bottom, we insert the values. For the first lets choose Custom, 2nd choose Default, and 3rd choose Auto.

Custom [2]+ Default [0]+ Auto [64] = 66
2+0+64 = 66

And the configuration would be read off the bitflag later for whatever purpose this serves. Generally use a 2nd variable as the constant checker, and have it start out at an extreme value within the possible line, like lets say ‘262144’, and increasingly divide it by 2, then check to see whether it makes a negative when subtracted from the current bitflag value.

It’s not as complicated as it sounds, and it will save a lot of time and space, not just for menus, but it can also be used for several other things. Equipment, lists, battle arrays and complex combo-based combat, the possibilities are endless!

Observação: se você gostou deste post ou ele lhe foi útil de alguma forma, por favor considere apoiar financeiramente a Gaming Room. Fico feliz só de ajudar, mas a contribuição do visitante é muito importante para que este site continua existindo e para que eu possa continuar provendo este tipo de conteúdo e melhorar cada vez mais. Clique aqui e saiba como. Obrigado!

Um comentário para “Complex Bitflags”

  1. Ryei disse:

    Muito bom o HUD, o DouglasEagle está de parabéns.

Deixe um comentário

Inscreva-se na nossa newsletter!