So I keep driving myself a little nuts on debating how to handle this... I initially thought of state management as something for only actors and players so I would do this for my actor script that would be used by the player and enemies...
class_name Actor
extends KinematicBody
var state = "" setget set_state, get_state
var physics_state = "" setget set_physics_state, get_physics_state
var previous_physics_state = ""
var previous_state = ""
var previous_health = 0
func _process(delta):
if state != "" and has_method(state):
call(state, delta)
func _physics_process(delta):
if physics_state != "" and has_method(physics_state):
call(physics_state, delta)
func set_state(method):
emit_signal("state_changed", method)
previous_state = state
state = method
if method != "" and !has_method(method):
print("state [" + method + "] does not exsist!")
func get_state():
return state
func set_physics_state(method):
emit_signal("physics_state_changed", method)
previous_physics_state = physics_state
physics_state = method
func get_physics_state():
return physics_state
And know after restarting a project I'm thinking of doing it this way since maybe I would want a state management for more than just players and enemies....
class_name States
extends Node
export(String) var active setget set_active, get_active
func set_active(a):
active = a
var children = get_children()
print(children)
for c in children:
if c.name == active:
c.set_pause_mode(Node.PAUSE_MODE_INHERIT)
else:
c.set_pause_mode(Node.PAUSE_MODE_STOP)
func get_active():
return get_node(active)
Idk Probably doesn't really matter...Maybe both may be useful. Guess I'll flip a coin lol. And really state machines is just a simple concept for programming, this may be like coming up with a for loop machine or something...Then I run into where with the second method is more visual in the scene, but more cross referencing with nodepaths, where the first is a bit less work after implementation. You guys have any preferences?
Edit: What other things you guys get into a self debate over whether to use something as a separate node or something your script inherits? I been using godot for a year so I haven't really developed any real consistent habits yet like I have with GameMaker.