Trying to build a rough and ready state machine using parapoly, but I've gone wrong. I get "'sm' of type '^StateMachine' has no field 'previousState'", presumably because I need to attach the specific state type maybe (that's what it implies when I pass by copy, but I do need pass by reference). I've been following the Overview for this but I've interpreted it wrong, any advice appreciated
package main
import "core:fmt"
MyStates :: enum
{
Start,
Middle,
End
}
StateMachine :: struct($State: typeid)
{
currentState: State,
previousState: State,
transitionProc: proc(s: State) -> State
}
NextState :: proc(sm: ^StateMachine)
{
sm.previousState = sm.currentState
sm.currentState = sm.transitionProc(sm.currentState)
}
SetState :: proc(sm: ^StateMachine, $State: typeid)
{
sm.previousState = sm.currentState
sm.currentState = State
}
main :: proc()
{
sm := StateMachine(MyStates){
currentState = MyStates.Start,
previousState = MyStates.End,
transitionProc = proc(state: MyStates) -> MyStates {
switch state
{
case MyStates.Start: return MyStates.Middle
case MyStates.Middle: return MyStates.End
case MyStates.End: return MyStates.Start
}
return MyStates.End
}
}
NextState(&sm)
fmt.printf("%v", sm)
}