If Else/en: Difference between revisions
(Updating to match new version of source page) |
(Updating to match new version of source page) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
<languages/> | <languages/> | ||
<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. | |||
[[Category:Logic]] | [[Category:Logic]] | ||
[[Category:Code Block]] | [[Category:Code Block]] |
Latest revision as of 15:20, 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.