Tag, You're It.
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This template contains code that can serve as a starting point for creating new HubNet activities. It shares many of the basic procedures used by other HubNet activities, which are required to connect to and communicate with clients in Disease-like activities.
HOW IT WORKS
In activities like Disease, each client controls a single turtle on the server. These turtles are a breed called STUDENTS. When a client logs in we create a new student turtle and set it up with the default attributes. Students own a variable for every widget on the client that holds a state, that is, sliders, switches, choosers, and input boxes. Whenever a user changes one of these elements on the client, a message is sent to the server. The server catches the message and stores the result. In this example a slider is used to demonstrate this behavior. You can also send messages to the client-side widgets using hubnet-send. Monitors on clients must be updated manually by the model, that is you must send a message to a monitor every time you want the value displayed to change. For example, if you have a monitor that displays the current location of the client's avatar, you must send a message to the client like this:
| hubnet-send "location" (word xcor " " ycor)
whenever the client moves. Buttons on the client side send but do not receive messages. When a user presses a button, a message is sent to the server. The server catches the message and executes the appropriate commands. In this case, the commands should always be turtle commands since the clients control only a single turtle.
HOW TO USE IT
To start the activity press the GO button. Ask students to login using the HubNet client or you can test the activity locally by pressing the LOCAL button in the HubNet Control Center. To see the view in the client interface check the Mirror 2D view on clients checkbox. The clients can use the UP, DOWN, LEFT, and RIGHT buttons to move their avatar and change the amount they move each step by changing the STEP-SIZE slider.
Comments and Questions
breed [ players player ] players-own [ user-id it ] to startup setup hubnet-set-client-interface "COMPUTER" [] hubnet-reset end to setup clear-patches clear-drawing clear-output listen-clients ask turtles [setxy random-xcor random-ycor] end to go every 0.1[ listen-clients display ] end to listen-clients while [ hubnet-message-waiting? ] [ hubnet-fetch-message ifelse hubnet-enter-message? ;; when clients enter we get a special message [ create-new-player ] [ ifelse hubnet-exit-message? ;; when clients exit we get a special message [ remove-player ] [ ask players with [user-id = hubnet-message-source] [ execute-turn hubnet-message-tag ] ;; otherwise the message means that the user has ] ;; done something in the interface hubnet-message-tag ;; is the name of the widget that was changed ] ] end to create-new-player create-players 1 [ set user-id hubnet-message-source set label user-id ifelse count players with [it = true] = 0 [set it true set color red] [set it false set color white] setxy random-xcor random-ycor ] end to remove-player ask players with [user-id = hubnet-message-source][ die ] end to execute-turn [turn] let new-heading position turn ["up" "right" "down" "left"] if new-heading != false [ set heading 90 * new-heading fd 1 ask players with [it = true] [ let new-it one-of other turtles-here if new-it != nobody [ ask new-it [ set it true ] set it false ] ] ask players with [it = true] [set color red] ask players with [it != true] [set color white] ] end
There is only one version of this model, created about 15 years ago by Josh Cough.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.