There should be a way to call a primitive type's function by string. #6878
Closed
caimantilla
started this conversation in
Scripting
Replies: 2 comments
-
You can already write your own method on your script and make a |
Beta Was this translation helpful? Give feedback.
0 replies
-
This is implemented for future 4.3: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
It was mildly frustrating to find out that
Callable
only works with objects.My understanding is that adding this functionality to non-Object types would add a lot of overhead, so I'm not asking for it to support those types. I sure don't want to grind performance to a halt just so that I can store a reference to
Vector3i.clamped
.However, wouldn't it make sense if maybe there were some wrapper class that does this? Like
ArrayCallable
, orVector3Callable
, which would store a copy or (preferably) reference of that type and allow calling its functions that way. This could be done in GDScript, but it's... kind of a pain to solve what should be a simple problem. Execution speed would also suffer, since IIRCmatch
statements in GDScript are syntactic sugar and every condition still needs to be checked.A real-world example of this can be seen here. I was trying to call
Array.pop_front
in a while loop in my dialogue script, only to find out that every singleArray
function has to be hard-coded, andpop_front
wasn't implemented. So, while not entirely necessary, a native class for this type of case would be incredibly helpful, although a bit of extra maintenance would be required if it can't be auto-generated.Note 1: Maybe accepting a
Variant
and being calledPrimitiveCallable
would be ideal?Note 2: It also might only make sense to support this for reference types (
Array
,Dictionary
, packed arrays...)Beta Was this translation helpful? Give feedback.
All reactions