Client Overrides Example

Client Overrides Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

ccl 

Tagged by Modeling Commons System about 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0beta1 • Viewed 254 times • Downloaded 31 times • Run 0 times
Download the 'Client Overrides Example' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Click to Run Model

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.

Uploaded by When Description Download
Uri Wilensky almost 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated from NetLogo 5.0 Download this version

Attached files

File Type Description Last updated
Client Overrides Example.png preview Preview for 'Client Overrides Example' almost 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.