Skip to content

EmuBitfieldOption

Michael edited this page Jun 11, 2020 · 3 revisions

This class represents a specific bit in a bitfield (or an action which may be applied to multiple bits). Most of the time these will be automatically taken care of by the bitfield they belong to, although in some situations you may want to take control.

Note: I recommend having a strong understanding of binary numbers and bit fields ("flags") before manually creating and manipulating Emu's bitfield-related elements.

Constructor

Inheritance: EmuCore / EmuCallback

EmuBitfieldOption(text, value, callback, eval)
Parameter Type Description
text string The text shown to label the option
value real The value contained in the option
callback function The function invoked when the option is toggled
eval function The function that determines whether or not the option is "on"

Notably, EmuBitfieldOptions require a callback and evaluator function. The callback is invoked when the option is clicked on, and the evaluator function is invoked every frame to determine if the option should be drawn as "on" or "off."

Example

var option = new EmuBitfieldOption("None", 0, function() {
        root.value = 0;
        root.callback();
    },
    function() {
        return root.value == 0;
    }
);
bitfield.AddOptions(option);

This will create an EmuBitfieldOption element with a specialized callback and evaluator, and add it to a previously defined EmuBitfield. The callback will set the entire bitfield value to zero, and the evaluator will only return true if the bitfield value is exactly equal to zero.

Helper Functions

There are several helper functions to go with EmuBitfieldOptions, which should cover most situations where you would want to create them manually.

emu_bitfield_option_exact_callback

This may be used in place of a callback. It will set the value of the bitfield to exactly the value of the option rather than toggling it. This can be useful when trying to add an "All" or "None" option to a bitfield.

emu_bitfield_option_exact_eval

This may be used in place of an evaluator function. It will only return true if the value of the bitfield is exactly equal to the value of the option, rather than containing a specific bit. This can be useful when trying to add an "All" or "None" option to a bitfield.