Client Overrides Example
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This example demonstrates how to use overrides in HubNet.
HOW IT WORKS
The most important part of the code is found in the EXECUTE-COMMAND procedure. When the server receives a message that the client clicked on the view it sends a message back to the client to change the color of the nearby patches.
Note that this feature will only work if you have the "Mirror 2D view on clients" box checked in the HubNet Control Center.
THINGS TO TRY
Comment out the line:
hubnet-clear-overrides hubnet-message-source
what changes?
NETLOGO FEATURES
This model demonstrates basic usage of HUBNET-SEND-OVERRIDE and HUBNET-CLEAR-OVERRIDES.
Comments and Questions
breed [students student] students-own [ user-id ] patches-own [ true-color ] to startup hubnet-reset end to setup clear-patches clear-drawing clear-output ask patches [ ;; the gray covers the "true color" of the patch, which can only ;; be seen on the clients if they click on a nearby patch set pcolor gray set true-color one-of [blue green] ] reset-ticks end to go listen-clients every 0.1 [ tick ] end ;; ;; Here's where the action is ;; to execute-command [command] if command = "View" [ ;; extract the coordinates from the message let p patch (item 0 hubnet-message) (item 1 hubnet-message) ;; get the patch clicked on and the surrounding patches in a single patch set let my-patch-set (patch-set p [neighbors] of p) ;; clear any existing overrides on the client including any patches ;; revealed by the last click hubnet-clear-overrides hubnet-message-source ;; send an override to the client each patch in MY-PATCH-SET will evaluate ;; the reporter in the block [TRUE-COLOR]. So the color of the patch on the client ;; will appear as TRUE-COLOR rather than the color on the server. hubnet-send-override hubnet-message-source my-patch-set "pcolor" [true-color] ] end ;; ;; Standard HubNet Procedures ;; to listen-clients while [hubnet-message-waiting?] [ hubnet-fetch-message ifelse hubnet-enter-message? ;; when clients enter we get a special message [ create-new-student ] [ ifelse hubnet-exit-message? ;; when clients exit we get a special message [ remove-student ] [ ask students with [user-id = hubnet-message-source] [ execute-command hubnet-message-tag ] ] ] ] end to create-new-student create-students 1 [ set user-id hubnet-message-source hide-turtle ] end to remove-student ask students with [user-id = hubnet-message-source] [ die ] end ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There are 3 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Client Overrides Example.png | preview | Preview for 'Client Overrides Example' | over 12 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.