Expected input to be a number but got TRUE/FALSE - netlogo

I have got this block of code:
to catch-rose
let prey one-of roses-here
if prey != nobody
[
set energy energy + 1
set rose_ramasse rose_ramasse + 1
ask prey [ die ]
]
end
When I launch the simulation, I get the following error message
+ expected input to be a number but got the TRUE/FALSE false instead.
error while unefeebleue 2 running +
called by procedure CATCH-ROSE
called by procedure GO
called by Button 'go'*
I've been trying to solve out my problem myself but I can't. Why it does not want to recognize the second SET command? Why does it think it is true/false statement?

The error message is telling you the following:
It starts with the operation that failed. Often this is a procedure name, in this case it is +. So you know that it is one of the inputs to + that is failing.
It's telling you that one of the inputs to + is a TRUE/FALSE value.
Now, you've told us that the line it refers to is the second set statement. There are two inputs to the + on that line, rose_ramasse and 1
So, your problem is that rose_ramasse is a TRUE/FALSE (boolean) value. Without the rest of your code, it's not clear whether rose_ramasse is a global variable or not, so it is hard to go any further to help you work out where rose_ramasse is being assigned a boolean value.
I can replicate the error message with a simple function like the following:
globals [age]
to go
set age TRUE
set age age + 1

Related

How to read formula including turtle values from a input box?

Im having trouble including a formula in the input box into my model and hoped someone could help. In short I want the global variable "subsidy_absolute_threshold" to be read as "100 + m2 / 1600". So that wherever that variable is implemented, that code is implemented instead. The current code reads something like
turtles-own [m2 subsidy_eligible]
globals [subsidy_absolute_threshold]
[...]
set subsidy_absolute_threshold "100 + m2 / 1600"
[...]
ask turtles [
if ambition < read-from-string subsidy_absolute_threshold [set subsidy_eligible true]
]
Technically the global value is an input box set as a string, but it should be functionally the same thing. The error message I get is "Extra characters after literal." which I struggle to understand.
I have tried all the "types" of input boxes, but none work. I have also tried directly writing in the formula, as in replacing subsidy_absolute_threshold with 100 + m2 / 1600, which works.
Use the native command runresult instead of read-from-string.
I'm somewhat unsure exactly why read-from-string does not work, so if someone wants to present an explanation please do.

Cannot edit numbers document with AppleScript

I am trying to run a very simple script in automator for a the apple program numbers. I have tried a couple of different scripts with no success.
With the following code:
on run {input, parameters}
tell application "Numbers"
activate
tell document 1 to tell sheet 1 to set the value of cell "B3" to 0
tell document 1 to tell sheet 1 to set the value of cell "C4" to 42
end tell
return input
end run
I get the following error message:
"Numbers got an error: Can’t set cell "B3" of sheet 1 of document 1 to 0."
There was a nearly identical posted question with the following solution:
on run {input, parameters}
tell application "Numbers"
tell table 1 of sheet 3 of document 1
set the value of cell 1 of column "E" to 1000
end tell
end tell
return input
end run
but this gives me the following error message:
"Numbers got an error: Can’t set table 1 of document 1 to 1000."
This other post did mention it may have something to do with privileges but did not elaborate and I have been unable to find any more information regarding this.
Can anyone help me please?
Thank you.
With a Numbers document already opened, the following example AppleScript code works for me:
tell application "Numbers"
activate
tell first table of first sheet of front document
set value of cell "B3" to 0
set value of cell "C4" to 42
end tell
end tell
Here is a different way of saying the same thing as the example AppleScript code above:
tell application "Numbers"
activate
set value of cell "B3" of table 1 of sheet 1 of document 1 to 0
set value of cell "C4" of table 1 of sheet 1 of document 1 to 42
end tell
Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

Netologo Behavior Space: have each agent report values

I'd like to run a Behavior Space sweep in my model and have each agent report the respective values that they own in the results.
Here is the code I am using to ask each agent to report values.
to-report wrapup
ask artcollectors
[
type who
type " "
type num-artcollectors
type " "
type num-subjectmatters
type " "
type c-artcollection-size
type " "
type c-self-reference-bias
type " "
type c-artdisposal-rate
type " "
type c-random-bias
type " , "
print clist
]
end
When I do this and report to the Console, Netlogo will make the first run and report results to the console, then Nelogo stops at the end of the first run and reports
"Reached end of reporter procedure without REPORT being called.
error while observer running END
called by procedure WRAPUP
called by procedure __EVALUATOR"
So I get that I am not running the right syntax in my wrapup procedure. Can anyone suggest the magic words I need to use?
A to-report procedure is a reporter and must therefore return some value to the caller. Your wrapup procedure is actually a command - the agent does something and then stops. So, you should use the declaration for a command procedure, to wrapup rahter than to-report wrapup.
Hope this helps,
Charles

