Blueprint Basics (3) - Branches and Loops

Brief introduction
Branches and loops are essential in all development languages. They can effectively control the flow of program execution. They are implemented by some branch and loop nodes in the blueprint.
Right-click -> Utilities -> Flow Control to pop up some standard flow control nodes, as shown in the figure
(1), Branch
Branch is a judgment node. When the input parameter Condition is true, the program takes the True branch, otherwise it takes the false branch.
For example, when Condition is checked, the program will take the True branch and print "True branch"
output result

(2) Delay
delay node, when the program executes to this node, it will block for a period of time and then run, a bit like the sleep function.
For example, set a delay of three seconds before printing data, and no input is accepted during the delay

Output the result, and print it three seconds after the event is triggered

(三)、Do N
This node will control the number of executions. If the set number of times is exceeded, the node will not receive any input unless the node is reset (Reset).
For example, set the number of executions N to 3, then the node will execute at most three times

Press the "1" key to trigger, it will output the number of times of the current line, if more than three times, the node will not be executed when the "1" key is pressed

If you want to execute it again, you must reset the Do N node, reset it by pressing the "2" button, and press the "1" button again to execute the node.

(4), DoOnce

This node is similar to Do N, which is equivalent to setting N to 1 in Do N, and there is an additional input parameter of type bool Start Closed, which is true by default. The node is closed at the beginning and needs to be reset before execution.
For example, at the beginning, the node will not be executed by pressing the "1" key, and the DoOnce node must be reset by pressing the "2" key.

Press the "1" key again, the node will execute and print "Hello"

(5), DoOnce MultiInput

This node can add multiple branches relative to DoOnce. Similarly, it needs to be reset before executing it again.
For example , add several branches to the node. When the node is executed, execute the corresponding output branch according to the input branch, and press the "1" key. When executing the output branch A Out corresponding to the input branch A ln, if you want to execute other branches again, you must press the "1" key to reset the node. Repeatedly

output result

(6), FlipFlop

This node has two output branches. When called for the first time, A will be output. When the second call is made, B is output, and a bool value is output to determine whether to output A. If A is output, the value is true, otherwise it is false.
For example, connect two output nodes and print the return value Is A

Press the "1" key multiple times to output the result

(7), ForLoop

This is a loop node. The class uses a for loop to control the number of loops by setting the first index (First Index) and the end index (Last Index). Each loop will output the subscript Index of the current loop, and output after the loop ends. Go to the Completed branch and end the loop.
For example , set the First Index to 0, the Last Index to 100, and print the Index value of each loop, and finally print "Completed"

(八)、ForLoopWithBreak
This loop node adds an input branch Break based on the ForLoop node, and executing Break can jump out of the current loop
For example, when index is greater than 50, the loop ends. Each loop in the program will first judge whether the index is less than 50. If so, execute the print string node and print the index, otherwise execute the Break branch in the ForLoopWithBreak node, and the loop ends.
output result
(9) The Gate
node is similar to a switch. It has four input branches. Enter, Open, Close, Toggle, and
Enter are the execution branches. Only from this node can the output be executed.
Open, open the node and execute Liu
Close, close the node. Execute the flow
Toggle switch, in the two states of Open and Close, it will switch
Start Closed to close by default.
For example
result output
(10) Each time MultiGate
is executed, it will output from a branch. When the input value Is Random is Treu, the output branch is random. When the input value Loop is True, the node can loop multiple times, and vice versa.
For exampleWhen all Loops are flase, the four output branches will be output in order from small to large, and only one round can be output.
result output
When both Is Random and Loop are set to True, the four output branches will output randomly, and only multiple rounds
of result output will be output
(11), Retriggerable Delay
This node is similar to Delay, the only difference is that it can be triggered again.
For example
Repeatedly press the "1" key within 5 seconds, the Retriggerable Delay will be triggered repeatedly, and the timer will be reset to zero again, so that the output cannot be output.
After the Delay node is triggered, it will not receive new input. Only when the time is up, the node will receive input after
outputting . Repeatedly press the "1" key within 5 seconds, and the time of the first trigger shall prevail. 5 seconds, the result is output
(12), Sequence
This node can be connected to multiple outputs, and executing this node can output multiple branches,
result output
(13), The incoming parameter of the WhileLoop
node is bool type, ture is the loop, and flase is the exit loop, similar to the while loop.
For example, start the loop,
uVal will be decremented by 1 for each loop, know that uVal is less than or equal to zero, exit the loop, and execute Combined
result output

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325728562&siteId=291194637