Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query state #7

Open
WinstonHartnett opened this issue Jun 24, 2020 · 2 comments
Open

Query state #7

WinstonHartnett opened this issue Jun 24, 2020 · 2 comments

Comments

@WinstonHartnett
Copy link

Is there any way to query the state of a machine directly (e.g. without manually setting an extra flag)?

@mratsim
Copy link
Owner

mratsim commented Jun 27, 2020

No there is no way, in the generated code the "state" doesn't exist even in memory it's simply the location of the code you are in. For example in pseudo code

type
  GrabLunch = enum
    OpenTheDoor
    WalkToRestaurant
    OrderDish
    WalkBack
    HaveLunch
    Exit

Would become

proc grabLunch(restaurant: Restaurant) =
  block OpenTheDoor:
    discard
  block WalkToRestaurant:
    if restaurant.isClosed():
      goto WalkBack
    else
      goto OrderDish
  block OrderDish:
    discard
  block WalkBack:
    if restaurant.isClosed():
      goto Exit
    else:
      goto HaveLunch
  block HaveLunch:
    discard
  block Exit:
    discard

The various states are just labels of code sections and are not materialized.

That said you always know when you are in a certain state.

Do you need something like a currentState() function?

@WinstonHartnett
Copy link
Author

Ah, I see. Yes, a currentState function would be helpful.

I am hoping to use Synthesis for FSMs in a quick game I am writing with the Godot game engine Nim bindings. Sometimes, different code needs to run continuously at a different rate than the FSM's synthesize proc, which would be easy with a currentState function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants