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

    Droidz

    Posted

    Hi, you get same problem with "OnStartEngine"? You can also try to use "OnAddState" when  bot add "Idle" (it is all time last state)

    Matenia

    Posted

    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

    Matenia

    Posted (edited)

    OnAddState does not work it seems. It's never called inside the plugin.
    OnStartEngine, all states are missing. 

    Edited by Matenia
    Droidz

    Posted

    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 { }
        };

     

    Matenia

    Posted

    Thank you, I did something similar but this should help in case it reloads the engine (Quester reload etc).



    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...