First Class Functions and Signals in GDScript - Godot 4

  Рет қаралды 22,921

GDQuest

GDQuest

Күн бұрын

Пікірлер: 41
@franciscoayrolo5612
@franciscoayrolo5612 10 ай бұрын
Maybe it would've been useful to explain the concept of Higher Order Functions and First Class functions, so that people see WHY it's a big deal. i.e First class functions are a feature of higher order functions, which are basically functions that take functions as arguments. It sounds totally mundane and intrascendental, but it wasn't there before for a reason, right? And it should be explicited! Now functions can be seen as objects themselves, instead of having to be passed around by their names in strings. This in turn opens the conversation for what anonymous functions are and whatnot, which is also great
@SenkaZver
@SenkaZver 10 ай бұрын
This is definitely a game changer. Signals were so awkward to use before, but this follows the typical writing of most of gdscript and is far easier and cleaner to use and read. Massive update
@adon155
@adon155 10 ай бұрын
Not sure if this was in earlier versions, but another great use for callables is the array methods map, filter, reduce, any and all. Map lets you apply a function to every item of a list to transform it, Filter lets you filter out items in a list based on a function returning true or false, Reduce is kinda hard to explain but it lets you apply a function that combines every element in a list (a common example would be summing every integer), and Any/All lets you check if every or atleast one element of a list meets a criteria
@BryceDixonDev
@BryceDixonDev 10 ай бұрын
Those are new, and really fantastic. They weren't really possible before because we couldn't pass method references as parameters.
@not_kelbaz
@not_kelbaz 10 ай бұрын
GDScript is just perfect for game dev 👌
@askeladden450
@askeladden450 10 ай бұрын
Yea, its really underrated. I came from 6 years of unity c# experience and more than a decade of c++ experience, and i was more productive in gdscript after just 2 days of learning than i had ever been in unity. The terse syntax, integration with the engine and amazing compile times are game changing.
@yourmajesty9025
@yourmajesty9025 10 ай бұрын
Have you seen their auto LODs? 😂
@Volt-Eye.
@Volt-Eye. 10 ай бұрын
​@@yourmajesty9025do you know how rapidly Godot is Growing. Unity took more than 20yrs
@saul8510
@saul8510 10 ай бұрын
​@@yourmajesty9025eh, why you talk like that? godot auto lod is quite efficiente, and it has them unlike unity...
@TRUFANATIC
@TRUFANATIC 10 ай бұрын
I agree!
@ahnmichael1484
@ahnmichael1484 10 ай бұрын
I have been in love with Python for some years, but was still dealing with C#'s somewhat slow/tedious coding - I am so thrilled to be able to code in Godot and it feel like home, so easy and logically clean 😭
@Bogdan-Dode
@Bogdan-Dode 9 ай бұрын
a mobile app tutorial that will resize to all screen sizes will be wellcome
@astrangefool
@astrangefool 10 ай бұрын
i jumped on this when it first came out and it makes handling deferred calls like loading from the web so much more compact! i love it!
@GDScriptDude
@GDScriptDude 9 ай бұрын
Hopefully the auto-complete works nicely with this feature of avoiding string names for functions in signal connects.
@Gdquest
@Gdquest 9 ай бұрын
In my experience so far, yes it does.
@matheusnico1as
@matheusnico1as 10 ай бұрын
I have a question about your course. I'm good with programming because I'm a software engineer for 7 years and I code since 2014 and I'm very good with Godot 4 in 2D, but I never tried 3D and I want to dive into 3D content from the basics to the advanced. Which course do you recommend? It looks like you have different classes. Also, great video!
@Gdquest
@Gdquest 10 ай бұрын
I'm glad you enjoyed the video! Thanks for watching. I would get the 3D course and Node Essentials. The latter is more of a reference resource but it does cover a fair amount of 3D mechanics and would help you go faster. Node Essentials may even be enough on its own for you, it's hard to tell. Remember that you can get both courses now that they cost less and if you find the 3D course not matching your level of skill, you can ask for a refund. Alternatively, you can already get a fairly accurate idea of the concepts taught in the 3D course here: Info about the 3D course: school.gdquest.com/products/learn_3d_gamedev_godot_4 Info about Node Essentials: school.gdquest.com/products/node_essentials_godot_4
@matheusnico1as
@matheusnico1as 10 ай бұрын
@@Gdquest great, thank you very much!
@adon155
@adon155 10 ай бұрын
If you’ve used other languages it might be good to note that these callables are also used for some functional concepts related to lists, such as a map, filter and reduce methods
@mimisaiko
@mimisaiko 10 ай бұрын
Love how I don't have to type so many double quotes anymore
@superj1e2z6
@superj1e2z6 10 ай бұрын
Speaking of signals, I see that all object derived classes use signals (Nodes,Resources,...). Are there some good tricks with creating and using non-node signals.
@ObsidianBlk
@ObsidianBlk 10 ай бұрын
One idea off the top of my head... let's say you create a custom Resource object to be used to contain custom game data that you plan to save and load. Let's say this same resource object is used by a "player" node to store a score. Let's also say that you have a "scoreboard" Control node that displays the score from the resource. Instead of connecting the scoreboard to the player node directly (which could become cumbersome depending on the complexity of your scenes) you could, instead just have both the player and scoreboard load this custom resource (Godot will only load a resource file once, so both the player and scoreboard will, essentially get the same instance of the Resource object without have to explicitly pass the loaded Resource object to either of those nodes). That way, the player node can change the score in the custom resource, and when that happens, the custom resource can emit a signal, that the scoreboard listens for, when information is changed. I hope that made sense.
@alexanderverbin1609
@alexanderverbin1609 10 ай бұрын
It is a brilliant idea to use a connection function instead of using the function's name in the quotes. I was thinking about it while learning Godot3, the same situation was in Qt Framework with version 4 but starting with version 5, The Qt Company decided to add a reference to a function instead of the function's name. It decreases the waste of time.
@rafaelbordoni516
@rafaelbordoni516 10 ай бұрын
Huuuuuuuge!!!! Dependence on strings was a thing a lot of people complained about, me included. This is gonna make everything so much easier, just thinking in terms of first class functions like one does in javascript or lua already changes the whole code, this is going to be huge for gdscript!!
@grymdylan
@grymdylan 10 ай бұрын
Wasn’t aware of this; this is a game changer. So much easier.
@SleepDepJoel1
@SleepDepJoel1 9 ай бұрын
Loved the original courses, can't wait to get my hands on the new versions!
@snartgaming4922
@snartgaming4922 10 ай бұрын
took yall long enought thank you guys
@God_of_Art
@God_of_Art 10 ай бұрын
guys is it time to jump on ver 4?
@VictorEstivadorebarbudo
@VictorEstivadorebarbudo 10 ай бұрын
Damm! this looks pretty cool, but this Callable looks new, I didn't know it exists in 3.5 and I think I need to practice to get used to it. but the less usage of strings is something really amazing. for a begginer all that strings are too much responsability over me D=
@BryceDixonDev
@BryceDixonDev 10 ай бұрын
Slight correction: GDScript doesn't have functions, it has methods (which are confusingly declared with the func keyword). The primary difference between functions and methods is that a function has no inherent state while a method is inherently tied to the state at which it's defined. You can compare this to something like C++ which doesn't have methods (the closest thing being a lambda which explicitly captures), but its classes/structs can have member functions (which dont have inherent state, they get state via the `this` parameter). This is likely the reason they went with the name of "Callable" instead of "Function"
@wulfrickwille3871
@wulfrickwille3871 9 ай бұрын
Can you explain 'state' in more detail?
@BryceDixonDev
@BryceDixonDev 9 ай бұрын
@@wulfrickwille3871 Sure; imagine the following code block: func f1(): add_child(f2()) fund f2(): var x := 4 var g := func(): print(x) var node := Node.new() node.ready.connect(g) return node When `node` is added to the SceneTree, its `ready` signal will invoke the `Callable` `g` to print `x`. However, as that will be occur in the scope of `f1`, `x` will have fallen out of scope since `f2`'s stack frame has been removed, so to have access to it, `g` must have an internal copy as part of its own state. This also means different instances of the same lambda can have different states (for example if `x` was a parameter or derived from a parameter of `f2`)
@BryceDixonDev
@BryceDixonDev 9 ай бұрын
@@wulfrickwille3871 And for non lambdas, this also holds true. `self` isn't an implicit first parameter like `this` in C++, it's a part of each method's internal state. Calling a.f() will invoke a different Callable object than b.f() which is also why you can't properly reference/bind non-static methods like you can in C++.
@this-cris
@this-cris 9 ай бұрын
This is a valid insight. Even if your .gd file doesn't have a class_name declaration, it is still technically a class and can be referenced and instantiated by other .gd files using the resource path. all the top level variables define the state, although you could be "stateless" if you don't use a single var definition outside of a function. Any idea why they went with "func XYZ():" instead of some other keyword?
Learn GDScript from Zero with this Free app
2:01
GDQuest
Рет қаралды 108 М.
5 INVALUABLE Godot 4 Code Patterns (feat. @Gdquest )
11:39
PlayWithFurcifer
Рет қаралды 69 М.
iPhone or Chocolate??
00:16
Hungry FAM
Рет қаралды 43 МЛН
Godot 4.2, Restorer of The Lost | Full Feature Breakdown
21:35
How to Code Melee Attacks in Godot: Hitboxes and Hurtboxes
15:11
10+2 AWESOME ADDONS for GODOT 4
8:36
MrElipteach
Рет қаралды 143 М.
Godot 4 Fixing Bias Shadow for BETTER!!!!
3:25
tutor tomato
Рет қаралды 469
How to Use SIGNALS Correctly in Godot 4 (everything to know)
24:06
How to use Classes in Godot! - Intermediate Tutorial
8:46
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,1 МЛН