NetLogo - Stepping on patch initializes new function - netlogo

I'm creating this game on Netlogo where a turtle basically moves through a maze to the red patch. Once at the red patch it will go onto the next level. I have written both maps but how do I connect the two?
How do I make it so when a turtle steps on a red patch a new function initializes?

ask turtle-in-question [if pcolor = red [code you want to run] ]
Should work
as does
if [pcolor] of turtle-in-question = red [code to make new level]
it works at the observer level so in most cases it will be the better choice.

Related

Why am I getting an error when I disengage world wrap in NetLogo?

I downloaded a working model and I'm adjusting it to fit criteria I have. I want to disable the world wrap so the turtles are constrained in their movement to the initial screen but when I do I get an error telling me: OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead.
Welcome to StackOverflow! For future reference, your question is a bit incomplete as it's hard for others to help you without seeing the code you are using. Try to include enough code for others to answer your question. I cannot directly help resolve your issue, but I can provide some general information.
In NetLogo the behavior of many of the language primitives changes when world wrapping is enabled and when it is not. As an example using patch-ahead, in a world with wrapping in both directions, this code will always succeed:
; turtles will color themselves the color of the patch 1 unit away
ask turtles [
set color ([pcolor] of patch-ahead 1)
]
But if wrapping is disabled in one or both directions, the patch-ahead of a turtle can return nobody when there is no patch in front of the turtle because the turtle is at the edge of the world. In that case you are asking NetLogo to evaluate [pcolor] of nobody, but that is not possible, and you get an error like the one you described.
To resolve this issue you'll have to look through the code and see where these errors are made and handle them appropriately. For my example:
ask turtles [
if patch-ahead 1 != nobody [
set color ([pcolor] of patch-ahead 1)
]
]
You can read more about the world topology of NetLogo models in the docs.

Query about hidden turtles

What actually happens to hidden turtle? I mean after we hide the turtle it continue to live in invisible mode occupying memory as I guess.
I hide few turtles but did not ask them to be shown back and when I inspected the hidden turtles continuing simulation their attribute were changing as per my commands. So, what exactly hiding a turtle sense for.
In one of my simulations, turtles represent people making decisions about whether to protect themselves during an epidemic. There are tens of thousands of these turtles, with potentially hundreds on some patches. The turtles don't move, but they each make their own decision based on personal characteristics like attitude and environmental perception such as how close the epidemic is.
Having these turtles visible would just clutter up the screen. Instead, I hide them and colour the patch based on what proportion have adopted protective behaviour. This is much more informative.
In my most recent simulation, though, I make the turtles size 0 instead of hiding them. This still makes them disappear, but I can still right-click on the world view to access the list of turtles where I have clicked.
Another reason to hide turtles is when you are simulating an infinite plane and turtles outside the view should simply be hidden.
Note that if you are moving turtles using setxy rather than forward you should test to make sure the patch you are about to move to exists since setxy throws a runtime error if it is given coordinates outside the world. From NetLogo documentation:
ifelse patch-at (new-x - xcor) (new-y - ycor) = nobody
[ hide-turtle ]
[
setxy new-x new-y
show-turtle
]

Why doesn't this always create a triangle?

I would expect this code to create a triangle each time, but instead many
times it goes through the wrap-around, creating a zigzag line or
disconnected angle pieces. Why is that? Is it a bug?
Create a go button (not a forever button) to run this code
to go
clear-all
create-turtles 3
ask turtles
[ setxy random-xcor random-ycor
create-links-to (other turtles)]
end
The links take the shortest path, which may go around the world edges, which (in the default world topology) are connected to each other.
Go into the "Settings..." dialog and turn off wrapping if it isn't the behavior you wanted.
See http://ccl.northwestern.edu/netlogo/docs/programming.html#topology for details.

how to move(or don't move) turtles just in special ways or patches in netlogo?

Imagine a city with streets that people move around the city and streets. How can i say to the turtles that move just in a certain ways or don't move in some ways(patches)?
Some relevant models in the Code Examples section of the Models Library that I suggest you look at and study:
Look Ahead Example: turtles look ahead of them before moving so they don't step on blue patches
Wall Following Example: turtles treat brown patches as "walls", walking alongside them
In Look Ahead Example, the crucial snippet of turtle code is:
ifelse [pcolor] of patch-ahead 1 = blue
[ lt random-float 360 ] ;; We see a blue patch in front of us. Turn a random amount.
[ fd 1 ] ;; Otherwise, it is safe to move forward.
In Wall Following Example, the behavior of the turtles is more complicated, so the code is a more complicated, too.

Turtle that has no effect on other turtles implementation but speeds up the reaction

I am using an existing model in netlogo called Chemical Equilibrium and am adding some more code. I want to add turtles (catalyst) which have no effect on the reaction/other turtles but speeds up the FORWARD reaction, which has been defined as follows:
to react-forward [t]
ask t [ set color red ]
set color green
rt random-float 360
jump 2
end
I was thinking that I should put a switch and a slider, make the turtles into whitemols or I do a turtles-own [catalyst] and then define that like I have done with temperature and pressure. I tried the following but it didnt work.
turtles-own [speed catalyst]
crt whitemols
[ set color white
randomize
set speed 1
]
I know the above code is incorrect but am not sure how to code this particular feature.
There are many ways to do this, of course. I can't tell what is going on in your program from the little snipped you include.
One way would be to have the catalyst be of a different breed:
breed [catalysts catalyst]
breed [chemical-x chemical-x]
;and so on
;then the forward reaction is sped up by the existence of catalysts
to react-forward
let num-catalysts count catalysts
;speed up by num-catalysts
;...
end