Reputation: 29
I am just learning to use netlogo, and I was trying to code a simple model to have different agents [breeds] perform different tasks. The agents that appear on the interface/universe are selected with a chooser...
This is what I wrote in my code:
breed [escarabajos escarabajo]; type of beetles that survive in forests
breed [beetles beetle]; type of beetles that survive in agricultural areas
;For each breed there are three sub-types of beetles, depending on how far they can move (vagility) this is also selected with a chooser.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SETUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
ca
setup-patches
set-default-shape turtles "bug"
ask turtles [create-bichos]
reset-ticks
end
to setup-patches
ask n-of 100 patches [ set pcolor green ]
ask n-of 500 patches [set pcolor yellow]
end
to create-bichos
if breed = "escarabajo" [
ask patches with [ pcolor = green ] [
let k forest-carrying-capacity ; what I want is to create the maximum amount of beetles ;possible per patch, and this maximum is determined with a carrying capacity value, which is set ;with a slider....
sprout-escarabajos k [set color 116 set size 6]
]
]
if breed = "beetle" [
ask patches with [ pcolor = yellow ] [
let k agricultural-carrying-capacity
sprout-beetles k [set color 76 set size 6]
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
if ticks = 72 [stop]
ask turtles [rt random 360
move
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;; PROCEDURES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to move
if vagility = "High"
[ask turtles [
move-to one-of patches in-radius 2
]
]
if vagility = "medium"
[ask turtles [
move-to one-of neighbors
]
]
if vagility = "low"
[ask turtles [
move-to one-of neighbors4
]
]
end
Like I said, the code doesnt seem to have any problem, but when i hit the setup button, only the different colored patches appear...
Upvotes: 0
Views: 158
Reputation: 17678
You have the line ask turtles [create-bichos]
. This has three problems. (1) You don't have any turtles yet, so there are no turtles to ask, so the create-bichos procedure is not called. (2) If you did have some turtles already, then EACH of those turtles would call the procedure, so they would be asking the patches to do things multiple times. (3) breed
is an attibute of turtles, you can't use it as the name of the chooser.
As a learner, you need to write smaller bits of code and make sure each one works before moving on. So let's imagine that you start by creating the turtles (since that's your question) and your chooser is called 'breed-select'. The solution is to simply remove the ask turtles
, but as a first pass you should simply create a fixed number of turtles before introducing more code.
breed [escarabajos escarabajo]; type of beetles that survive in forests
breed [beetles beetle]; type of beetles that survive in agricultural areas
to setup
clear-all
setup-patches
set-default-shape turtles "bug"
create-bichos
reset-ticks
end
to setup-patches
ask n-of 100 patches [ set pcolor green ]
ask n-of 500 patches [set pcolor yellow]
end
to create-bichos
if breed-selector = "escarabajo"
[ ask patches with [ pcolor = green ]
[ sprout-escarabajos 5 [set color 116 set size 6]
]
]
if breed-selector = "beetle"
[ ask patches with [ pcolor = yellow ]
[ sprout-beetles 5
]
]
end
Upvotes: 1
Reputation: 1
Use the create agent command create-escarabajos <number>
or create-beetles <number>
to create new agents of your custom breeds
Upvotes: 0