All Questions

Community

N
Jakob Nyström
posted to: Coding the State

Releationship state - statemachine

Can you elaborate on the way to set the node references inside the scene.

Here the State searches up in the tree instead of statemachine traversing down and assigning itself as reference.

When it comes to scene organization I guess this would be the job of the parent to set this reference.



  • Nathan Lovato replied

    Hi Jakob,

    I think ideally, you would want not to have that reference on the states. Have them either emit a signal or return a value from their virtual functions, like the name of a state, triggering a state change. That'd increase encapsulation. The way we have it just a tiny bit more convenient.

    Then, sure, you can let and might want to let the state machine pass itself to its children. That would probably be the way to do it with object-oriented programming. Razvan, who wrote this code, has a lot of experience with the functional programming paradigm, where the rules can get quite different, hence the recursive function that looks up for a state machine.

    Another alternative would be to state machine as a scene, this way all the state nodes' owner would be the StateMachine automatically. I think I did this for a previous course.

  • N
    Jakob Nyström replied

    Thanks. Your suggestions makes sense.

    I will probably allow some convienience inside a scene, then go for stricter coupling and ecapsulation scene to scene interaction.

    Scene organization is described in the Godot docs but I think this topic could have some more coverage, examples on different approaches.