If Else: Difference between revisions
(Marked this version for translation) |
(updates from Blockument) |
||
Line 3: | Line 3: | ||
<!--T:2--> | <!--T:2--> | ||
<p id="tooltip">Test for something. If true, then the agent follows the commands in the first hook. If false, then the agent follows the commands in the “else” hook.</p> | <section begin="image"/>[[File:if_else.png|alt=The If Else Block|thumb]]<section end="image"/><p id="tooltip">Test for something. If true, then the agent follows the commands in the first hook. If false, then the agent follows the commands in the “else” hook.</p> | ||
==Syntax== | |||
Inputs in this block: | |||
#a comparative statement block ([[Special:MyLanguage/Equals|=]] statements, [[Special:MyLanguage/Greater Than|>]] statements, [[Special:MyLanguage/Not|not]] statement, [[Special:MyLanguage/And|and]]/[[Special:MyLanguage/Or|or]] statements) | |||
==Example== | |||
[[File:if_else_example.gif|alt=If Else example gif|thumb]] | |||
[[File:if_else_example.png|alt=If Else example code|thumb]] | |||
This is a model of a hungry frog attempting to catch two different types of fly. While ‘fly around’ is toggled, the frog moves toward the closest fly. The fly detects whether the frog is nearby and will move in the opposite direction. The if else block is used to determine the speed of each fly based on the size of each agent. In this case, large flies are fast, whereas small flies are slow. It can be seen from the line graph that the population of the larger, faster flies falls more slowly than the smaller, slower flies. | |||
<!--T:1--> | <!--T:1--> |
Revision as of 14:48, 14 August 2023
Test for something. If true, then the agent follows the commands in the first hook. If false, then the agent follows the commands in the “else” hook.
Syntax
Inputs in this block:
Example
This is a model of a hungry frog attempting to catch two different types of fly. While ‘fly around’ is toggled, the frog moves toward the closest fly. The fly detects whether the frog is nearby and will move in the opposite direction. The if else block is used to determine the speed of each fly based on the size of each agent. In this case, large flies are fast, whereas small flies are slow. It can be seen from the line graph that the population of the larger, faster flies falls more slowly than the smaller, slower flies.