Porting web extension to netlogo web

17 views
Skip to first unread message

Franco Bagnoli

unread,
Nov 22, 2023, 11:28:14 AM11/22/23
to netlogo-devel
Hi, all. 

I am developing some games with netlogo (to teach aspects of complex systems) and I need to collect the answers via a web form. 
I know how to "hack" the url of a  google form, and using the web extension I am able to upload the answers to it. 
However, It is much simpler for students to just use their mobile phone. However the web extension is not working on netlogo web. 
I can edit the html and add a button for fetching the value of a monitor and send it to the google form, but it would make things more uniform to being able to "web:make-request" from netlogo, both desktop and web versions. 

I do not have a clear idea of how extensions are packaged for the web version.. Some help? 


Jeremy Baker

unread,
Nov 28, 2023, 1:24:55 PM11/28/23
to Franco Bagnoli, netlogo-devel
Hey Franco,
Thanks for your interest in NetLogo. You're correct that the Web Extension is not supported in NetLogo Web. There is some similar functionality availability.
You mention web:make-request and using a Google Form, so I assume you're doing an HTTP POST request? If so, you can use the http-req extension in NetLogo Web. It's undocumented and mostly unsupported, but it does work. After adding extensions [ http-req ] to your code you can do something like http-req:post "https://netlogoweb.org" "hello" "text/plain", with the arguments being the URL, the message itself, and the message type. It will report the response from the server. The downsides are many. The extension is not also supported in desktop NetLogo meaning you'll need separate models for each platform. It's a blocking call, meaning your model can freeze if the network is slow to respond or doesn't respond at all for some reason. It doesn't handle any error conditions, so if anything goes wrong the effects could be frustrating.
If you're just doing a simple HTTP GET request for your form URL, you can actually use the Fetch Extension, like fetch:url-async "http://www.netlogoweb.org/" show. It is supported in NetLogo Web and desktop NetLogo and well documented. One difference from the Web Extension is that if you want to check the response from the server you will have to use an anonymous task that will run asynchronously after the request is completed. It doesn't seem like that'd be a big deal for your use case, but just pointing it out.
If you are still interested in implementing an extension in NetLogo Web, we have some documentation on that in the Tortoise repository. Some important info there:
"In NetLogo Web the target for an extension must be JavaScript, and at the moment the only way to include an extension is by bundling it with the NetLogo Web code itself as part of Tortoise. This is all experimental, and we may change the definition file format or the way extensions are loaded as needed for future work. Longer-term the NetLogo team has plans to provide a mechanism to allow inclusion of third party extensions that are external to the NetLogo Web site, but that work is not yet complete."
So it's unfortunately not a simple matter to port an existing Java-based extension like Web to the JavaScript target in NetLogo Web.
I hope that helps. If you have questions on using the HTTP-Req or Fetch extensions, the Netlogo users group might be a more appropriate place to answer them. If you have questions on implementing NetLogo Web extensions, this is the appropriate forum.  Thanks.
-Jeremy


From: netlog...@googlegroups.com <netlog...@googlegroups.com> on behalf of Franco Bagnoli <franco....@gmail.com>
Sent: Wednesday, November 22, 2023 10:28 AM
To: netlogo-devel <netlog...@googlegroups.com>
Subject: [netlogo-devel] Porting web extension to netlogo web
 
--
You received this message because you are subscribed to the Google Groups "netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-devel/ba47530d-c7f0-4859-9de7-b81ebd3fe541n%40googlegroups.com.

Franco Bagnoli

unread,
Nov 28, 2023, 3:21:58 PM11/28/23
to Jeremy Baker, netlogo-devel
Thanks Jeremy, 

I was able to use the fetch extension for recording the results, the only problems are that from standard netlogo it posts the request twice (?) and from netlogo-web it originated an error message, so that I wrote a script to remove it from html (it is a generic error message complaining that something went wrong with the reception of the message -- after all the fetch module has the goal of retrieving, not posting things). 

However, I think that many users would profit from a simple way of getting data from users, both from the standard netlogo desktop application and the web one, and feeding data on a google form is the simplest way. 

Anyhow, for the moment, with the inconvenients illustrated above I managed to get it working. 
--

Franco Bagnoli

Direttore del Centro Interdipartimentale per lo Studio di Dinamiche Complesse (CSDC)

Professore Associato

(tel.) +39 0554572336; (cell.) +39 3386586493;

 

UNIVERSITÀ DEGLI STUDI DI FIRENZE

Dipartimento di Fisica e Astronomia


Reply all
Reply to author
Forward
0 new messages