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


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

    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?


     Share


    User Feedback

    Recommended Comments

    When I use OnStartEngine, none of the states have been added yet and I need to get their priority (and in some cases, I need to add NextStates).
    I will try OnAddState I think

    Link to comment
    Share on other sites

    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



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...