Akshansh Vaid
Akshansh Vaid

Reputation: 13

Writing an if statement depending on an attribute of an agent to command agents of a different agentset

I am trying to make an agentset do something, if an agent(of a different agentset) has a particular shape.

Here, if the shape of a particular

where

I have tried along these lines:

ask rabbits
[
 if (shape ghost 1 = "circle")
  [
   forward 1
  ]
]

For this code I get,

"Expected a closing paranthesis here."

with a highlighter on ghost. I'm aware that this code is wrong but I can't think of how else this should be written to get the desired result.

Upvotes: 1

Views: 45

Answers (1)

JenB
JenB

Reputation: 17678

This will (I think - can't test) get the syntax correct:

ask rabbits
[
 if ([shape] of ghost 1 = "circle")
  [
   forward 1
  ]
]

but you also have an ordering error and will have every rabbit check the shape of chost 1. I think what you really want is:

if ([shape] of ghost 1 = "circle")
[ ask rabbits
  [ forward 1
  ]
]

Upvotes: 2

Related Questions