Create Each Do: Difference between revisions
No edit summary Tag: Reverted |
(Marked this version for translation) |
||
(40 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
<!--T:12--> | <!--T:12--> | ||
[[Category: Agents]] | [[Category: Agents]] | ||
<section begin=image/>[[File:Create Each Do.png|alt=The Create Each Do Block|thumb]]<section end=image/> | <section begin=image/>[[File:Create Each Do.png|alt=The Create Each Do Block|thumb]]<section end=image/><p id="tooltip">Creates the specified number of agents of the selected breed. Each newly created agent immediately follows the directions specified in "do".</p> | ||
<section begin="name" />'''<code>create [_] [▼](s) each do</code>'''<section end="name" /> is a [[code block]] part of the [agents] drawer. | |||
<!--T:22--> | |||
The created agents have the default shape, color, and size specified in their breed’s ‘Show Traits’ area. They are created in the middle of the terrain, on the ground (x=0, y=0, z=0), with their headings evenly distributed, starting at 0 degrees (e.g. if 4 are created, one will start out facing toward each of the 4 sides of spaceland.) The turtles then follow the instructions provided within the each do hook once. | |||
<!--T:21--> | |||
<section begin="name" />'''<code>create [_] [▼](s) each do</code>'''<section end="name" /> is a [[code block]] part of the [[agents]] drawer. | |||
<!--T:13--> | <!--T:13--> | ||
== Usage== | ==Usage== | ||
<code>create [_] [▼](s) each do</code> is used to populate [[Spaceland]] with [[agent]]s and then run a [[stack]] of code individually for each agent. This can be useful for making many agents and setting different [[trait]]s for each. | <code>create [_] [▼](s) each do</code> is used to populate [[Spaceland]] with [[agent]]s and then run a [[stack]] of code individually for each agent. This can be useful for making many agents and setting different [[trait]]s for each. | ||
<!--T:14--> | <!--T:14--> | ||
==Syntax== | |||
<code>create [Textbox: Number of Agents to Create] [Dropdown: Type of Agent](s) each do [code]</code> | [[File:Create Each Do Nums1.png|right|alt=The Create Each Do Block|thumb]] | ||
< | <!-- <code>create [Textbox: Number of Agents to Create] [Dropdown: Type of Agent](s) each do [code]</code> --> | ||
<!--T:19--> | |||
Inputs in this block: | |||
#a number in the socket | |||
#a breed from the dropdown menu | |||
#relevant code | |||
<br> | |||
==Example== <!--T:23--> | |||
<!--T:24--> | |||
[[File:create_each_do_example.gif|alt=Create Each Do example gif|thumb]] | |||
[[File:create_each_do_example.png|alt=Create Each Do example code|thumb]] | |||
<!--T:25--> | |||
When setup is pushed, The World creates 100 turtles, and each of those turtles follow the instructions within the “each do” block. In this example, each turtle takes on a random color and moves to a random position in spaceland. All turtles are created, change color, and relocate in one tick of the StarLogo clock. | |||
<!--T:15--> | <!--T:15--> | ||
==Nuances== | ==Nuances== | ||
<code>create [_] [▼](s) each do</code> is very similar to <code>[[create|create [_] [▼](s)]]</code>. Both create agents, but generally <code>create [_] [▼](s) each do</code> allows for more complex and powerful usages. | <code>create [_] [▼](s) each do</code> is very similar to <code>[[create|create [_] [▼](s)]]</code>. Both create agents, but generally <code>create [_] [▼](s) each do</code> allows for more complex and powerful usages. | ||
<!--T:16--> | <!--T:16--> | ||
==Related Blocks== | ==Related Blocks== | ||
*<code>[[create|create [_] [▼](s)]]</code> | *<code>[[create|create [_] [▼](s)]]</code> | ||
==Relevant Video Resources== <!--T:17--> | ==Relevant Video Resources== <!--T:17--> | ||
==Relevant Activities== <!--T:18--> | ==Relevant Activities== <!--T:18--> | ||
</translate> | </translate> |
Latest revision as of 18:02, 11 August 2023
Creates the specified number of agents of the selected breed. Each newly created agent immediately follows the directions specified in "do".
The created agents have the default shape, color, and size specified in their breed’s ‘Show Traits’ area. They are created in the middle of the terrain, on the ground (x=0, y=0, z=0), with their headings evenly distributed, starting at 0 degrees (e.g. if 4 are created, one will start out facing toward each of the 4 sides of spaceland.) The turtles then follow the instructions provided within the each do hook once.
create [_] [▼](s) each do
is a code block part of the agents drawer.
Usage
create [_] [▼](s) each do
is used to populate Spaceland with agents and then run a stack of code individually for each agent. This can be useful for making many agents and setting different traits for each.
Syntax
Inputs in this block:
- a number in the socket
- a breed from the dropdown menu
- relevant code
Example
When setup is pushed, The World creates 100 turtles, and each of those turtles follow the instructions within the “each do” block. In this example, each turtle takes on a random color and moves to a random position in spaceland. All turtles are created, change color, and relocate in one tick of the StarLogo clock.
Nuances
create [_] [▼](s) each do
is very similar to create [_] [▼](s)
. Both create agents, but generally create [_] [▼](s) each do
allows for more complex and powerful usages.