-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add varref
function to referencing a variable in a instance
#3497
Comments
Actually FuncRef was removed in 4.0 in favor of Callable, which is basically a method pointer. Such concept exists in many languages, while "property pointers" not so much. Also implementation of VarRef would take less than 30 lines. It could as well be a plugin. |
Aren't all |
@KoBeWi It could be a addition for 3.5 release, even if it takes small lines of code, it could be useful for some cases like funcref does. But yeah, if not added to core, it can indeed be a small script to add. @LightningAA If you used |
Pointers/references and passing arguments by reference in scripting languages have a rather negative reputation. I think that we should not encourage this. But if you need, then you can pass an array like extends Reference # 4.x: RefCounted
class_name VarRef
var _instance
var _property
func _init(instance, property):
_instance = instance
_property = property
func set_value(value):
_instance.set(_property, value)
func get_value():
return _instance.get(_property) |
would #623 be sufficient solution for you? |
Describe the project you are working on
ReactGD a plugin to create reactive interfaces with JSX-like syntax
Describe the problem or limitation you are having in your project
In my project, you return a structure from the
render
function of aReactGDComponent
extended script, which is used to render the node tree. One of the features is to grab the reference of a node like:which would be parsed into:
the plugin would use
ref
passed value of the variable reference to set the variable value to the node reference.Describe the feature / enhancement and how it helps to overcome the problem or limitation
The function
varref
would return aVarRef
just likefuncref
returnsFuncRef
, which would store the instance reference and the variable name string, then it would have functions similar toFuncRef
.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The class
VarRef
would have the following functions:get(): Variant
Get the referenced variable valueset(Variant val): void
Set the referenced variable valueis_valid(): const bool
Returns whether the object still exists and has the variable assignedset_instance(instance: Object): void
Sets the instance reference derived fromObject
of the referenced variableIf this enhancement will not be used often, can it be worked around with a few lines of script?
It requires the creation of a class that stores the instance reference and the variable name and implement the functions needed.
Is there a reason why this should be core and not an add-on in the asset library?
Because it works simillar to
FuncRef
, which is a core feature, so I don't see a reason to not haveVarRef
too.The text was updated successfully, but these errors were encountered: