Ryan
Ryan

Reputation: 387

How to link turtle x of one breed to turtle y of another breed?

I am attempting to link individual turtles of breed x to individual turtles of breed y. The following throws an error:

breed [xs x]
breed [ys y]

to setup
  clear-all
  create-xs 25 []
  create-ys 25 []
  ask x 1 [ create-link-with y 2 ]
end

The error says that "x 2 is not a Y" which I don't understand, since I asked for a link between x 1 and y 2.

I am confused, because I know that connecting a single turtle of breed x to multiple turtles of breed y does work, a la:

breed [xs x]
breed [ys y]

to setup
  clear-all
  create-xs 25 []
  create-ys 25 []
  ask x 1 [ create-links-with n-of 5 ys ]
end

I've read over the NetLogo guide concerning links and breeds, but I did not see anything which addressed this issue specifically.

Is the single link version possible?

Upvotes: 1

Views: 221

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30453

Who numbers are assigned across all turtles, not per-breed. so e.g. create-link-with y 27 will succeed. Your xs are numbered 0 through 24 and your ys are numbered 25 through 49.

(As an aside, note that it's rarely a good idea to use who numbers at all — in real code, at least, as opposed to little tests and experiments. create-link-with one-of ys will work as well and avoids involving who numbers at all.)

Upvotes: 2

Related Questions