Question

I am trying to find if there is a turtle on patch-ahead n

whose speed - acceleration is <= 0. The code I came up with is:

if any? turtles on patch-ahead n with [speed <= (speed - acceleration)]

but this gives an error that:

patch-ahead expects a number, instead got agent set.

How do I remedy this?

n is a number variable. I want to access the turtle's 'speed', which is a user defined turtle-own variable, at the nth patch from the calling turtle. The command 'with' doesn't work here. Please suggest an alternative to access the speed of the turtle at, say, the 3rd patch from the calling turtle.

Was it helpful?

Solution

If you look at the patch-ahead documentation you will notice that it does require one argument: a number representing the distance to look ahead. You are using a patch 'n' instead of a number.

As per you comment, I think maybe you want turtles-on, and use parenthesis to make it clearer, as such:

if any? ((turtles-on patch-ahead n) with [speed <= (speed - aceleration)])

In the above I am assuming that n is a number: the distance you want to look ahead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top