+1 vote

Hello again, sry for my stupidness.
I have variable in a script
enter image description here
I try to use variable from near of class, but can't do that. I trying to find documentation where describes that situation but I failed.

Thank you so much for helping to noobs!

in Engine by (38 points)

1 Answer

+1 vote
Best answer

I don't believe you have access to that property inside your object class. I think the solution here would be to pass a reference to the outer class/object into your change method:

class Fsm:
    var state = EState.IDLE
    var substate = EState.IDLE

    func _init():
        print("fsm controllable")

    func change(newState, obj):
        state = newState
        match state:
            EState.MOVE:
                print("FSM: move")
                obj._is_moving = false
            EState.IDLE:
                print("FSM: idle")

then in your outer class, you can do:

var _is_moving = false
var fsm = Fsm.new()

func _ready():
    fsm.change(EState.MOVE, self)
by (1,650 points)
selected by
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.