Ally
Ally

Reputation: 65

How to set color of turtles made by slider?

I'm trying to create a simulation where there are zombies and human turtles that move around the world. I'm using 2 sliders to create different numbers of zombies and humans. I want to set the color of zombies to green and humans to red. Here is my code so far:

 to setup
 cro Zombies
 cro Humans
 ask turtles [set shape "person"]
 end 

I'm not sure how I would be able to set the color of zombies and humans since they are only interpreted as numbers and I can't use:

ask Zombies [set color green]

Any ideas are appreciated thanks!

Upvotes: 0

Views: 33

Answers (1)

Luke C
Luke C

Reputation: 10301

Is there any reason you don't want to use breeds? It would probably make your life a lot easier in the long run. For example, this basic setup has two sliders like yours, but note that they are called "n-Zombies" and "n-Humans":

breed [ zombies zombie ]
breed [ humans human ]

to setup
  ca
  set-default-shape turtles "person"
  ; create a number of zombies set by the "n-Zombies" slider
  create-zombies n-Zombies [
    set color green
    setxy random-xcor random-ycor
  ]
  ; create a number of humans set by the "n-Humans" slider
  create-humans n-Humans [
    set color red
    setxy random-xcor random-ycor
  ]
  reset-ticks
end

Gives you something like:

enter image description here

Upvotes: 2

Related Questions