Skip to content

Multiple views via HubNet

Frank Duncan edited this page Mar 20, 2015 · 10 revisions

Users often ask if they can have more than one view in their model and show different things, or show the same things differently, in each one.

Hopefully in the future we'll provide this capability directly. But it is already possible now using HubNet with local clients. It's a bit awkward, but it works.

You'll need to be using NetLogo 5.x, not some older version.

How to do it

  1. Open any model
  2. from the Tools menu, open the HubNet Client Editor
  3. in the editor, add a view to the client
  4. in the Command Center, type hubnet-reset
  5. In the dialog that opens, uncheck "Broadcast server location" and press the Start button
  6. in the HubNet Control Center window, check the "Mirror 2D view on clients" checkbox
  7. in the Command Center, type __hubnet-create-client

Now you've got a second view, identical with the main view.

But identical views are no fun. You want the other views to show something different. The relevant primitives are:

  • creating, detecting, and removing clients:
  • __hubnet-create-client
  • you can make as many clients as you like
  • hubnet-clients-list
  • for finding out the clients' names, for use with the primitives below
  • hubnet-kick-client, hubnet-kick-all-clients
  • customizing view contents ("client overrides"):
  • hubnet-send-override
  • hubnet-clear-override
  • hubnet-clear-overrides
  • recentering and zooming view ("client perspectives"):
  • hubnet-send-follow
  • hubnet-send-watch
  • hubnet-reset-perspective

It's especially useful to override the turtle and link variable hidden?, to make things invisible in one view and visible in another.

Automating

Most of the above steps can be done by code in the Code tab. And once you've added the view to the HubNet client, it's saved with the model so you don't need to add it again.

But a few manual steps are necessary. You have to click the Start button after hubnet-reset and check the view mirroring checkbox.

Example

Show only red turtles, make them bigger, and label them with coordinates:

hubnet-send-override one-of hubnet-clients-list turtles with [color != red] "hidden?" [true]
hubnet-send-override one-of hubnet-clients-list turtles "size" [5]
hubnet-send-override one-of hubnet-clients-list turtles "label" [(word pxcor " " pycor)]

see screenshot

Clone this wiki locally