Skip to content

New extension: State Machine#831

Open
github-actions[bot] wants to merge 1 commit intomainfrom
extension/infokub/830
Open

New extension: State Machine#831
github-actions[bot] wants to merge 1 commit intomainfrom
extension/infokub/830

Conversation

@github-actions
Copy link
Contributor

Description

This extension provides a way to manage Finite State Machines for Scene and Objects with a Behavior.

You can:

  • Add as many states as you want
  • Connect states together
  • Manage transitions easily
  • Support start/stop events
  • JSON import/export available

(help link is broken until i publish the State Machine Editor, which is ready, but i wait the review here to publish it)

How to use the extension

After you added the extension to your project:

Configuration

If you use it for the scene

  • Start the state machine with your first state
  • Add as many states as you want to the machine
  • Then connect them together

If you use it on an object

  • Set a start state in the Configuration, or Add the state then Set the machine to it afterward
  • Then add and connect states

You can also use the State Machine Editor to have a GUI and not do all of this by hand:
https://gd.games/instant-builds/abbfb1bb-1696-4ac5-a839-281f3cfe537f

Manage states

When your machine is started, here are the good practices for an easy use:

  • Check what is the current state
    • Test if the state begins
    • Do the state actions
    • Verify if the state can use a transition to an other state + other required conditions
      • Accept the transition
    • Test if the state ends

You can then group your events by state.

Checklist

  • I've followed all of the best practices.
  • I confirm that this extension can be integrated to this GitHub repository, distributed and MIT licensed.
  • I am aware that the extension may be updated by anyone, and do not need my explicit consent to do so.

What tier of review do you aim for your extension?

Reviewed

Example file

state_machine_editor.zip

Extension file

StateMachine_0.0.1.zip

@github-actions github-actions bot requested a review from a team as a code owner March 26, 2023 02:59
@github-actions github-actions bot added the ✨ New extension A new extension label Mar 26, 2023
@github-actions github-actions bot mentioned this pull request Mar 26, 2023
3 tasks
@github-actions github-actions bot changed the title New extension: <title> New extension: State Machine Mar 26, 2023
@Oxey405
Copy link
Member

Oxey405 commented Mar 28, 2023

That looks very promising ! I will test it fully later this week but the gd.games example build looks very very promising !
I have a few questions :

  • Can you add a condition for a state to trigger ? / How do you trigger a state ?
  • Is the state machine calculated efficiently enough to be used 60 times a second even on a mediocre computer ?

@D8H
Copy link
Contributor

D8H commented Mar 28, 2023

This extension is interesting but I'm not sure to understand how it can be used.

For scene switching, I see the "change the scene" actions as transitions already. Scenes usually are changed with a value directly so it can't be a forbidden transitions.

Is it for procedurally generated levels that are split into scenes as a maze?

I usually do FSM inside a scene. I create a dedicated extension with a condition to check the state and one action to do transition. This way I can easily add new states and eventually add some checks if needed. For more complicated FSM, actions can be added to follow more complex states and maybe handle transitions internally.

This last point is very important for FSM on objects. Handling the transitions internally allows a good encapsulation and reusable behaviors. Which is not possible with a general purpose FSM.

Can you explain with practical cases how you see this extension being used?

@infokub
Copy link
Contributor

infokub commented Apr 9, 2023

Thanks for your comments.
I'm SORRY bc i expected GitHub to tell me i had comments on this extension :(

@Oxey405 you can brutally set the state yourself, there is an action for that, and it should not be used bc it will break the state flow. But still doable.
There are no auto calculation, so yes it run smoothly. You need to ask if a transition between your state and an other is possible (it will only check if the state is in the transition list) then if it meets your condition, you can authorize the transition and it will move to the next state at the start of the next frame.

You are, or are not in a state, and you can only have one state (per machine) at once, so no heavy calculation here.

@D8H there are many practical cases :

  • IA : when you want a NPC to follow a waypoint track for example, it will be easier to think it as stated environement : first, idle state, it gets the waypoint, then follow state, it uses navigation to reach the destination, then come back to idle state.
    So it can be also used for many other things IA related. I made an example game where the character plays the game by itself. i can publish it. For sim games, or strategy games, having FSM to describe every IA behavior is very common.

  • UI : locking your UI depending on the state it is, is very useful. That's what you see in the example i provided : when you open the export panel, it locks everything else so you can't move or change any state button. I made it using the FSM.

@VegeTato VegeTato added the 🔍 Reviewed extension An extension that is to be reviewed in great detail before merging. label Jun 13, 2023
@arthuro555 arthuro555 added 🧪 Experimental extension An extension submission to be merged with a lightweight review. and removed 🔍 Reviewed extension An extension that is to be reviewed in great detail before merging. labels Dec 16, 2024
@arthuro555
Copy link
Member

Ping @D8H, it seems you missed the answer from infokub

@arthuro555 arthuro555 added the ⏱ Waiting for reviewer attention A reviewer needs to come take (another) look at this submission label Dec 16, 2024
@GustavoMarciano
Copy link

I have been using this extension for years and it has not been reviewed yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🧪 Experimental extension An extension submission to be merged with a lightweight review. ✨ New extension A new extension ⏱ Waiting for reviewer attention A reviewer needs to come take (another) look at this submission

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants