is there a way to ask a patch to do something if it has a specific number of turtles on it? I don't know the exact commands for this, but it would look something like this
ask patch -10 0 [
if 10 turtles are on this patch [
ask patch 5 5 [
set color red
]
]
]
Related
first time poster.
I am a student working in netlogo.
I am running the Game if Thrones model and have an error.
The code works, but is appears when the humans defeat the nightlong, before the text comes up, I get an error message.
Code is:
If season = “winter” and count whitewalkers = 0 [
set season “spring”
ask patches with [ snow? ][
set snow? false
if else resources = 0 [
set pcolor brown
][
set pcolor green
]
]
user-message “The Night King has been defeated! Summer is back.”
stop
]
The error message is:
WITH expected a true/false value from (patch 70 253), but got 0 instead. Error while observer running WITH Called bu procedure GO Called by button “go”
Many thanks
I have tried removing the brackets, but I believe they are needed.
I have put more space in between the brackets, but that makes no difference.
NetLogo does not perform type inference and the ? at the end of such primitives is a convention to indicate to the reader of the code that it is a boolean type, but not a language feature. NetLogo’s compiler does not immediately assign a boolean value to a variable that has a ? in its name, but simply assumes that it is an integer and assigns 0.
You probably need to set the snow? variable to a default value before using it elsewhere in your code, probably on top of your model’s setup procedure.
Here is a simple piece of code to illustrate how to initialize boolean variables in NetLogo:
patches-own [snow?]
to show-snow
show "before assigning bool value"
show [snow?] of patches
ask patches [ set snow? false ]
show "after assigning bool value"
show [snow?] of patches
end
enter image description here
My model has links with defined duration, and I am trying to register the new links and the old ones in two different vectors.
The Problem: When I run the simulation the new links are stored correctly, but the old ones appear duplicated in the csv file. I am making a mistake at some point and I really need some help. If there is a more elegant way of doing it, I appreciate the tips! Thanks all for the collaboration!
ifelse not link-neighbor? myself
[
create-new-links-with partner in-radius 0.1
ask new-links
[
set registernew []
set link-duration max (list duration maxduration)
set link-creation time:copy dt
set link-end time:plus link-creation link-duration "year"
set link-installment invtransf
set meets 1
set registernew ([(list link-creation link-duration link-end link-installment meets end1 end2) ] of new-links)
add-records
set breed old-links
]
]
[
ask old-links
[
set registerold [ ]
set meets time:copy dt
set registerold ([(list link-creation link-duration link-end link-installment meets end1 end2) ] of old-links)
]
I haven't checked this, but I suspect that the problem is that you have bidirectional links WITH, not unidirectional links TO or FROM, so the old-links get reported by each end separately which duplicates their presence in the list.
Again I haven't tried this but you might set a flag-variable in each link at the start of each large pass, like, reported? to false, and then deep in the loop when you are about to report it see if it's already been reported and if not, go ahead ( report and set the flag ) and if it has, don't report it again but interrupt the run with a user-message and examine what just happened.
Wade
I am fully aware that similar questions may have been posted, but after searching it seems that the details of our questions are different (or at least I did not manage to find a solution that can be adopted in my case).
I currently have two files: "messyFile" and "wantedID". "messyFile" is of size 80,000,000 X 2,500, whereas "wantedID" is of size 1 x 462. On the 253rd line of "messyFile", there are 2500 IDs. However, all I want is the 462 IDs in the file "wantedID". Assuming that the 462 IDs are a subset of the 2500 IDs, how can I process the file "messyFile" such that it only contains information about the 462 IDs (ie. of size 80,000,000 X 462).
Thank you so much for your patience!
ps: Sorry for the confusion. But yeah, the question can be boiled down to something like this. In the 1st row of "File#1", there are 10 IDs. In the 1st row of "File#2", there are 3 IDs ("File#2" consists of only 1 line). The 3 IDs are a subset of the 10 IDs. Now, I hope to process "File#1" so that it contains only information about the 3 IDs listed in "File#2".
ps2: "messyFile" is a vcf file, whereas "wantedID" can be a text file (I said "can be" because it is small, so I can make almost any type for it)
ps3: "File#1" should look something like this:
sample#1 sample#2 sample#3 sample#4 sample#5
0 1 0 0 1
1 1 2 0 2
"File#2" should look something like this:
sample#2 sample#4 sample#5
Desired output should look like this:
sample#2 sample#4 sample#5
1 0 1
1 0 2
For parsing VCF format, use bcftools:
http://samtools.github.io/bcftools/bcftools.html
Specifically for your task see the view command:
http://samtools.github.io/bcftools/bcftools.html#view
Example:
bcftools view -Ov -S 462sample.list -r chr:pos -o subset.vcf superset.vcf
You will need to get the position of the SNP to specify chr:pos above.
You can do this using DbSNP:
http://www.ncbi.nlm.nih.gov/SNP/index.html
Just make sure to match the genome build to the one used in the VCF file.
You can also use plink:
https://www.cog-genomics.org/plink2
But, PLINK is finicky about duplicated SNPs and other things, so it may complain unless you address these issues.
I've done what you are attempting in the past using the awk programming language. For your sanity, I recommend using one of the above tools :)
Ok, I have no idea what a vcf file is but if the File#1 and File#2 samples you gave were files containing tab separated columns this will work:
declare -a data=(`head -1 data.txt`)
declare -a header=(`head -1 header.txt`)
declare fields
declare -i count
for i in "${header[#]}" ; do
count=0
for j in "${data[#]}" ; do
count=$count+1;
if [ $i == $j ] ; then
fields=$fields,$count
fi
done
done
cut -f ${fields:1} data.txt
If they aren't tab separated values perhaps it can be amended for the actual data format.
I am trying to apply the following condition:
if ( the color of patch -2 -1 is red )
[
some commands
]
Could someone please tell me how to write this in NetLogo?
if ([pcolor] of patch -2 -1 = red)
[
]
Pretty much how you put it but in code, read the tutorials and what not and this should be simple. Note that you use pcolor for patches and color for turtles.
I'm looking for a way to define a Bone animation system, I need a basic one, since my objective is to apply it for inverse kinematics, much like Flash supports.
The desirable feature is that: I can set bones (as position in 2D, defined by 2 dots) each having an ID. So I can make an animation based on frames, ie:
['l_leg', [10, 0],[ 13,30 ] ] ['r_leg', [30, 0 ], [13, 30] ] //Frame 1 (standing)
['l_leg', [10, 0],[ 13,30 ] ] ['r_leg', [35, 30], [13, 30] ] //Frame 2 (lifting right leg)
...
I'm confident that defining Joints ain't necessary.
The lib may be lib in Ruby, since I can port it to JS, but if in JS already is better :)
UPDATE: deprecated for a long time now.
I am developing my own: http://github.com/flockonus/javascriptinmotion
See Wikipedia: Express Animator.
1st result for Google: javascript skeletal.