Question

I'm writing a Hubnet-application and I want the view of each client to depend on the turtles in that client's variable turtles I can see. In particular I want to hide all turtles not in a clients turtlesIcansee from her.

I've managed to get this to work by checking the 'mirror 2D view on clients' box in the Hubnet-control Center and adding the following code

ask turtles[hubnet-send-override [user-id] of self turtles "hidden?" [true]]
ask turtles[hubnet-send-override [user-id] of self [turtlesicansee] of self "hidden?" [false]]

Although this currently seems to work, I have two questions about the code:

1) The first row is redundant if I could take the complement of turtlesicansee in the second row (and switch false to true). Is there a way to do this, effectively saying that I want to hide all turtles not in turtlesicansee?

2) I'm not sure about the quantification in the second statement. I want to tell every turtle (client) that the only turtles she can see are the turtles in HER turtlesicansee. Is this what I'm getting? Part of what is confusing me is that I'm asking turtles to send the override messages but I don't really see why it matters which turtle the message came from (but I haven't figured out how to get the quantification right without the ask turtles command)

Anyway, can anyone help me with this?

Was it helpful?

Solution

About the complement & the necessity of your first line (telling each client to make all turtles hidden)

First, what I'm assuming... 1) each turtle in the model is associated with a hubnet client (a student) 2) there are no other turtles or kinds of turtles in the model. 3) the agentset "turtlesicansee" is a turtle variable that changes over time

Given these assumptions, one way to get the complement of turtlesicansee is

let onesicantsee turtles with [ not member? self turtlesicansee ] 

This would create a temporary variable with the complement of turtlesicansee.

So, you could do your two commands with less redundancy by saying:

ask turtles[
  let onesicantsee turtles with [ not member? self turtlesicansee ]
  hubnet-send-override user-id   turtlesicansee   "hidden?" [false] 
  hubnet-send-override user-id   onesicantsee     "hidden?" [true]
]

HOWEVER, setting the override on a client (at least in my understanding/mental model of things) isn't expensive. It doesn't actually cause something to happen, it sets a "filter" on the next display update. So, your original code isn't so bad. You need to manipulate the filter's behavior for all turtles, and your approach may actually be faster than the one that I've written here.

On the question of the "logic" of HubNet's command here, and your "Part of what's confusing me..." note. I agree, this is very bizarre. The "hubnet-send-override" command could be issued outside of an ask-turtles block. But in this case (and in most cases) you need to personalize the "filter" to each turtle (student) by using their user-id and their turtlesicansee variables. So, doing the command inside an ask turtles sets the scope of those variables to each student, in turn. [Does that make sense?]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top