Reputation: 11
how to set the value of 1st turtle when comparing 2 turtles value in nested if like we have attribute age in turtles now if age of turtle 1 is greater then 20 then check age of turtle 2 in side the nested if of first if if the inner if condition true then set the value of age of turtle 1 here is the code example
let i 0
let j 0
let node1 one-of turtles
let node2 one-of turtles
;; initialize the distance lists
while [i < number-of-nodes]
[
set j 0
while [j < number-of-nodes]
[
set node1 turtle i
set node2 turtle j
;; zero from a node to itself
if i != j
[
ask node1
[
if value = 0
[
ask node2
[
if value = 0 [
; here what i do so i can set the value of node1
]
]
]
]
set j j + 1
]
set i i + 1
]
Upvotes: 1
Views: 70
Reputation: 17678
you can directly set the value with
ask node1 [set value XXX]
However, you might want to reconsider the approach. At the beginning you have let node1 one-of turtles
which randomly selects a turtle to be node1. But then you are overriding this assignment with loops to select specific turtles to be node1 and node2 that are nominated by your indices i and j. Using such an index relies on the turtles actually having who
numbers that are from 0 to number-of-nodes - 1. Relying on who numbers instead of using agentsets (or lists) is likely to lead to problems later on, because it will only work if you create all your node turtles before creating anything else that uses a who number, and never create (or delete) others.
Upvotes: 1