Reputation: 89
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
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 ]
[ 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 [ ... ] ]
.
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