-
-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
GDScript suggestion: The "With" Construction from GMS #18345
Comments
I don't really see the point of it, only makes the code harder to read because you have to switch context in your head. What's wrong with regular indexing? var rect = $rectangle
rect.color = random_color
rect.position = random_position |
The with keyword is a solution to a problem Godot doesn't have. It performs a context switch, so you could do things like In your example with would be just syntax sugar for vnen's code. Actually, you could even drop the |
For some reason I feel like I remember seeing some kinda syntax either in gdscript or python or something similar where you can initialize several fields of a variable at once using func with(target, fields): #fields is Dict of (String, Variant)
for key in fields.keys:
var set_property = target.set(key, fields[key])
if set_property == false: #Maybe a method
if target.has_method(key):
target_func = funcref(target, key)
target_func.call_func(fields[key]) |
@nobuyukinyuu |
Personally, I find this confusing and error prone related to indentation. |
#1736 is describing something like VB's |
Coming from GM:S, I don't think GDScript needs this feature. For those of you who want to know more about it, here you have the official docs on it: https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml%20language%20overview/401_18_with.html But again, I don't think this should be implemented. |
As described in #1736 (comment), and according to the various comments here mentioning that the feature from GMS is not particularly relevant/needed in GDScript, I'll close this. |
It executes the given statement to a given node with the "other" keyword, for example:
The text was updated successfully, but these errors were encountered: