I have tried for a long time, but I cant solve the following error.
In a turtle I want to change the pcolor, into the pcolor of a patch somewhere else in the field. Example:
ask turtles [
set pcolor (ask patch 0 0 [show pcolor])
]
However I just recieve the error "Expected error".
Thank you very much in advance!
If you use
ask turtles [
set pcolor [pcolor] of patch 0 0
]
It does what I assume you want.
Related
I would like to prevent a turtle from visiting a patch it has visited before. I'm developing the code, but this error appears: error: "a patch cannot access a variable of a turtle without specifying which turtle".
I'm pretty sure it's another syntax error. But, I am not able to find this error. I tried to simplify the code to make it easier for you guys to help me. Any kind of help is welcome.
turtles-own: patchVisited
setup: set patchVisited (list patch-here)
go: set patchVisited lput patch-here patchVisited
move:
let availablePatch [neighbors with [not member? self [patchVisited] of myself and resource-value > 0.2 ]] of patch-here
let neighAvailable count availablePatch
move-to max-one-of availablePatch [resource-value]
Change
let availablePatch [ neighbors with [not member? self [patchVisited] of myself and resource-value > 0.2 ] ] of patch-here
to
let availablePatch neighbors with [not member? self [patchVisited] of myself and resource-value > 0.2 ]
You don't need neighbors of patch-here, that's what neighbors means.
In general: (1) NetLogo highlights the line with the syntax error. That is useful information for us (and you) so include it in the description of the problem. (2) Make smaller changes in your code - get the smaller change working before moving on. In this case, you could have just one turtle moving around and done something like:
ask neighbors with [not member? self [patchVisited] of myself] [set pcolor red]
and turned the patches white again afterwards.
I'm new to NetLogo and I have a question that I'm sure is pretty basic. But, I'm not getting over the difficulty.
If anyone can help me overcome this difficulty, I would be very grateful.
I would like from the patch where the turtle is found to consider the 8 neighboring cells in search of the highest pveg value. If it has equally high values, choose 1 of these randomly. Upon finding the highest pveg value of the neighbors, the turtle went there.
I am using the command: max-one-of. I think it serves my purpose. But, I'm making some syntax error that shows the following error: MOVE-TO expected input to be an agent but got NOBODY instead.
Thanks in advance
extensions [ gis ]
globals [ veg ]
patches-own [pveg]
to setup
clear-all
reset-ticks
setup-patches
crt 1 [
ask neighbors [ set pcolor blue ]
set color black
]
end
to setup-patches
end
to go
ask turtles [neighboring]
end
to neighboring
let my-neighWith-pveg [ neighbors with [pveg > 0.2] ]of patch-here
ifelse neighWith-pveg = 0
[ ]
[ move-to max-one-of patches [my-neighWith-pveg] set pcolor red ;;ERROR HERE
]
end
The NetLogo dictionary says, max-one-of needs an agentset and a reporter as input:
max-one-of agentset [reporter]
In your code, you use two agentsets: turtles and my-neighWith-pveg
Since you want to chose from the neighbors (and not all turtles) with the hightes pveg, you can write:
max-one-of my-neighWith-pveg [pveg]
I tried the following syntax but got the following error.
Error messages: TURTLES-ON expected input to be an agent or agentset but got NOBODY instead.
In the 2D screen when an error message was issued, an error occurred when the turtle reached the rightmost cell. If the sintax "forward 1", this case works well withour any error. But I need to use the "forward 1 * 0.1" syntax with "tick-advance 0.1".
I already saw the following description, but I do not solve it still now.Does anyone know a good way? Thank you in advance.
https://ccl.northwestern.edu/netlogo/docs/programming.html#topology
The following is an example syntax:
ask turtles with [xcor < max-pxcor][
if not any? turtles-on patch-ahead 1
[forward 1 * 0.1]]
The can-move? reporter referenced in your link is one way (and references another: patch-ahead distance != nobody). In the dictionary definition, it notes that the reporter reports true when the turtle could move some distance without violating topology- in other words, if the turtle can move to an existing patch. Any patches "off the edge" of a world without world wrapping do not exist, and so return nobody.
tick or tick-advance shouldn't figure into this issue, as the evaluation of the patch-ahead is done by each turtle independent of timing. For example, here's a toy model that doesn't have tick or tick-advance at all:
to setup
ca
crt 200 [
move-to one-of patches with [ not any? turtles-here ]
pd
]
reset-ticks
end
to go
let speed 1 * 0.1
ask turtles [
if can-move? speed and not any? other turtles-on patch-ahead speed [
fd speed
]
]
end
Note that I've turned world-wrapping off entirely, and get a result like what is shown below- no errors, and turtles have stopped moving either because there is a turtle in there way or because they've bumped up against the edge of the world:
I want to set a patch variable as equal to the number of turtles on that patch.
I have tried
ask patches [set variableA (count turtles-here)]
when i do this, i get the error: "set expected 2 inputs"
i tried to use a workaround by setting the turtle-count as the plabel
ask patches [set plabel (count turtles-here)]
that code worked, but i need to do this for multiple variables and when i tried to transfer the plabel over to the variable
ask patches [set variableA plabel]
i again get the error: "SET expected 2 inputs"
any help is appreciated.
Are you sure that variableA is truly a patch variable? If it is, your first line should work. The following program, for instance, compiles and executes without error:
patches-own [ variableA ]
to test
ask patches [ set variableA (count turtles-here) ]
end
The only case I can see that would be causing the error that you're seeing is if variableA is not a patch variable, but a reporter taking one argument. For example:
to test
ask patches [ set variableA (count turtles-here) ]
end
to-report variableA [ x ]
report 0
end
...will give you the SET expected 2 inputs error.
I'm a netlogo beginner and hope to get some help.
I'm trying to create a patch at coordinates 0,0 and then set the color to red, including all 8 surrounding patches.
How can i do so?
I tried something like,
ask patch 0 0 [set pcolor red of neighbors]
I know it's wrong, 'cos i'm stuck. Hope someone can give me a tip!
You can simply do:
ask patch 0 0 [
set pcolor red
ask neighbors [
set pcolor red
]
]