Hello everyone,
I’m new in visual scripting and trying to add 2 AOT Lists to an AOT Dictionary variable using For Each Loop like this
When I run it the result is like this
I expect the result is
a: 1
b: 2
c: 3
d: 4
e: 5
Can somebody help me fix the graph so the result is just what I expected? thank you.
Hello there!
What you are doing is:
void Start()
{
foreach(string str in strings)
foreach(int integer in ints)
if(!dictionary.ContainsKey(str))
dictionary.Add(str, integer);
}
What I suspect you want is something like this (only one loop):
void Start()
{
for(int i = 0; i < strings.Count; i++)
if(!dictionary.ContainsKey(strings[i]))
dictionary.Add(strings[i], ints[i]);
}
So you should use one for each loop and use the List.GetItem method with the index given by the for each loop to get the value of the second list.

Means I should use one loop and one for each loop? What I got based on your answer is something like this, cmiiw.

and yet I still don’t know where to connect for each loop to get the value of the second list.
You only need one loop.
The GetItem node get you the element of your second list if you provide the current index of the loop.
Something like this

I don’t see your screenshot.
1 Like
Sorry about the screenshot, I’m updating with your last correction and be like this

It works, thank you.


1 Like