Create an "itinerary" agentset of patches

I'm building a model where turtles "search" a subset of patches for a resource according to different search criteria.
I'm trying to build reports that return a sorted list or agentset of patches that a turtle can then use as an itinerary for it's search.
For some reason I'm having trouble storing the itinerary in a turtle owned variable.
an example reporter is:
to-report availability
let sorted-patches sort-on [ ( (space - occupants) / space ) ] patches with [space > 0]
report sorted-patches
end
when I do show availability in the console, it prints out what I expect, an ordered list of patches.
But if I do
let test-variable availability
show test-variable
it returns
ERROR: Nothing named TEST-VARIABLE has been defined.
is this a problem of scope somehow, can I not use let as an observer?
Is it a problem of type? Can I not store an agentset as a named turtle-owned variable?
Is there a way to do the same thing with a list instead of an agent set?
Thanks
From your description, it's a scoping problem. But the problem is not that you are trying to use let with an observer, it's the scope of let. NetLogo is not really interactive in the sense you are trying to do - the variable created by let is thrown away at the end of the line.
If you type let test 3, hit enter, then type show test, you will get the same error. However if you type let test 3 show test, then it will return 3.
Why are you needing this from the console? If it's for testing, then you can look at it the way you have already found - simply by show availability. If you are using it for turtles while the model is running, then it is not interactive and there's no problem.

How to reciprocate?

Actually I am coding a Matlab simulation where the AnchorID and SourceID will report to eachother. For example if I take an anchor 30 and source 50 it will collect all the agc values between these anchor and source and calculate rssi_dB and display them.Below mentioned is an example of anchor 30 and source id 50
Note: list of anchors ID's and source ID's are same. for e.g. 30 50 55 58 . These ID are both same for anchor and source.
function A30(BlinkSet)
for i=1:length(BlinkSet)
xAnchorID=30;
xSourceID=50;
a=BlinkSet{i}.AnchorID;
b=BlinkSet{i}.SourceID;
if xAnchorID==a && xSourceID==b
xagc=BlinkSet{i}.agc;
rssi_dB(i)=-(33+xagc*(89-33)/(29-1));
end
end
rssi_dB(rssi_dB==0)=[];
rssi_dBm=sum(rssi_dB(:))/length(rssi_dB);
disp([sprintf('The rssi value is %0.0f',rssi_dBm)]);
When I call the function in Matlab command window I get the rssi value of the above function.
Also my task is when I reciprocate the Anchor ID and source ID say Anchor as 50 and source as 30 like the function I have mentioned below I get an error which is mentioned after the function below.
function A50(BlinkSet)
for i=1:length(BlinkSet)
xAnchorID=50;
xSourceID=30;
a=BlinkSet{i}.AnchorID;
b=BlinkSet{i}.SourceID;
if xAnchorID==a && xSourceID==b
xagc=BlinkSet{i}.agc;
rssi_dB(i)=-(33+xagc*(89-33)/(29-1));
end
end
rssi_dB(rssi_dB==0)=[];
rssi_dBm=sum(rssi_dB(:))/length(rssi_dB);
disp([sprintf('The rssi value is %0.0f',rssi_dBm)]);
When I call this function I get an error as
??? Undefined function or variable "rssi_dB".
Error in ==> A50 at 14
rssi_dB(rssi_dB==0)=[];
Error in ==> main_reduced at 26
A50(BlinkSet);
In main function I have coded like this,
%A30(BlinkSet);
A50(BlinkSet);
Any help is highly appreciated.
In both of these functions, you only create the variable rssi_dB if execution enters the if statement within the loop (i.e., if xAnchorID==a && xSourceID==b is at some point true). Clearly, this code is never executed in your A50 function. Without knowing what is in BlinkSet it's a bit difficult to diagnose the exact problem, but this is the cause at least.
As a side note: it's not a good idea to create two separate functions to do this job when their code is almost identical. You should add an input argument to your function that allows it to do the job of both. In this particular case, all that changes is the value of xAnchorID and xSourceID, so you could just pass these in:
function srcToAnchorRssi(BlinkSet, xSourceID, xAnchorID)
% The rest of the function stays the same!
If you want to provide some defaults for these arguments, you can do, e.g.:
if nargin < 3 || isempty(xAnchorID), xAnchorID = 50; end
if nargin < 2 || isempty(xSourceID), xSourceID = 30; end
It's always a good idea to include an isempty in statements of this sort, so that your function supports syntax like myFunction(myArg1, [], myArg3). Also note that the order of the operands to || is crucial; if you did if isempty(theArgument) || nargin < theArgumentNumber and the user did not pass theArgument, then it would error in the isempty because theArgument would not exist as a local variable. We can get around this by swapping the operands' order because MATLAB is smart enough to know it doesn't have to evaluate the right operand if the left operand is true (note that this is also the case in many other programming languages).