<Disclaimer>
I normally code in GUI for SC2, still need to learn galaxy, however this has limitations.
please take it easy on me if I ask really basic stuff during the course of this thread.
</disclaimer>
I was wondering if it was possible in galaxy script to check the bitflags of a parameter that is a preset.
EX: Check the preset mouse button flag to see if xbutton2 has been checked.
I know that I could make a bunch of if then statements or a switch, but then for a 5 flag preset you end up with 29 statements
I also could use true false checks which is my back up plan if I can't check bitflag states
Just like in other languages, bitflags are implemented using a numeric type (in this case: integer) and using bitwise operators.
Example:
intmouse_bitflag=c_mouseButtonFlagLeft|c_mouseButtonFlagRight|c_mouseButtonFlagXButton2;if(mouse_bitflag&c_mouseButtonFlagXButton2){//XButton2 is pressed}else{//XButton2 is not pressed}
One can also use the byte type if no more than 8 flags are required.
The function returns true if all flags of "Mask" are 1 within "Bitflag".
You can also create a more generic function taking two integer parameters and then use it with "Convert Preset To Integer" to be able to check any bitmask type.
Okay so I created a generic version of the function and it work just fine. Now for my next couple of questions:
1. Why are you so awesome? :P
2. How would I go about creating/inputting a custom script input for a preset value (say for dynamic input while script is running)?
Aha yes, that would be it. How would I go about doing so?
You cant. A bitflag preset is an integer. Strings and integers are completely different types. You would have to contruct the preset manually by using an if then else.
Avoid using strings (especially dynamically created ones) when possible. Due to the nature of strings they will likely perform worse than anything related to integers.
Bitflags should only really be used when space is a consideration or you want a single parameter that controls a variety of behaviour (operations such as checking multiple flags at once). Otherwise for performance and readability booleans should be used.
Bitflags are mostly used in embedded systems programming as a substitute for booleans because of the limited resources available (cannot afford to allocate a word for a single boolean value). Some architectures even include special instructions to get/set individual bits which execute faster than standard masking instructions. In software engineering you often find bitflags in use with bulky data such as the WC3 terrain node structure since the performance lost with masking is made up with more compact information (better cache performance) and the saved memory is substantial (can even be in the order of megabytes).
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
I was wondering if it was possible in galaxy script to check the bitflags of a parameter that is a preset.
EX: Check the preset mouse button flag to see if xbutton2 has been checked.
I know that I could make a bunch of if then statements or a switch, but then for a 5 flag preset you end up with 29 statements
I also could use true false checks which is my back up plan if I can't check bitflag states
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
Just like in other languages, bitflags are implemented using a numeric type (in this case: integer) and using bitwise operators.
Example:
One can also use the byte type if no more than 8 flags are required.
@Mille25: Go
That's an interesting example but what I was wondering if I could check to see is something like this
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
It is possible. Use the following function:
The function returns true if all flags of "Mask" are 1 within "Bitflag".
You can also create a more generic function taking two integer parameters and then use it with "Convert Preset To Integer" to be able to check any bitmask type.
Example usage and output:
Output:
Umm I think I broke it when I added two more preset values for fun to test this more.
Outputs this which is wrong
It should be the 3rd and 5th that are true only
Edit: It works fine only using the 4 preset values that I gave you before, but not with 5 or more Edit2: It work when using less than 4 values too.
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
Aha Figured it out
I had
When I should have had
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
Okay so I created a generic version of the function and it work just fine. Now for my next couple of questions:
1. Why are you so awesome? :P
2. How would I go about creating/inputting a custom script input for a preset value (say for dynamic input while script is running)?
Example usage script:
Is it even possible to use a string to input a custom script?
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
I'm a little bit confused about what you are trying to do.
Are you asking how to convert a string into a bitflag preset?
@Mille25: Go
Aha yes, that would be it. How would I go about doing so?
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
You cant. A bitflag preset is an integer. Strings and integers are completely different types. You would have to contruct the preset manually by using an if then else.
Okay, Thanks for your help
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
Avoid using strings (especially dynamically created ones) when possible. Due to the nature of strings they will likely perform worse than anything related to integers.
Bitflags should only really be used when space is a consideration or you want a single parameter that controls a variety of behaviour (operations such as checking multiple flags at once). Otherwise for performance and readability booleans should be used.
Bitflags are mostly used in embedded systems programming as a substitute for booleans because of the limited resources available (cannot afford to allocate a word for a single boolean value). Some architectures even include special instructions to get/set individual bits which execute faster than standard masking instructions. In software engineering you often find bitflags in use with bulky data such as the WC3 terrain node structure since the performance lost with masking is made up with more compact information (better cache performance) and the saved memory is substantial (can even be in the order of megabytes).