How to send popup window messages/questions to clients during hubnet simulations (netlogo)

StackOverflow https://stackoverflow.com/questions/22315263

  •  12-06-2023
  •  | 
  •  

質問

I am quite new to Netlogo and I am currently programming a serious game with Hubnet. I was wondering if it is possible to send messages to specific clients via popups windows. I explain: For instance, if a client makes a certain decision (or action), he is alerted of its potential consequences by a message via a popup window. In other situations, I would like the popup window to be a "yes or no" or a multi-choice (with a popup menu) question, in which case I would like to store the client's answer in a specific variable (a global or a turtle variable).

I know that is possible to send popup window messages to the user's interface with for instance:

user-one-of "value" [list-of-choices]

user-message "value"

user-yes-or-no? "value"

I really can't figure out how to do it for the client's interface, however I suspect that it is possible since in some situations, a client may receive a popup message after an action. For instance, when a client enters the wrong input type into an input box (e.g. a character instead of a number), an error message pops up like this:

error message popup in a client's interface

I'd like to program this kind of message by myself in the code so that such a message pops up following some client's actions (for instance when clicking inappropriately a button).

Hope someone can help me on this one!

Thanks!!

Clément

役に立ちましたか?

解決

I am going to give three answers to your question. The first, taking your question literally, is "no." It is not possible to trigger a popup window from the host on the HubNet client.

The second is "yes" under certain very limited circumstances. The example you show, suggests you might have an input box on the HubNet client, which the client user will use to send a value up to the host, and which you want to be a NUMERIC value. If, when creating the HubNet client interface, you specifically select "numeric" as they subtype of input, the user who types a non-numeric entry will get a popup box telling them their input is invalid.

The third answer is a kind of "yes" with one of several "workaround" approaches that might be acceptable to you.

For each of these approaches, I'll specifying NetLogo code that would run on the host computer. This code would normally be placed in the part of the model where you have received the objectionable input from the client. Following the format of the HubNet examples in the Models Library, this would be in a procedure called "listen-clients." I'm also assuming that there is a breed of turtles (i'll call them "students") who are mapped to HubNet clients using a turtle variable (I'll call it "user-id"). This user-id would be initially obtained as the hubnet-message-source of the hubnet-enter-message (and of all subsequent messages from that HubNet client).

So, the options I've seen used for the situation you mention (as I understand it) are...

Workaround A, Send a message to the client in one of several ways.

1) send a "chat" message [ probably not acceptable ]

hubnet-send-message user-id "[your message goes here]"

this will show a message in the user's chat window. I think it's not acceptable for you because it is ignore-able, and because it doesn't identify the part of the interface that caused the problem.

2) send a message that overwrites the input box that they have typed the objectionable input into. Suppose the name of the input box on the client is "entry" So then, if the user types "-8" into the input box, and the number must be positive, you could use the following code:

hubnet-send user-id "entry" "MUST BE POSITIVE"

would lead the input box to be filled (startlingly) with that text. (Note: this works even if the input box was declared to be of numeric-only type)

3) cause a message or condition to appear in the VIEW by using hubnet-view-overrides. Depending on how shocking you want the experience to be for the client, you can manipulate their individualized View. (this is for HubNet models that use View Mirroring).

For example, to make the patch at 5 10 show a message "INVALID" you could say:

hubnet-send-override user-id (patch 5 10) "plabel" [ "INVALID" ]

Or you could make it even more crazy by turning ALL the patches red (along with the INVALID message)

hubnet-send-override user-id patches "pcolor" [ red ] 

Then, when the user resolves the issue, you can remove all the view overrides

hubnet-clear-overrides user-id

Option Number 3 is more "advanced" --> i would recommend consulting the User Guide here because the syntax can be confusing. But it is pretty effective in getting users' attention :)

Hope that helps

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top