ClayHanson / BlocklandRebuilt-IssueBoard

Beta testing for Blockland Rebuilt.
6 stars 0 forks source link

Hard-typed primitive variables, ie int/float/long support #306

Open ConanODoyle opened 1 year ago

ConanODoyle commented 1 year ago

Feature Pitch

Some way to create variables that have a fixed type to them and wont be automatically recasted to string and back when operations are done on them. Main thing that's needed is int, long, and float forced types.

Potential Use Cases

Should be rather self evident if you've done any sort of math in Blockland.

How will it work?

Potentially done via lightweight wrapper objects? or some sort of syntactic sugar done on a variable, like (int) %var which will then mark %var to stay an int.

I understand most of the bugs come from when interpreting statements that involve mixed types (ie adding a string to an int), so what this could do to make it work as smoothly as possible is force all the %variables in the evaluated statement to be the specified type before evaluating the statement.

Elletra commented 1 year ago

The problem with this is that it would require a massive change to how the interpreter and the language works.

There is a common misconception that "everything is a string in TorqueScript". That is not true. There are three types in TorqueScript: strings, floats, and unsigned ints. Every opcode has a fixed type it expects and anything that isn't that type gets automatically converted.

Also, the console stuff relies on string values for everything.

I would love types for TorqueScript, but it would require basically rewriting multiple systems from the ground up, and I don't know if they would want to do that. Have you ever seen the interpreter code? It's a mess.

ConanODoyle commented 1 year ago

that is sad

and yeah I am aware internally types are generally kept correct, so I was thinking about intercepting the interpreter bit and adding logic to cast stuff inside the statements could possibly be feasible and generally work as expected. Oh well.