I am trying to access a function inside of an instanced scene. Godot 3

Godot 3.5 (Stable)

Hello, I am new here, and this is my very first post.

I am trying to create a state machine, and the way I want to implement it is
by creating my own functions inside of it to try to imitate Godot’s approach (Methods from Built-in nodes).

I’m trying to access a variable from inside the node using functions:
get_state() and set_state(), similar to that of Godot’s methods.

It accepts parameters.

However it returns null, but it doesn’t seem to stop the game from running? which confuses me.

extends Node2D #This is the state machine 

onready var _state_ :String #the variable that we try to get with get_state()

func get_state():#a function for retrieving states from here as output
	
	return _state_
i
func set_state(state:String): #a function for getting states as input
	
	if _state_ != null:
		return _state_

Anyways, I can try to access (state) variable directly itself. But I wanted to do it inside a function.

$StateMachine._state_ = "sample state" #Directly change the _state_ var

Is there a way to do what I’m trying to achieve? 'trying to do it this way for the sake of code clarity, as I believe things will be more clear this way.

Ya, set_state does not set anything.