Core Function SetFlag
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> SetFlag( <enumInst>, <flag/flags>, <state> ) </pre> === Description === Enable or Disable a flag (or array of flags) in a given enum instance. === Parameters === ==== ...") |
(→Remarks) |
||
(3 intermediate revisions by one user not shown) | |||
Line 31: | Line 31: | ||
=== Return Value === | === Return Value === | ||
− | + | Returns the current value of the enumInst (a copy of it) | |
− | + | ||
− | + | ||
=== Remarks === | === Remarks === | ||
This is just an easier way to do bit flags. | This is just an easier way to do bit flags. | ||
+ | |||
+ | This will not set a flag to a value it is already set to for example if you try enable a flag that's already enabled it will ignore the request (same goes for disabling a flag) this will ensure your enumInst doesn't get incorrect values even if you spam it. | ||
+ | |||
+ | This modifies the original enumInst and it's return value can be ignored. | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | // Since SetFlag modifies the enumInst directly | ||
+ | // it can be used stand alone like this: | ||
+ | SetFlag($enumInst, $OPT_H, true); // modifies $enumInst on the spot | ||
+ | // This keeps your code cleaner since you do not | ||
+ | // need to do this: | ||
+ | $enumInst = SetFlag($enumInst, $OPT_H, true); | ||
+ | // since that would be rather pointless | ||
+ | </syntaxhighlight> | ||
=== Example === | === Example === |
Latest revision as of 07:53, 15 September 2015
SetFlag( <enumInst>, <flag/flags>, <state> )
Contents |
Description
Enable or Disable a flag (or array of flags) in a given enum instance.
Parameters
enumInst
Instance of an enum (or any integer will do)
flag
Either:
An enum flag (or any integer)
OR
An array of enum flags.
state
Optional; The state to set the flag to should be a boolean of true or false.
Default: true
Return Value
Returns the current value of the enumInst (a copy of it)
Remarks
This is just an easier way to do bit flags.
This will not set a flag to a value it is already set to for example if you try enable a flag that's already enabled it will ignore the request (same goes for disabling a flag) this will ensure your enumInst doesn't get incorrect values even if you spam it.
This modifies the original enumInst and it's return value can be ignored.
// Since SetFlag modifies the enumInst directly // it can be used stand alone like this: SetFlag($enumInst, $OPT_H, true); // modifies $enumInst on the spot // This keeps your code cleaner since you do not // need to do this: $enumInst = SetFlag($enumInst, $OPT_H, true); // since that would be rather pointless
Example
See HasFlag( ) for examples.