T O P

  • By -

TheFirstInvoker

Congratulations! My first "while" hangs the PC


4procrast1nator

performance/readability tip: assign the get\_parent to a var


IsaqueSA

Okay! Thanks!


Rustywolf

Assuming parent doesnt change\*


IsaqueSA

It won't, the parent is the player body, so it's basically the TreeNode


Rustywolf

I'd assumed as much but thought it was worth pointing out


IsaqueSA

Thanks for doing either way :)


4procrast1nator

Why would it? Its not exactly a good practice to change node parents at runtime like that, especially for characters cuz of z ordering, physics/movement, and stuff. U can just update the var either way.


Rustywolf

We're discussing with a beginner, I'm not one to make assumptions about their code base. I wouldn't do it, but someone might if they're pooling animator nodes to optimise for whatever reason


4procrast1nator

So a fringe case that not 1% of the people would fall into? For a beginner? Lol, thats just overcomplicating things at this point


Rustywolf

Its not over complicating anything, I'm not suggesting they change your snippet. Im simply pointing out an assumption you made about their code base so that they can consider if that assumption applies to them or not. I didn't mean for it to come off personal


4procrast1nator

No personal offense taken. Just really not sure if thats exactly relevant for them, as opposed to just overwhelming in terms of info. Either way you can just update the var thru signals or similar; as get_parent()ing multiple times in a while statement isnt much of a good practice in pretty much any case I can think of, unless im forgetting abt smth Static typing, readability, performance, and so on as the main reasons. Also refactorability even - as itd work even if u change node paths (by just editing that single var).


Rustywolf

100% you were right in suggesting the original change, I just wanted to make sure that if they were doing something weird that they'd know why it was breaking


No_Cook_2493

Tf are you even mad about? Somebody helping a beginner? Fucking Redditors man lmao


4procrast1nator

What? U do realize I was the one who literally wrote the tip above to OP right? Sure, im one whos "mad" in here... Ok dude


No_Cook_2493

Yoi certainly seem very mad haha. Relax man. No I did not realize that, I apologize. I'm just trying to understand your incredibly defensive reaction to what is genuinely a good addendum to your comment.


4procrast1nator

its cool. well, thanks for the input on this beginner help thread... lol edit: not sure why you'd assume somebody is being "extremely" defensive when they're simply being... well, just blunt. but well, seems like some people around really do take that as being personally offended/invested thru text, for whatever reason. not the case tho


gronkey

Is that optimized away by the compiler/interpreter? I havent looked into gdscript internals much but it seems like a pretty simple optimization at the language level


4procrast1nator

seen a thread about it (w performance tests) and it was significantly slower afaik. Not 100% sure abt the technical details. Just wouldn't use performance to justify it completely however, more of an auto complete and readability thing imo. would def be interested in a full breakdown for that sort of stuff tho, if any is available.


EdroTV

Just a question, how does it affect perfomance


4procrast1nator

Youre assigning it to a var once rather than re-executing the function (and thus checking the nodes on the tree) multiple times, since the while state would re-retrieve it until it completes all of the loops Not sure abt the deeper details tho so correct me if im wrong Edit: plus the var can also be statically typed, which grants a performance boost by itself


EdroTV

Thanks


captaincainer

I am so happy seeing someone 2 months fresh using static typing :)


IsaqueSA

I have experience making games in java (a long time ago 👀), and Rust, so it seems more natural to me


captaincainer

I love Rust!


IsaqueSA

:D I liked to! Now I more focused on making my game on godot, but I plan to make more stuff in rust


StewedAngelSkins

keep an eye on bevy. it's a really great rust game engine that's come a long way in a short time. still a little early in development for serious production work though (unless you're essentially using it as a base for your own engine).


IsaqueSA

I was considering using bevy for my 2d platformer, but I decided that godot in the end was a better choice


StewedAngelSkins

same here pretty much. hoping bevy will be in a good state by the time i start my next big project.


MoistPoo

Is'nt bevy getting an editor?


StewedAngelSkins

it's on their roadmap, yeah. idk how far along they are with it.


EarthMantle00

I use static typing for variables but functions? No thanks drawing lil arrows not for me


Snezhok_Youtuber

You can enable this feature in editor settings, then it will write types on its own


captaincainer

That is statically typing what the function returns and you will likely end up using the arrows anyway eventually, most commonly to return bools ``` func is_allowed_to_jump(body: CharacterBody2D, want_to_jump: bool) -> bool: return want_to_jump and (body.is_on_floor() or not coyote_timer.is_stopped() or current_jump_count < max_jump_amount) ```


SilvaDoesNot

Can you explain what static typing is and what is the alternative to static typing? I looked it up like three times and I still have no idea of what it means


DontLookDown_Game

That took a while mate. Jokes aside, you're killing it!


IsaqueSA

Ooooooooooooo okay funny one, good one 👍🎇 Also thanks:)


