MerlinofMines / EasyCommands

Github Repository for Ingame Scripts built by MerlinofMines. Uses MDK to Deploy to SpaceEngineerse
GNU General Public License v3.0
8 stars 3 forks source link

[Feature Request] Variable Type and Cast Improvements #213

Closed MerlinofMines closed 2 years ago

MerlinofMines commented 2 years ago

Is your feature request related to a problem? Please describe. Currently you can't inspect the type of a variable, and if you attempt to cast it you may get a script halting exception. You also can't cast a string as another primitive type without knowing the target type beforehand. This makes inspecting arbitrary user input difficult as you can't safely inspect or cast the input without possibly throwing a script halting exception.

Describe the solution you'd like I want to inspect the type of a variable and have it output the variable type, so that I know beforehand whether or not it is safe to cast.

I also want to be able to cast a string to whatever primitive type if represents, so that if I have numeric input i can cast it and then check the resulting type. This effectively enables string "isNumeric" because you can say if resolved myVariable is numeric

I propose a "type" operation (after) that returns a string representing the variables type. The string should be the same string used as the input to the cast operations.

set myVariable to 53.4
print myVariable type
#string

set myVaraible to 1:2:3
print myVariable type
#vector

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

MerlinofMines commented 2 years ago

We should also add "Resolve" support so that you can resolve any string to another primitive type without specifically specifying the output type. That combined with the type operation gives the user a lot of control over handling ambiguous user input

MerlinofMines commented 2 years ago

I'd like to see something like:

set myInput to "My Display" text
set myVariable to resolve myInput

if myVariable type is not number
  Print "Input type must be a number! Instead was: " + myVariable type
MerlinofMines commented 2 years ago

We might be able to follow the same pattern used for rounding so that "cast" and "resolve" are actually the same operation, where cast as a uniOperand attempts to cast as whatever type possible but cast with a string attribute is treated as a BiOperand variable instead. This would also enable "resolve myVariable" and "myVariable resolved"

MerlinofMines commented 2 years ago

This was resolved by #215