tutorials/scripting/gdscript/gdscript_basics #61
Replies: 14 comments 28 replies
-
|
Is there a concept of "generators" in gdscript? For example: for obj in compute_a_long_list():
do_something(obj)
func compute_a_long_list():
# in c# it would be yield return 1
# yield return obj1
# yield return obj2
# etc... |
Beta Was this translation helpful? Give feedback.
-
|
4.3 introduced PackedVector4 |
Beta Was this translation helpful? Give feedback.
-
|
Is there a way to use |
Beta Was this translation helpful? Give feedback.
-
|
Since typed dictionaries are introduced in 4.4, a new section similar to "Typed Arrays" should be added for "Dictionary" section. |
Beta Was this translation helpful? Give feedback.
-
|
On property getters, does a property run its getter each time the property appears, or is the property's calculation cached? Silly example: var my_var : int:
get = expensive_function
func expensive_function():
# Does a lot of stuff
func my_function():
var new_int := 0
for x in big_number:
new_int += my_var # does this call the getter each time?
new_int += my_var + 1 # or is it cached for future lines?
new_int += my_var + 2
return new_int |
Beta Was this translation helpful? Give feedback.
-
|
On the warning about lambdas, is the third code block not just repeating the second, failing to actually represent the difference in variants outside of the lambda's scope that are pass-by-reference data types? |
Beta Was this translation helpful? Give feedback.
-
|
Concerning boolean operations in GDScript, the order of parameters is important. For the Some other languages check both methods before comparing the results. func _ready():
print(test_1(true) or test_2(false)) # test_1 true
print(test_1(false) or test_2(true)) # test_1 test_2 true
print(test_1(true) and test_2(false)) # test_1 test_2 false
print(test_1(false) and test_2(true)) # test_1 false
func test_1(value: bool) -> bool:
print("test_1")
return value
func test_2(value: bool) -> bool:
print("test_2")
return valueAn other exemple with the following code: func _unhandled_input(event):
if hovering:
if event.is_action_pressed("left_click"):
toggle_selection(hovering)The code is equivalent to: func _unhandled_input(event):
if hovering and event.is_action_pressed("left_click"):
toggle_selection(hovering)In both cases, if |
Beta Was this translation helpful? Give feedback.
-
|
Does Return stop a function or does it just return a value? If it does not, what is the reasoning behind removing that feature from Return? |
Beta Was this translation helpful? Give feedback.
-
|
A warning for people trying to use static variables in editor plugin code: you need to put @tool at the top of the script, even if the class is fully static. If your editor plugin tries to read a static variable from a static class, you'll get null. I think it should be documented, because static methods can be called without issues from editor plugins, but as soon as you try to read a static variable it all goes to hell without any warning. I posted a bug report on the godot doc repository. |
Beta Was this translation helpful? Give feedback.
-
If it's similar and not equivalent, what exactly is the difference? Is either form obsolete/recommended? |
Beta Was this translation helpful? Give feedback.
-
|
It would be neat if the editor could detect that functions are coroutines and annotate them as such, in a similar way that it detects when a function has a signal connected to it (from the editor) and shows a little green icon. |
Beta Was this translation helpful? Give feedback.
-
|
In the example, probably lowercase func my_function(int_arg := 42, String_arg := "string"):
pass |
Beta Was this translation helpful? Give feedback.
-
|
There is a typo in the Abstract Classes comments, got me a bit confused so pointing it out... The comment should be: |
Beta Was this translation helpful? Give feedback.
-
|
I was not aware properties cannot be overridden in subclasses. I now have to replace many if them with get_xxx, set_xxx in my code base. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
tutorials/scripting/gdscript/gdscript_basics
GDScript is a high-level, object-oriented, imperative, and gradually typed programming language built for Godot. It uses an indentation-based syntax similar to languages like Python. Its goal is to...
https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html
Beta Was this translation helpful? Give feedback.
All reactions