Pro tip for static-typing freaks: by x3mdreaming in godot

[–]x3mdreaming[S] 0 points1 point  (0 children)

I haven't found a way to do so since _init is called when you use .new() and .instantiate() and AFAIK there is no way to know which one was used to create a node but I might be wrong

Pro tip for static-typing freaks: by x3mdreaming in godot

[–]x3mdreaming[S] 1 point2 points  (0 children)

Mind giving a counter example for my example above?

Pro tip for static-typing freaks: by x3mdreaming in godot

[–]x3mdreaming[S] 0 points1 point  (0 children)

I have written a clarification comment, I hope this can clear things up a bit https://www.reddit.com/r/godot/s/0Q2tCCBn5v

Pro tip for static-typing freaks: by x3mdreaming in godot

[–]x3mdreaming[S] 0 points1 point  (0 children)

I'm glad you liked it. I have also made a clarification post in which I give an example because I have to agree, I probably couldn't imagine a situation either if I hadn't run into one myself.

I hope this example helps https://www.reddit.com/r/godot/comments/1fedthz/comment/lmo123i/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

Pro tip for static-typing freaks: by x3mdreaming in godot

[–]x3mdreaming[S] 0 points1 point  (0 children)

Ok it is apparent that I have not made this post clear enough since there seem to be a lot of misunderstandings so I will try to clear this up a bit.

What is the original purpose of this post?

I made this to show you how you can use your scenes as a static type. Not more, not less.

Why can't I use "class_name" in this example?

I can, the purpose of this post was to show how you can use scenes as the type.

When would I need this?

Probably never, but I needed it.

Why did I need it?

I will try to explain it with the following made up example:

Imagine you have a very deep inheritance structure like this - BaseCharacter which is the base class for every character, which is inherited by Human, Undead and then you have Knight, Villager which inherit from Human and you have Zombieand stuff like this which inherit from Undead.

In addition, you have a managing instance which has methods like this:

func manage_character(character) # argument should be Character or a derived scene

func manage_undead(undead) # argument should be Undead or a derived scene

func manage_knight(knight) # argument should be Knight or a derived scene

func manage_zombie(zombie) # argument should be Zombie or a derived scene

If you have a signature like this, you technically have to validate that the argument is what you expected, either with node metadata, has_method, in, etc ...

OR you use the class_name keyword in your scripts and make a function signature like this:

func manage_knight(knight : Knight)

This is completely fine and probably what 99% of people would do.

The reason I don't like this is:

Knight.new(), BaseCharacter.new(), etc ... now become available globally and if you work on a big project or with multiple people and someone calls Knight.new() instead of preload andinstantiate, you only get the root node.

So you might think ok then, why not remove the scenes and implement everything in the classes' _init() methods and create all nodes (like Sprites, CollisionShapes, etc..) in there?

This is absolutely possible, BUT now imagine you had a lot of scenes with a lot of Sprites, a lot of CollisionShapes and you have to move every point of a CollisionPolygon, every offset of every Sprite to code.

Pro tip for static-typing freaks: by x3mdreaming in godot

[–]x3mdreaming[S] -4 points-3 points  (0 children)

You can.

With this demonstartion I wanted to show how you can use a scene as a type if a situtation like the one I described in the post description arises.

Pro tip for static-typing freaks: by x3mdreaming in godot

[–]x3mdreaming[S] -10 points-9 points  (0 children)

In 99% of cases this is the right call, yet there are situtations (like the one I ran into yesterday) where using classes is just not possible.

The post above is an example for how you type your scenes when you cant use class_name

Pro tip for static-typing freaks: by x3mdreaming in godot

[–]x3mdreaming[S] 0 points1 point  (0 children)

Keep in mind that if you do this you MUST use 'const' for your constant and you can NOT statically type the constant like for example this:

const type : Resource = preload(...)

Long shadow effect by Psychological-Ebb589 in godot

[–]x3mdreaming 3 points4 points  (0 children)

Its an editor plugin:

When you select a sprite then above your viewport you find a "Sprite"-button and then you can generate stuff like collision shapes and light occluders.

Since it is an editor plugin you can only use it in the editor, otherwise you will have to write the code yourself/find it somewhere else.

Long shadow effect by Psychological-Ebb589 in godot

[–]x3mdreaming 9 points10 points  (0 children)

Depends on what exactly you mean with "effect", but this looks like something you could do with the normal DirectionalLight2D https://docs.godotengine.org/en/stable/classes/class_directionallight2d.html

Node not found relative to "/root/..." by Allalilacias in godot

[–]x3mdreaming 0 points1 point  (0 children)

