Reputation: 620
I want to position my turtles in a certain squared location. Why does this code below not work? Netlogo accepts it, but does not compile, saying "can't set turtle variable XCOR to non-number false" It should be pretty simple, but I somewhat can't get around it.
crt 50
[
set size 2
set xcor xcor >= 81 and xcor <= 90 ;set initial location
set ycor ycor >= 81 and ycor <= 90 ;of turtles
set start-patch patch-here
pen-down
]
Upvotes: 1
Views: 4940
Reputation: 14972
The error message pretty much says it all: set xcor
should be followed by an expression that evaluates to a number. In your code, however, set xcor
is followed by a boolean expression (i.e., something that evaluates to true
or false
): xcor >= 81 and xcor <= 90
.
In other words, xcor >= 81 and xcor <= 90
does not mean "give me a number between 81 and 90", it is a question meaning "is xcor between 81 and 90?" and NetLogo does not know how to set xcor
to the answer to this question.
If you want NetLogo to give you a number that is in a certain range, you generally need to use the random
function. In your case, you could simply do:
set xcor 81 + random 10
set ycor 81 + random 10
Note that random
will only give you integers. If you wanted your turtles to be at non-integer coordinates, you could use random-float
instead.
Upvotes: 4