RavioliMavioli / malware-slayer

Action platformer and terminal simulator game made in Godot Engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve hook mechanic

RavioliMavioli opened this issue · comments

The hook mechanic is so janky. I will probably left it there for few months while doing other main features.

The hook mechanic is supposed to work similar to the one in the "Rusted Moss"
Example below:

The current implementation is still very limited and for a lack of better word; funky and janky

Fixed
@dfgworm did an amazing job for creating a better hook mechanic,
But it will still get more improvement later, until then the issue will still be open.

@dfgworm By the way, the method that you use to cache nodes into variables is by using get: return node instead of putting directly on to @onready var. I would like to know why the getter method is the preferred way.

commented

I would like to know why the getter method is the preferred way

One reason is the ease of transfering nodes around. If you just get it using @onready, you won't be able to move the node during runtime without completely breaking all references in and out of this node.
Also there is the argument of error tolerance. In case of anything going wrong, active getter actually has a chance to fix itself.

I actually had a case in my project where @onready did not work at all. I had to do some things in _ready in one component, and @onready of another component did not yet happen, so it still had some nulls when i needed it. It worked fine with active getters. Another way to fix that would be to defer _ready code, but that could potentially cause other ordering issues.

All of this might be particularly relevant to your character selection mechanic.
In the end there is just no downside to doing it this way.

you use to cache nodes into variables is by using get: return node

This is actually the opposite of caching, since i just get the node every time it is needed without saving it anywhere. I'd call it a statically typed shortcut.