Need to get input for state machine

Godot Version

State Machine Base:

extends Node

class_name State_Machine

var CS : State
var NS : State

## Put parent here.

var parent

## Change new state, if current state is different to new state,
## then apply exit rules, change current state to new state, and apply enter rules.
func state_check() -> void:
	if (CS != NS):
		CS.exit()
		CS = NS
		CS.enter()
	return

## Apply state rules.
func state_process() -> void:
	NS = CS.process_event(get_process_delta_time())
	# FIXME: need to figure out how to get input to this.
	NS = CS.process_physics()
	return

## Force state change.
## NOTE: use only for switching to death states and things like that.
## Possibly could result in problems.
func state_forcechange(state: State) -> void:
	CS = state
	NS = state
	return

Player:

extends CharacterBody2D

class_name Player

# Regular variables.

@export var SS : State

const speed_walk : float = 300.0
const speed_run : float = 500.0

# Onready variables.

@onready var SM : State_Machine = $"State Machine"

func _ready():
	SM.CS = SS

func _physics_process(_delta) -> void:
	SM.state_process()
	SM.state_check()
	move_and_slide()
	return

Player State Machine:

extends State_Machine

func _ready():
	parent = $".."

Question

For my state machine in need to get player inputs to my process_inputs function but i'm not sure how to do that.

note here, I realise that i put the process delta in events and not physics and I changed that.

This is madness! What is wrong with:

func _ready() -> void:
	state_machine.current_state = starting_state

This shorthand is going to cause you all sorts of problems in the future.

Any way, each to their own.

I can’t see a process_input function in your code (or is it PI - oh it can’t be that, that is already a constant, prehaps PINP?). If you are just looking for how to get user input then the docs are very thorough.

You seem to be checking your state machine state_check in _physic_process. Do you really need to check this sixty times a second? Why don’t you just change state when it is called for by something else rather than continuously polling a change in new_state (or NS as you seem to prefer)? Whatever initiates the change of new_state could just as easily initiate an actual change_state function anyway.

2 Likes

It’s not called process_input but rather process_event, and I need to send an event/input in there.

I just used Input.whateverinputineed thing.