• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

Multiple boolean variables or one integer ?

Status
Not open for further replies.

Ardenian

A

Ardenian

What is recommended, regarding trigger performance and efficiency and considering the Hive spell submission rules,
multiple Boolean variables or one integer variable with keep-in-mind-defined values you would need Boolean in theory.

Example:

Boolean_IsUnit[1] = true
Boolean_IsHero[1] = true
Boolean_IsAlive[1] = true

or
-> CustomInteger[1] = 1

Second example:

Boolean_IsUnit[1] = true
Boolean_IsHero[1] = true
Boolean_IsAlive[1] = false

or
-> CustomInteger[1] = 2

and so on.


Is it completely indifferent or/and does it depend on the use of these variables ?

I would have like over 10 Boolean variables in my system, even with considering that 'false' can be used to replace some Boolean which were 'true' if another one is 'false'.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
If the boolean variables are too many and if the booleans are mutually exclusive I'd say go for the Integer. Even though booleans are executed faster, it will be a pain to make the if-else if all only one of them can be true at a time. You can always put it in a comment what each value mean or better yet, declare each possible value as a constant.
I.e:
constant integer HERO = 1
constant integer NON-HERO = 2
...
Thus, your condition can be:
If type[1] == HERO then
//some stuffs
endif
 

Ardenian

A

Ardenian

I'd say multiple booleans sounds better, that way you allow the users to modify the system and it makes the code a hell lot easier to read.

Thanks, you are right, I haven't thought about this point.

Something related to this, if I save all these Boolean values in a hashtable, 'am I allowed' to save them using integer variables ?

Like:
  • Hashtable - Save Boolean_IsUnit[i] as If Unit of HashInteger
?
Hashtable - Save Boolean_IsUnit as IsUnit of HashInteger

Isunit is an integer variable.
I would like to do it this way, as it allows to easily keep track of the slots the values are saved in and it is easy to modify and use them later.
 
Status
Not open for further replies.
Top