Structs Evaluation - harpwood/Easy-Virtual-Joystick-for-GameMaker-LTS-2022 GitHub Wiki

You have the option to let the script evaluate the provided configuration and skin structs in the virtual_joystick constructor. The evaluation setting can be found in the virtual_joystick_example_structs() function.

// Strict evaluation settings:
// By default, strict evaluation is enabled for both the 'config' and 'skin' arguments. 
// This is recommended, as it helps ensure that the input parameters meet the expected data types and formats.
global.strict_evaluation = {config : true, skin : true};

By default, strict evaluation is enabled for both the 'config' and 'skin' arguments. This is recommended, as it helps ensure that the input parameters meet the expected data types and formats. If the global.strict_evaluation variable is not already declared, it will be created with both evaluations enabled.

Configuration struct evaluation

The configuration struct evaluation is an important part of the virtual joystick script. If the strict evaluation is not enabled for the configuration struct, the script will only inspect the parameters of the struct. If any parameter is missing, it will be added with the default values. However, if strict evaluation is enabled, each parameter value will be also inspected using the built-in GameMaker function typeof to ensure that each parameter stores the correct data type. If a parameter has an incorrect data type, a default value will be assigned instead.

For example, the configuration struct parameter snap_tolerance is expected to hold a number, but instead has a different data type such as a string or a bool, so the default value will be assigned. It's important to enable strict evaluation to ensure that the input configuration is valid and prevent unexpected errors.

Skin struct evaluation

The skin struct evaluation is an essential part of the virtual joystick script. If the strict evaluation is not enabled for the skin struct, when providing a skin struct to the virtual joystick constructor, the script inspects its parameters to determine whether it is a sprite-based or draw-based skin. If the "sprite" parameter is found, the skin struct is assumed to be a sprite-based struct, and any draw-based parameters are ignored. Conversely, if a skin struct is recognized as draw-based, any sprite-based parameters are ignored. However, if strict evaluation is enabled, parameter value will be also inspected using the built-in GameMaker function typeof to ensure that each parameter stores the correct data type. If a parameter has an incorrect data type, a default value will be assigned instead.

For example, the configuration struct parameter alpha is expected to hold a number, but if it has a different data type such as a string or a bool, the default value is assigned.

Instead of providing a sprite-based skin struct, you can also provide the sprite or its name as a string. If strict evaluation of the struct is enabled, the script creates a sprite struct with default parameter values. If strict evaluation is not enabled, the sprite is used as-is.

vj_left = new virtual_joystick(,,, s_joystick_1080p);
vj_left = new virtual_joystick(,,, "s_joystick_1080p");

Previous : The skin struct Next : The DEMO project