This tutorial will teach you how to use bitwise pre-set types and how to get hundreds of yes/no bit flags out of a single unit custom value (each unit in the game has up to 66 total)...
Put as many values into 'Custom Flags' as you like, you can have hundreds of yes/no flags on your unit per custom value.
If you do not know about unit custom values, check this link before continuing [Triggers - Beginner] Custom Values and Their Use, if you do not know about bitwise logic please Google it, it is a moderately advanced concept...
Next we will create a 'Set' action and 'Get' function to store and load our custom flags onto a unit.
Converting from the pre-set to a real (custom value) is easy (real from (int from pre-set))
Converting from a real (custom value) to your pre-set is NOT easy however.
Galaxy doesn’t like you converting in this direction and tries to protect you against it (Because you can overflow the number of pre-set values. I.E. set value >= (2^(prset of bit values))
To get around this protection either code as a custom script or do the following...
set up your 'get' trigger with your bit flag variable as an int rather than the preset type you want to use.
Once the trigger is ready change the variable from type int to type preset-> (your preset)
GetUmbra'sCustomFlagOptions:FunctionReturnType:Preset->CustomFlagsParameters:InputUnit=(anydefaultwilldo)<Unit>LocalVariables:CustomIndex=5<Integer>CustomValue=0.0<Real>CustomFlags=0<Integer>// Change to <Preset -> Custom Flags> laterActions:Variable-SetCustomValue=(CustomvalueCustomIndexofInputUnit)Variable-CustomFlags=(Integer(CustomValue))
Just a warning... if you now click on '(Custom value CustomIndex of InputUnit)' line can set the input data to any variable you want... INCLUDING dialogs/regions/etc. doing this will break your code, the 'Custom Flags' preset is an INT type so only ever pipe int (or other presets) into it!!!
Now you have an huge large set of bit flags for any unit, you just need to use them... Simple bitwise algebra is fully supported in galaxy (though there are no good built in functions that will do it!)
You are going to have to make your own; here are some logical operators for you to get you started...
&// AND (= valueTwo & valueOne) Only flags true in both valueOne AND valueTwo|// OR (= valueTwo | valueOne) any flags true in valueOne OR valueTwo^// XOR (= valueTwo ^ valueOne) only flags true JUST valueOne OR JUST valueTwo~// 1s Compliment (= ~value) any true flags are false and vica verca<<// Shift Left (= <<value) each flag gets the value of the flag to it's right>>// Shift Right (= >>value) each flag gets the value of the flag to it's left>>>// Unsigned Shift Right (= >>>value) see above, however first value gets a 0
(I have not tested them all, if you have more to add/if some of them don’t work, please let me know!)
Here are three sample functions you can use to play with your new bit values.
CheckRelevantBitsOptions:Condition,OperatorReturnType:BooleanParameters:value<AnyPreset>relevantBits<SameAs>comparison<Preset->AnyComparisonOperator>// Already exists in Built-InCustomScriptCode:// Check whether reference bit flags are true in the given value.(#PARAM(relevantBits)#PARAM(comparison)(#PARAM(value)&#PARAM(relevantBits)))
CompareRelevantBitsOptions:Condition,OperatorReturnType:BooleanParameters:valueOne<AnyPreset>valueTwo<SameAs>relevantBits<SameAs>CustomScriptCode:// If the relevant bit flags in valueOne and valueTwo are the same.((#PARAM(valueOne)&#PARAM(relevantBits))!=(#PARAM(valueTwo)&#PARAM(relevantBits))// There is a bug when inputting 'Bit Flag' presets, if you are wanting to use the// 'value' tab to setup a preset value you will need to set the preset to a variable// rather than filling it in at the function call, otherwise the first flag you select // will not be used.
BitwiseOperation(Binary)Options:Function,OperatorReturnType:IntegerParameters:valueOne<AnyPreset>valueTwo<SameAs>operator<BitwiseBinaryOperators>// Preset you made earlierCustomScriptCode://Returns the two values operated on each other(#PARAM(valueOne)#PARAM(operator)#PARAM(valueTwo))// operator is preset value type custom script, script value is a &(AND) |(OR) ^(XOR)
This tutorial will teach you how to use bitwise pre-set types and how to get hundreds of yes/no bit flags out of a single unit custom value (each unit in the game has up to 66 total)...
Create the two following preset types
Put as many values into 'Custom Flags' as you like, you can have hundreds of yes/no flags on your unit per custom value.
If you do not know about unit custom values, check this link before continuing [Triggers - Beginner] Custom Values and Their Use, if you do not know about bitwise logic please Google it, it is a moderately advanced concept...
Next we will create a 'Set' action and 'Get' function to store and load our custom flags onto a unit.
Converting from the pre-set to a real (custom value) is easy (real from (int from pre-set))
Converting from a real (custom value) to your pre-set is NOT easy however.
Galaxy doesn’t like you converting in this direction and tries to protect you against it (Because you can overflow the number of pre-set values. I.E. set value >= (2^(prset of bit values)) To get around this protection either code as a custom script or do the following...
Just a warning... if you now click on '(Custom value CustomIndex of InputUnit)' line can set the input data to any variable you want... INCLUDING dialogs/regions/etc. doing this will break your code, the 'Custom Flags' preset is an INT type so only ever pipe int (or other presets) into it!!!
Now you have an huge large set of bit flags for any unit, you just need to use them... Simple bitwise algebra is fully supported in galaxy (though there are no good built in functions that will do it!)
You are going to have to make your own; here are some logical operators for you to get you started...
(I have not tested them all, if you have more to add/if some of them don’t work, please let me know!)
Here are three sample functions you can use to play with your new bit values.