Jump to content
  • Add event handler or hook to add new state safely


    Matenia
    • Product: WRobot General Type: Bug Status: Unconfirmed

    Right now, I use FiniteStateMachine Events and add new states. This causes issues when not all states have been loaded correctly and for some people if the Quester uses a LoadProfile or Reload step, it "breaks" the FSM context because state are already added. 

    Can you add some method I can utilize to add states to the FSM, for example "aftersuccessfulstart" or something?



    User Feedback

    Recommended Comments

    and code like:

    Engine lastEngine = null;
    robotManager.Events.FiniteStateMachineEvents.OnBeforeCheckIfNeedToRunState +=
        delegate(Engine engine, State state, CancelEventArgs cancelable)
        {
            try
            {
                if (engine == null || engine.States == null)
                    return;
    
                if (engine != lastEngine)
                {
                    if (engine.States.Any(s => s is Idle))
                    {
                        lastEngine = engine;
                        engine.AddState(new MyCustomState()); // or engine.States.Insert(X, new MyCustomState());
                        // cancelable.Cancel = true; ??
                    }
                }
            }
            catch { }
        };

     

    Link to comment
    Share on other sites


    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...