0 votes

Sorry if I'm not very clear, but I'm quite new.
As for the question, here's an example:

I have a whole bunch of sprite nodes that I want to hide through script, so I write a function

func _hide_this_node(the_node):

I was hoping to use this for a state machine technique I saw on Youtube where classes act as different states, but to use the "change state" function, that function must use a if else/switch statement to check the state you want to instantiate.

func set_state("the name of the new state"):
    Exit current state
    if the name of the new state = state1, then state1.new()
    elif the name of the new state = state2, then state2.new()

and so on

So to prevent the is else hassle, I would simply use

var state = Idle.new()

class Idle
class Run

func set_state(reference):
    Exit current state

so an example would work out like


And the function would instatiate whichever class I typed as a reference

in Engine by (12 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.