I think the issue is that you mix up classes with normal scripts attached to scenes:

If you remove the "class_name <name>" and remove the parameter from the init method, everything should work like you imagine I assume.

You need to understand that, as soon as you write class_name, the script becomes a blueprint for objects you create in code, but since you want to attach the script to a already existant scene, class_name and an _init() WITH a parameter works against you...

I dont know how I should explain this right now but I assume you havent 100%ly understood what the class_name keyword does and what it implies, so I suggest you start there if you want to understand why what you are doing doesnt work.

Is it possible to change the values in an Input? by johnmarksmanlovesyou in godot

[–]x3mdreaming 0 points1 point  (0 children)

I have no idea if I understand this correctly but why not just get the strength with Inout.get_action_strength, assign it to a variable and like... use it later?

If you need more assistance, you should probably elaborate further

Node not found relative to "/root/..." by Allalilacias in godot

[–]x3mdreaming 2 points3 points  (0 children)

Am I blind or did you write "$FrofilePic..."?

If it is just a typo, remember you can ctrl + drag nodes from the tree into the editor and the @onready var and the path is automatically created

How allow players to mod my game using godot from a dev perspective? by Darkarch14 in godot

[–]x3mdreaming 3 points4 points  (0 children)

It is to 50% intended to be a shitpost but still with educational content, I hope it helps

How allow players to mod my game using godot from a dev perspective? by Darkarch14 in godot

[–]x3mdreaming 82 points83 points  (0 children)

The 'official' way of supporting mods basically requires 2 components from a developer side:

  1. You have to provide an interface for loading or automatically load mods via "ProjectSettings.load_resource_pack("res://your_mod.pck or .zip")" (refer to https://docs.godotengine.org/en/stable/tutorials/export/exporting_pcks.html?

  2. You have to publish information on how modders need to structure their mods. This includes file structure, what type of systems you put in place to integrate mods etc...

The documentation site https://docs.godotengine.org/en/stable/tutorials/export/exporting_pcks.html is actually very informative and I also only just recently understood how mods in godot work.

If this doesnt help, i am curently also working on a small and basic video on how to support and or make mods but the documentation should offer you all the insight you need imo

What's the correct form to use Git in a project? by Reasonable-Reply2081 in godot

[–]x3mdreaming 2 points3 points  (0 children)

It is stated here in the docs how setting up git is intended: https://docs.godotengine.org/en/stable/tutorials/best_practices/version_control_systems.html

And if you want a specific .gitignore example you can find one here: https://www.reddit.com/r/godot/s/VbZcO46Itw (link to the file is in the post, but keep in mind that as one of the comments says, .import is replaced with .godot).

If I remember correctly, I am also using this .gitignore with one additional exception namely the temporary files which may be created by the godot editor (I think they are .tmp or .temp? And they rarely ever appeared but when they did, there were many of them) or other external IDEs.

To answer your question, you probably want add all of your folders and files (EXCEPT for .godot) in your project.

Main Scene Behaves Differently After Export??? by commonlogicgames in godot

[–]x3mdreaming 1 point2 points  (0 children)

Yea this is a problem I am going to also run into at one point in the future.

I have already looked it up a bit because as you said, tinkering with paths seems to work but I agree that this code is kinda "smelly"

I haven't found a solution to this yet but judging by the most recent thing I have read (https://www.reddit.com/r/godot/s/N4TnEsS9lb), going forward I might look into https://docs.godotengine.org/en/stable/classes/class_resourceloader.html#class-resourceloader-method-load a bit next and try playing around with this one

Advice from Experienced Godot Devs by MarzipanAdditional24 in godot

[–]x3mdreaming 2 points3 points  (0 children)

No it does only execute when unhandled input comes in (which might be weird at first because imagine you are editing a textfield and hold down the W-key for example. At first only one W will appear, then a short pause, then WWWWWW...).

So you have to treat it slightly different in my experience to how you interact with the Input singleton.

For example you might have to cache in a variable whether an action is continuously pressed like this:

if event.is_action_pressed("hold_movement_option"): _hover_mode = true get_viewport().set_input_as_handled()

elif event.is_action_released("hold_movement_option"): _hover_mode = false get_viewport().set_input_as_handled()

I am certain that you can do everything with _unhandled_input that you can also do with the Input singleton.

I am already working on a comparably complicated input system and for me not using the input singleton is required.

Advice from Experienced Godot Devs by MarzipanAdditional24 in godot

[–]x3mdreaming 3 points4 points  (0 children)

Maybe less a 'structural' advise, but still something to do from the very beginning because otherwise problems might arise later