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

Initial state never executed #428

Open
ErwinDraconis opened this issue Feb 10, 2021 · 1 comment
Open

Initial state never executed #428

ErwinDraconis opened this issue Feb 10, 2021 · 1 comment

Comments

@ErwinDraconis
Copy link

Hello,
i have the following fsm :

`enum State
{
HomePosition,
InPosition_1,
InPosition_2,
InPosition_3,
InPosition_4,
}

    enum Trigger
    {
        GoTo_1,
        GoTo_2,
        GoTo_3,
        GoTo_4,
        Go_Home,
    }`

the machine config is as follow :

`_fsm = new StateMachine<State, Trigger>(State.HomePosition);

        _fsm.Configure(State.HomePosition)
            .Permit(Trigger.GoTo_1, State.InPosition_1)
            .OnEntryAsync(async () => await GoToPosAsync(1));

        _fsm.Configure(State.InPosition_1)
            .Permit(Trigger.GoTo_2,State.InPosition_2)
            .Permit(Trigger.Go_Home, State.HomePosition)
            .OnEntryAsync(async () => await GoToPosAsync(2));

        _fsm.Configure(State.InPosition_2)
            .Permit(Trigger.GoTo_3, State.InPosition_3)
            .Permit(Trigger.Go_Home, State.HomePosition)
            .OnEntryAsync(async () => await GoToPosAsync(3));

        _fsm.Configure(State.InPosition_3)
            .Permit(Trigger.GoTo_4, State.InPosition_4)
            .Permit(Trigger.Go_Home,State.HomePosition)
            .OnEntryAsync(async () => await GoToPosAsync(4));`

when i fire the fsm automatically, 1 --> 2 --> 3 --> 4 , it always start from Position 2, ignoring the first one ? why is this behavior ?

hier is the dotgraph

image

Thanks for the help

@HenningNT
Copy link
Contributor

Stateless is (almost) entirely stateless, so it does not now when it's being configured, and when it's 'running'.
Because of this the initial transition of the 'starting' state is never executed.

You can circumvent this by putting the initial transition action in the OnActive handler, and call Activate when the state machine is fully configured and ready for action.
Another way is to add another state, and transition into the 'first' state, in your case HomePosition.

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