Skript icon indicating copy to clipboard operation
Skript copied to clipboard

Converting bases, color hex codes, and ranged function parameters

Open sovdeeth opened this issue 1 month ago • 1 comments

Problem

I sincerely apologize for shoving ~~three~~ four different PRs together, they just all seemed to build on each other. If one proves controversial, I'll spin it out to its own PR.

Color hex codes: The driving force for this PR. @cheeezburga's color pr, #7246, has a useful 'hex code of color' expression, which I want to use to assist in formatting chat messages based on color objects. Since that pr seems to be stale, I'm pulling it over here. I also added a color from hex expression as an inverse relationship.

Converting bases: Since we're providing hex conversion to decimal implicitly in color conversion, we should support it fully. Currently, there's no easy way to convert between bases. Users have used character x in "0123456789..." as a workaround, but it'd be nicer and easier to have it as a built-in function for many bases at once.

Ranged function parameters: The base conversion methods in Java only allow bases between 2 and 36. I wanted more robust limits on the function parameter inputs, like parse errors if the input was a literal and out of range.

Fixes to runtime error catching/simplification errors: If a element tries to simplify but encounters a runtime error, it currently just prints that error and whatever output is used for the simplification, leading to subsequent calls not triggering the runtime. Plus the error catcher section wasn't actually suppressing errors, only storing copies while still printing them.

Solution

Color hex codes: 2 new expressions, hex code of %colors% and colour from hex code %strings%. Support for to/from hex strings was added to Color/ColorRGB.

Converting bases: 2 new functions, toBase(value, base) and fromBase(value, base). These use Integer.parseInt() and toString() to convert between bases. the base parameter is ranged from 2 to 36.

Ranged function parameters: Adds a new Modifier, Modifier.RANGED. You can use Modifier.ranged(min, max) to set an inclusive range for a parameter with any Comparable type. If the inputs are literals, Skript will check them against the range and issue parse errors if they're outside: image

The ranges are also shown in the docs: image

Runtime errors: Spun simplification into a helper function, wrapped in a RuntimeErrorCatcher, and prints Skript.error() if it catches any. Actually removes all consumers in removeAllConsumers (whoops!).

Testing Completed

Added tests for color expressions and base functions.

Supporting Information


Completes: none Related: none AI assistance: none

sovdeeth avatar Dec 07 '25 06:12 sovdeeth

Test failure is due to odd interaction between runtime error and simplification I'll add a fourth PR to this to allow turning runtime errors during simplification into parsing errors via a runtime error consumer tomorrow.

sovdeeth avatar Dec 07 '25 08:12 sovdeeth