afdez
afdez

Reputation: 89

How to know type of object in netlogo?

I am doing an application in NetLogo and would like to know if there is something to know the data type of a variable, something similar to instanceof in JAVA.

to main
 move blockA
end

to move [block]
 ;;;how to know if block is xty BlockA or BlockB???
end 

regards

Upvotes: 3

Views: 479

Answers (1)

Bryan Head
Bryan Head

Reputation: 12580

To clarify, BlockA and BlockB are turtle breeds, yes? There are two ways:

I'll assume your breeds are declared as:

breed [ BlockAs BlockA ]
breed [ BlockBs BlockB ]
  1. [ breed ] of block will report it's breed, so you can do, for instance, if [ breed ] of block = BlockAs [ ... ] or ask block [ if breed = BlockAs [ ... ] ].

  2. The is-*? primitives. In the case of turtle breeds, you can do is-BlockA? block. This also works for other data types. For instance is-number? will tell you if something is a number.

Upvotes: 3

Related Questions