Coding Clients

No preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner about 6 years ago

hubnet 

Tagged by Reuven M. Lerner about 6 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 4.1pre2 • Viewed 187 times • Downloaded 14 times • Run 0 times
Download the 'Coding Clients' modelDownload this modelEmbed this model

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


VERSION

$Id: Coding Clients.nlogo 40136 2008-06-20 18:38:08Z everreau $

WHAT IS IT?

a model with minimal content that lets clients do little bits of coding.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [ color-names ]

breed [ students student ]

students-own
[
  user-id
  commands
  my-error
]

to startup
  setup
  hubnet-set-client-interface "COMPUTER" []
  hubnet-reset
  set color-names [ "gray" "red" "orange"
                    "brown" "yellow" "green"
                    "lime" "turquoise" "cyan" "sky"
                    "blue" "violet" "magenta" "pink" ]
end 

to setup
  cp
  cd
  clear-output
  set-default-shape students "turtle"
end 

to go
  every 0.1
  [ listen-clients ]
end 

;;
;; HubNet Procedures
;;

to listen-clients
  while [ hubnet-message-waiting? ]
  [
    hubnet-fetch-message
    ifelse hubnet-enter-message?
    [ create-new-student ]
    [
      ifelse hubnet-exit-message?
      [ remove-student ]
      [ execute-command hubnet-message-tag ]
    ]
  ]
end 

to create-new-student
  create-students 1
  [
    set user-id hubnet-message-source
    set label user-id
    set commands "fd 1"
    set my-error ""
    send-info-to-clients
  ]
end 

to remove-student
  ask students with [user-id = hubnet-message-source]
  [ die ]
end 

to execute-command [command]
  if command = "commands"
  [
    ask students with [user-id = hubnet-message-source]
    [
      set my-error __check-syntax hubnet-message
      if my-error = ""
      [ set commands hubnet-message ]
      hubnet-send user-id "error" my-error
    ]
    stop
  ]
  if command = "do it!"
  [ ask students with [ user-id = hubnet-message-source ]
    [
      if my-error = ""
      [
        carefully
        [
          run commands
          set my-error ""
          send-info-to-clients
        ]
        [
          set my-error error-message
          hubnet-send user-id "error" error-message
        ]
      ]
    ]
  ]
end 

;; whenever something in world changes that should be displayed in
;; a monitor on the client send the information back to the client

to send-info-to-clients ;; turtle procedure
  hubnet-send user-id "location" (word "(" pxcor "," pycor ")")
  hubnet-send user-id "error" my-error
  hubnet-send user-id "You are a:" appearance-string
end 

to-report appearance-string
  report (word color-name color " " shape)
end 

to-report color-name [c]
  report  item (int (c / 10)) color-names
end 

There are 2 versions of this model.

Uploaded by When Description Download
Uri Wilensky almost 9 years ago Coding Clients Download this version
Uri Wilensky almost 9 years ago Coding Clients Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.