Dwayne Johnson
Dwayne Johnson

Reputation: 5

How to set up turtles between boundaries, on only colored patches?

I'm trying to set up turtles on only on the white patches. Which white patch doesn't matter. I want to do this by the use of coordinates (creating boarders), not the patch color. However, my code gives an error: "With expected this input to be an agentset, but got a number instead". Does someone knows what I'm doing wrong? Thanks in advance!

Upvotes: 0

Views: 74

Answers (1)

Luke C
Luke C

Reputation: 10301

setxy only takes two arguments- an x value and a y value. You are passing it invalid calls to random-xcor and random-ycor. Instead, you likely want to generate random numbers within a range (for example, > -1 and < 6 for x). There are several ways to do this, but the easiest is probably using something like random or range:

A random version:

setxy ( 0 + random 6 ) ( 5 + random 1 )

A range version:

setxy one-of (range 0 6) one-of (range 5 7)

As an aside, you can streamline your setup call a little by extending your with statement to include both pxcor and pycor arguments:

  ask patches with [ pxcor >= 0 and pxcor < 6 and pycor >= 5 and pycor < 7 ] [
    set pcolor white 
  ]

Upvotes: 2

Related Questions