Suggestion Open

Add a type casting function.

#6760 opened by Unknown 9 months ago

Unknownreported this suggestion

Summary

Add explicit type casting operators/functions to MythicMobs, allowing users to convert variable types directly within YAML configurations using a syntax similar to STRING(x).

Usage

In YAML configurations, users can apply type casting functions to variables or expressions. For example:

Convert a value to a string: STRING({some.variable})

Convert a value to a number: INT(3.14) or FLOAT("2.5")

Convert a value to a boolean: BOOLEAN("true")

These functions would ensure that variables or expressions are interpreted as the specified type, even if their original type is different.

Value

This feature would enhance flexibility and reliability when handling dynamic values in MythicMobs configurations. It reduces errors caused by type mismatches and simplifies complex conditional checks or mathematical operations where explicit type control is needed.

Priority

Medium priority. While not critical for basic functionality, it significantly improves code clarity and reduces debugging time for advanced users working with dynamic data.

Implementation

The implementation should extend the existing MythicMobs expression parser to recognize casting functions like STRING(), INT(), FLOAT(), and BOOLEAN(). When parsing an expression, the system should evaluate the inner value first, then convert it to the target type using standard conversion rules (e.g., parsing strings to numbers, handling invalid conversions gracefully).

Sign in to join the discussion.