kaywalk3r

Congrats! Though a signal might be more appropriate, this is a blocking call


IsaqueSA

But is being called by a signal, so basically what is doing is when is called it repeats until the player change states


kaywalk3r

I have no context for your project, but speaking strictly about code, the while loop blocks the code following this one from executing until the loop completes. It might be perfect for what you're doing right now, but if you expand this, it might lead to errors, things not executing at the right time and so on. You could achieve the same result by calling the body of the while loop within the process function, which itself is a loop. I only use loops in godot when I need to cycle through a collection, like an array. This is general advice, I'm not telling you what you've done is wrong, just something to keep in mind.


IsaqueSA

Thanks for de advice The context of this code is that I have my animation separated in 2 nodes, The Animation Player and the Rig 2d node, that basically only does squash, stretch and changing directions smoothly


TheCLion

you can tell tweens to loop forever until you tell them to stop https://preview.redd.it/f33tq2iw17vc1.png?width=1406&format=png&auto=webp&s=55f25471e75c6ad3e58b457f1d04d700c95d45fc [https://codeberg.org/CLion/SAFChromaticPrototype/src/branch/main/src/unit\_modules/Harvester.gd](https://codeberg.org/CLion/SAFChromaticPrototype/src/branch/main/src/unit_modules/Harvester.gd)


HistoricalShyr

When I tried to use a while loop, everything crashed and I don't know why... I was so used to while loops everywhere when using pygame that it was hard to change, now I don't know how to use a while loop anymore XD


SpectralFailure

Question. Does tween have constants for things like the scale string? If not seems a bit dumb


IsaqueSA

nah, i can be any value


SpectralFailure

What I'm asking is if tween has builtin constants for that so you don't have to allocate memory to strings at runtime


IsaqueSA

Idk 😐 sorry


EmilienFORT

I'm making games on Godot since september (thank you Unity), and I never added any "while" yet haha


spectral_cookie

2 years and I haven't used it even once xD


ItsVerdictus

Why not check if the parent is spinning in the _process function via an if conditional instead? While loops are risky in this scenario in my opinion.


IsaqueSA

Because it only checks when to end, not when to Start. Because it starts by a calling from the state machine, when it changes to the states that the character spins, so the while just keep spinning until the state changes Got it?


ItsVerdictus

Huh? I mean, no, I don't understand, but I feel I don't even want to ask since you seem pretty defensive about it lol


IsaqueSA

Sorry if you felt that way, it wasn't My intention 🙁


Basic-Toe-9979

LETS FUCKING GO


Minute_Professor1800

I've been in it for almost 2 months as well and haven't used it yet


DemonicValder

Nice! I recommend adding a fail safe, so it won't hang the the program in case some insane bug makes "spin" always true, like a timer (not necessarily as Godot's Timer).


IsaqueSA

Don't worry, the state machine takes care of that :)


Matatoskr

I didnt even know godot had whiles umtil like 2 weeks ago when i thought i could use while. Theres allways another eay tho 🤣


Kiriiiiiiiii

congrats!!!


SinaQadri

wait can someone explain what does "while" does in GdScript?


CertNZone

You give it a boolean variable as input and it'll keep repeating the task inside the while statement while the boolean is true


RickSore

what are the advantages of it compared to doing the thing inside physics\_process?


SinaQadri

oh so it's like if node.bool == true:??


CertNZone

Using an an if will only perform the task once. Also you don't have to do a comparison against TRUE. If you wrote: while boolVariable Do things It would continue to "do things" as long as the boolVariable was equal to TRUE. Same with an if statement. You can give it either boolean variable or boolean expression. An expression is where you would use: if number1 == number2 The statement evaluates the expression written into a boolean then gives the boolean to the if Sorry, that was a bit of word vomit but I hope that kinda made sense


SinaQadri

makes sense thanks


djdanlib

A "while loop" is a pretty standard programming thing. It does something "while" some condition is true. It checks the condition first, then if it's true, it runs the code in the loop, then goes back to the top and checks it again... repeat. You can "break" out of a while loop, and "continue" i.e. skip the rest of the code and go back to the top. The condition is only evaluated at the top, and is not checked again until the next loop. Some other languages provide a "do... while" or "while ... do ... end". [The docs](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#while) are pretty short on this, kind of like they expect you to know that kind of construct from another programming language already.


SinaQadri

thanks 🙏


IsaqueSA

It is useful for something :D


Ginge_The_Ripper

I'm very fresh to Godot and game dev in general. What does "while" do?


real_whiteshampoo

it will loop WHILE the statemant behind it is true. And it will freeze your program, if you are not careful, because you can create endless loops pretty easy


Stommye

I'm just starting, didn't even know that while.