You are by far one of the best channels for Godot tutorials. You teach very well and very clearly. Love your videos.
@owenlloyd2528Ай бұрын
Thank you, very interesting. At first thought I cannot see any way that a lambda/callable would improve readability or functionality in my current projects but I am sure that when I get into it things will pop out screaming 'use me!'. Very informative.
@robipro9254Ай бұрын
Very nice tutorial. I like using lambda functions when connecting signals. Instead of, for example, writing my_signal.connect(_on_my_signal.bind(a_value)) then create in the script func _on_my_signal(my_value), I can simply write my_signal.connect(func(a_value): what ever code I want). That way, I don't have to think about a name of a function (here _on_my_signal) and I don't have to cluster my script with multiple small functions linked to managing signals.
@desireelustreАй бұрын
This is another informative content. Thank you as always.
@dev-wormАй бұрын
thank you! I am so happy to hear such kind words!
@ClaudehopperАй бұрын
In my opinion, using Lambda functions for the example you gave with capping the health is a little more work than it's worth. I find it much easier to just clamp the variable. var health: int = 100: - set(value): - - health = clamp(value, 0, 100) This does it all for you with much less clunk and is easier to read. However, even if I don't think that's a good use for it, I already found value out of using Lambda functions and I thank you for this video!
@Mr_BetaMaxАй бұрын
I didn't know GDScript supported this! Amazing!
@cheesy4810Ай бұрын
That helped with a lot of questions I had. Great tutorial, keep going.
@dev-wormАй бұрын
thank you so much! I am glad it helped!
@schuepbachrАй бұрын
Educational and aspirational. Thanks for the content! Now I need to get through initial setup and start implementing systems. (I feel like I could use a lambda to carry an armor system, with various stages of armor, and snapping it in line with the take damage process. Player takes damage, the value gets pushed through the player armor callable, then gets subtracted from current health, and tests dead or not.)
@lout160Ай бұрын
The tutorial I didn't know I needed. gotta go do some refactoring now.
@dev-wormАй бұрын
That’s awesome to hear! I hope it helps!
@JohnathanBlack-j3h26 күн бұрын
Appreciate this video! Thank You!
@dev-worm26 күн бұрын
I am so happy to hear that! glad I could help! thank you!
@OriahVinreeАй бұрын
I live a simple life. I see a new DevWorm video, I click.
@dev-wormАй бұрын
haha!! thanks the support truly means the world!
@LincsOracleАй бұрын
Great tutorial and I fully understand how to create an use a lambda function. However the I just struggle to see the benefit compared to just creating a couple of functions and call them directly as shown in the example below. Only difference I can see is I'm duplicating the print(new_health) statement in both functions. extends Node2D var player_health = 100 func add_health(phealth: int, amount: int) -> int: var new_health = phealth + amount print(new_health) return new_health func subtract_health(phealth: int, amount: int) -> int: var new_health = phealth - amount print(new_health) return new_health func _process(delta: float) -> void: if Input.is_action_just_pressed("ui_up"): player_health = add_health(player_health, 10) if Input.is_action_just_pressed("ui_down"): player_health = subtract_health(player_health, 5)
@fr4ctur71Ай бұрын
I have also been pondering the use of lambda functions. One thing I've realized is that I don't think you can pass a method normally as an argument. So the lambda and callables allow you to pass functions and logic to other scripts that don't have access to those methods. I've also found use for them specifically when building a load screen and something to monitor the loading of assets asynchronously. the main script could tell all the other things to start loading, and pass them a Lambda function as a callable that would essentially ping the main script or run whatever was needed to update the display. But it meant that each asset that was loading, didn't need access to the UI to update it or access to the main script to tell it to update the UI. I could be wrong about this though xD I'm very much still learning things
@dyegoeduardosantossilva3659Ай бұрын
Using Callables variables is very much useful ( not sure about lambda functions though, i didnt really understand if they are the same thing ). You can have a piece of script that at one point calls a function to do something. If you ever have, like, two different things you could do at this point ( like subtract or add health ) you might just do an if statement and check for each function to call, right? Using callables, however, is much more simpler in some cases. Like, suppose you have an watery enemy you can shoot with different kinds of bullets.A regular bullet doesnt do anything to him damage-wise, instead it plays an animation on the enemy and changes its behavior. Now imagine you have a freeze bullet, that only freezes this enemy ( locks him in place, changes animation, yadda yadda yadda ), and THEN, a regular bullet would shatter the ice and therefore deal damage to the enemy. Now, on both occasions, the bullet is hitting the enemy on the same way, but the processing is different. You could have an If statement on the enemy function that handles the interaction, checking for if the enemy is frozen or not. OR you could have the function that handles the regular bullet interaction stored on a variable. So now, every time your enemy gets frozen, you can change which function is stored in said variable. That way your code stays the exact same, calling a function inside a variable, but you can change which function is stored inside depending of different interactions. This might have been really hard to understand ( in that case sorry ), but its one example that Im using myself on the game im currently working on. In any case, yeah, they can help you organize your code better on a lot of situations, specially if you have some nodes accessing functions of other nodes or things like that ( like the bullet telling the enemy that it got hit )
@SleepyLazyPanda8 күн бұрын
thank y'all for sharing knowledge
@KartikNarayananАй бұрын
Great video. How are lambda functions/callables in terms of performance? Also, could you please do a similar video on _unhandled_input and how to use it in game
@dev-wormАй бұрын
supposably there isn't a noticeable difference in performance
@KurtBuhlerАй бұрын
Great one!!
@mkaks22gamerserise16Ай бұрын
always support you
@dev-wormАй бұрын
thank you so much! that means the world!
@notaboutit3565Ай бұрын
Haven’t gotten a chance to mess with this yet, but can you @export the var that contains the lambda and have an inspector-definable argument? Idk if that makes sense or has a real use but
@dyegoeduardosantossilva3659Ай бұрын
You cant do that, unfortunately. I would love to be able to do that but apparently its kinda of impossible to store that. I think functions are an adsress inside your ram memory, when you save stuff on export variables, they become actual text inside your .tscn file, so it would be impossible to store a function since every time you load the program ( in this case the game ) it goes to a different address in your ram. Although i might be completely wrong in this ( in why it doesnt work ). I do know for sure it doesnt, though.
@notaboutit3565Ай бұрын
@ thanks for the reply :) I appreciate the knowledge transfer for sure!
@dyegoeduardosantossilva3659Ай бұрын
@@notaboutit3565 you're welcome man
@rionhunter23 күн бұрын
i'd never been able to get variable base lambdas to work. learning it was because I was missing .call all this time has me fist shaking. Otherwise, my go-to lambda usage has been limited almost entirely to mouse_entered.connect(func(): mouse_over = true) and the opposite for mouse_exited. but by the gods has that been powerful enough for me
@malojordan653Ай бұрын
Would you consider making a roguelike tutorial?
@alonsonneveld8137Ай бұрын
I have a small problem in Godot rn when I try to run my project in the editor it only works sometimes do you know how to fix this bug
@dev-wormАй бұрын
like it only runs sometimes? I haven't ever had the issue you are having but I have had a few engine bugs and usually I just either close and reopen the engine or delete Godot and redownload it!
@notaboutit3565Ай бұрын
Also, I know these are intended not to be global scope, but could you add them to the global pool in the project settings and would it be beneficial?
@MaffezzoloКүн бұрын
Hi devworm, can you give me a light in how can i use normalmap on animatedsprites? This is really messing up with me😢
@635574Ай бұрын
For things like health, setters and clamp() are doing all the work, no funcs or lambdas required. But I would use this for some simple things like that calculator example, not sure if it will be useful for the game I'm building now. I only know setters because of 16bit dev
@dev-wormАй бұрын
that is a very good point, and I can agree with that for the health example. But I do still think there are many instance though where callables could play a huge part in keeping things "orginized" within a script.
@mystiogan5891Ай бұрын
Thank you (╹◡╹)
@dev-wormАй бұрын
thank you and of course!! I hope it helped!
@ajmgdajАй бұрын
tbf nothing needs a lmabda function. There are just places where they are extremely convenient and clear to read
@dev-wormАй бұрын
very true.
@bradleygross5340Ай бұрын
Can you curry with lambdas in Godot?
@GardenData61371Ай бұрын
Prepare for unforseen consequences
@CaucasmapАй бұрын
Hello friend, how can I zoom in and out of the map in my own grand strategy game and also move the map with the mouse?
@jeremiahaemile2008Ай бұрын
back from hell (school ;) today is my rest
@dev-wormАй бұрын
that rest is important! how is school been going Jeremiah? Im guessing not too well from that comment lol!
@jeremiahaemile2008Ай бұрын
@@dev-worm i have alot alot alot of weekly homeworks monthly test i have just finished the first month exams from two days and alot of unfinished lessons 🙂🙂
@jeremiahaemile2008Ай бұрын
so easy right 😁😁😁
@SeanBothaАй бұрын
GODOT CEO=people that say keep politics out of game engines are toxic!
@w00tyd00dАй бұрын
Hate to break it to you, but games have had politics in them for the past 40 years 😂 you just don't want games to include politics _you don't agree with,_ which is fine, but call it what it is.
@moonkis9103Ай бұрын
You can use any function (4.4 will have static as callable as well) as a parameter, you just shifted cluttering the namespace with functions to variables. I watched the video and honestly came out a bit disappointed. The examples fails to mention the two biggest most useful aspects of lambdas: Lambdas are great *especially* for capturing local variables and passing it down func foo() -> void: var local_variable: int = 5 bar(func(): local_variable += 1) and currying en.wikipedia.org/wiki/Currying Would have been really nice if this delved into those aspects a bit more and could have provided some useful insight into when they can be good. I can take a real example I use where I have a combat function (turn-based) where I reset the original local z_index of whatever I'm tweening on the tweens finished signal without having to store that information anywhere but it's lambda-callback.
@moonkis9103Ай бұрын
Snippet: func _handle_attack_action(event_: Event.AttackEvent) -> void: var position = event_.attacker.position var z_index = event_.attacker.z_index var reset_callback = func(): event_.attacker.z_index = z_index _tween = make_tween() _tween.set_ease(Tween.EASE_OUT) event_.attacker.z_index = 999 _tween.tween_property(event_.attacker, "position", event_.target.position, 0.125) _tween.tween_property(event_.attacker, "position", position, 0.125).finished.connect(reset_callback) This way the attacker will always be on-top of the defender, but then reset once the tween is finished to it's original z-index. This code isn't perfect, but it does display the power of capturing state to be modified at a later stage as part of say a callback.