Can I disable a specific function instead of repetitively checking if ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Multirious

Just curious if you can disable a function, so you don’t have to constantly check for something. It might be more efficient but Idk.

Instead of this

func _process(delta: float) -> void:
	if stopped:
        move(delta)


func move(delta: float):
    var collider = move_and_collide(dir * speed * delta)
    if collider:
        stopped = true

Something like this

func _physics_process(delta: float) -> void:
    move(delta)


func move(delta: float):
    var collider = move_and_collide(speed * delta)
    if collider:
        disable('move')
:bust_in_silhouette: Reply From: Wakatta

You dare insult the use of logic gates…

What you want to do can be done with some overrideable functions such as, set_process(false), set_input(false) and the same can be achieved using groups

add_to_group("moveable")

func _physics_process(delta: float) -> void:
    get_tree().call_group("moveable", delta)

func move(delta: float):
    var collider = move_and_collide(speed * delta)
    if collider:
        remove_from_group("moveable")

Or even better with signals. To be honest you’re over complicating what can easily be achieved with a well placed if-else-then statement.

The best possible workflow for your intentions are State Machines so also have a look at that

I’m not entirely sure why is this question insulting the use of logic gates…
But, State Machines would probably work.

Multirious | 2021-08-06 06:05