'Netlogo: move to a specific patch
I am gonna ask a simple question. I have workers and patches. Workers want to go to a specific patch, labeled by an id. I tried the following code, but it does not work. Can someone help me? Thanks
workers-own[selected-area]
patches-own [id]
ask workers [
move-to one-of patches with [id = selected-area]]
Solution 1:[1]
In your example you have two important variables. selected-area, which is a turtles-variable, and id, which is a patch-variable.
Each agent (patch or turtle) can access its own variable, but not those of the others. The problem here, is that you ask the patches to compare id to selected-area, but patches don't have a variable called selected area so the program doesn't work.
The current structure of your program is:
- Observer gives command to all agents (2)
- Every agent gives a command to all patches (3)
- Every patch tries to compare id to selected-area
A very nice tool for these sorts of situations is myself. Myself refers to the agent that asked you to do what you are currently doing, the one who is 1 level above you. In this case, it will allow the patch to check the turtle's variables.
ask workers [
move-to one-of patches with [ id = [ selected-area ] of myself ] ]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
