本文轉自:https://docs.uipath.com/studio/docs/state-machinesnode
A state machine is a type of automation that uses a finite number of states in its execution. It can go into a state when it is triggered by an activity, and it exits that state when another activity is triggered.express
Another important aspect of state machines are transitions, as they also enable you to add conditions based on which to jump from one state to another. These are represented by arrows or branches between states.app
There are two activities that are specific to state machines, namely State and Final State, found under Workflow > State Machine.dom
You can only create one initial state, yet it is possible to have more than one Final State.ui
The State activity contains three sections, Entry, Exit and Transition(s), while the Final State only contains one section, Entry. Both of these activities can be expanded by double-clicking them, to view more information and edit them.this
The Entry and Exit sections enable you to add entry and exit triggers for the selected state, while the Transition(s) section displays all the transitions linked to the selected state.3d
Transitions are expanded when you double-click them, just like the State activity. They contain three sections, Trigger, Condition and Action, that enable you to add a trigger for the next state, or add a condition under which an activity or sequence is to be executed.code
To exemplify how to use a state machine, we are going to build the guessing game we did in the previous chapter, the only difference being that we will try to guess a number between 1 and 100.orm
You can also add a State Machine activity to the Designer panel to create a new state machine automation.blog
InitialGuess
and RandomNumber
. The first variable stores your guess, while the second stores the random number.RandomNumber
variable.new Random().Next(1,100)
. This expression generates a random number.InitialGuess
variable. This variable stores the user’s guess.InitialGuess
> RandomNumber
. This verifies if the user’s guess is bigger than the random number.InitialGuess
< RandomNumber
. This verifies if the guess is smaller than the random number.InitialGuess
= RandomNumber
. This is the condition on which this automation steps to the final state and end.RandomNumber.ToString
+ "." This is the final message that is to be displayed, when the user correctly guesses the number.
另:
https://www.jianshu.com/p/8d77459c69d2?from=timeline&isappinstalled=0