10. Modify/Create NetLogo with AI Partner

ChatGPT and other AI systems can understand the NetLogo programming language and the NetLogo interface elements. You can use this AI Partner to help you modify an existing NetLogo simulation (or even create a brand new one!). The first challenge is to come up with an idea for the enhancement you want to do (or the kind of simulation you want to create). Here’s way to use AI to generate a list of possible projects:

Imagine that I want to make the FIRE simulation more realistic. Obviously we could ask it to consider how wind and rain could be added. Let’s ask ChatGPT for five suggestions that would make FIRE more realistic or more educational:

My Prompt for 5 ideas:
I want to modify NetLogo’s FIRE model to make it more interesting or more educational. It still will need to be very easy to use, even for 3rd grade children. The code should also be simple so that you and I can actually make it work. Please give me five examples of NetLogo model enhancements to the FIRE model. The enhancements must be original, we can’t just copy another entire model. Can you do this?

ChatGPT Response:
Absolutely, Scott — I can help you design original, easy-to-use, and educational enhancements to the NetLogo FIREmodel that will be exciting and understandable even for 3rd graders. Here are five original enhancements, each adding just a bit of complexity while keeping the code and interface kid-friendly:

🔥 1.  Wind Direction and Speed
Idea: Add a slider and visual arrow to show wind blowing in a certain direction and speed. Fire spreads faster downwind and slower or not at all upwind.
Why it’s educational: Teaches how wind affects wildfires — a real-world concept.
Interface:

  • Slider: wind-speed (0 to 5)
  • Slider: wind-direction (0 to 360)
  • Simple logic: When fire spreads, bias it toward the direction of the wind.

🌲 2.  Different Tree Types
Idea: Add two kinds of trees — “dry trees” (burn easily) and “wet trees” (burn slowly or not at all).
Why it’s educational: Kids learn that different environments burn differently.
Interface: • Slider: percent-dry-trees (0 to 100)
logic: At setup, some trees are marked dry and some wet. Dry trees catch fire more easily

🚒 3.  Firefighters
Idea: Add a few “firefighter turtles” that try to block the fire by turning nearby burning patches into “wet” ones that can’t burn.
Why it’s educational: Introduces problem-solving and human intervention in natural systems.
Interface: • Button: deploy-firefighters
Simple logic: A few turtles move toward the fire front and “protect” nearby trees.

🌧️ 4.  Rain Cloud
Idea: Let students click a button to make it rain, which temporarily prevents fire from spreading.
Why it’s educational: Teaches about weather effects and cause/effect.
Interface: Button: make-it-rain
Simple logic: Change tree patches to “wet” for a few ticks, then dry out again.

🔄 5. Regrowth After Fire
Idea: After a tree burns, it doesn’t stay black forever — it slowly regrows (green again) after many ticks.
Why it’s educational: Shows natural cycles and forest recovery.
Interface: Slider: regrowth-time (e.g., 50 to 200 ticks)
Simple logic: Burned trees slowly turn green again based on a counter.

For this example I chose “2. Different Tree Types.” Here’s my next prompt:
I love your “Different Tree Types” idea! Here’s the code for the existing model:
[then I pasted the entire old FIRE code after the word “model:”.]

ChatGPT went ahead and gave me all of the changes, but I had more guidance to give. Here’s the next prompt with the new guidance. PAY ATTENTION to guidance because you should add similar statements to make sure AI gives you its best and most appropriate solution.
The Next Prompt:
Whoa! I’m not ready for the new code yet. I need to tell you that I’ll be using NetLog 6.4. This version has some code changes from earlier version, so please make sure you are using the latest version of NetLogo language. Sometimes you have given me global variables that should be identified in interface elements like sliders. Please make sure that variable and not defined in both places. Now, please give the complete code that replaces all the code in the existing model. Finally, give me complete directions for the interface elements I need to add. Thank you.
ChatGPT then gave me a very usable output of code and directions for me and for teachers using the new simulation with 3rd graders.

The Result!
I created a new NetLogo file through “SAVE AS…” to give the FIRE file a new name on my computer. I deleted all the code in the original NetLogo model and replaced it with ChatGPT’s code. The green check mark indicated that it should logically run. When I moved to the interface, NetLogo informed me there was no variable name “percent-dry-trees”. That was expected and would have happened if I was a pro writing my own code. The specific variable, “percent-dry-trees” needs to be defined by a slider (because the slider changes its value). When I created the slider according to ChatGPT’s direction, the error message went away.
I tested Setup, but was met by the error “there is no name FOREST.” ChatGPT gave the color of one kind of tree “GREEN” and the other “FOREST,” but there is no named color “FOREST” in NetLogo. I replaced all instances of FOREST with BROWN (for the dry trees), and that worked. Finally, the monitor showing the percent trees wasn’t working. I didn’t type ChatGPT’s report code correctly.
When I fixed my error, everything worked perfectly. Bottom Line, ChatGPT made one error, naming a color that didn’t exist. And I made one error, retyping ChatGPT’s suggestion rather than copy/pasting it, so my typo was the other error. I regard this as a huge success 🙂 The final FIRE-TREE-TYPES simulation below:

You can create you own totally new NetLogo model in a similar way. Here’s a sample prompt to create a brand new model:

The First Prompt:
In the last chat, you gave me an idea to build the following NetLogo Model: Micromobility City Planning.

The Second Prompt:
I’m ready for you to help me. Here are some guidelines. First, as you write the code for the model, please use the “ifelse” format rather than statements containing “else.” Current NetLogo versions do not use the “else” construct. Second, in past trials, you have defined global variables that are actually defined in infrastructure elements like sliders. Please avoid that confusion between global variables and infrastructure-defined variables. Finally, please use your judgement to select the specific model purpose and variables so that the code is simple enough to run correctly and reliably. I’ll need the complete code, ready to paste into NetLogo. I’ll also need descriptions of each interface element. Can you do this? Thank you.