I was trying to update a bunch of global variables using the set command.
The global variables are the combinations of different strings.
For example, I have 6 global variables called:
a_x, b_x, c_x, a_y, b_y, c_y
I want to update the values of all six global variables into 1 using the foreach command.
Below is my code:
let a_x 0
let b_x 0
let c_x 0
let a_y 0
let b_y 0
let c_y 0
let first_list (list "a" "b" "c")
let second_list (list "x" "y")
foreach first_list [
[i] ->
foreach second_list [
[j] ->
set (word i "_" j) 1
]
]
I got the "This isn't something you can use "set" on" error message.
I guess I may need to convert the strings (word i "_" j) into a variable name so that the Netlogo can update it by the set command.
Is there any way that I can convert the strings into a variable name in the foreach loop in Netlogo?