How does ForEach react if more items are added?
Posted: Mon Apr 06, 2015 3:39 pm
Instead of trying out, I decided to ask in case there are some exceptions to this rule, especially since one already comes to my mind.
Suppose I am making a game with locations, and some sort of pathfinding might become one way or other necessary.
what comes to my mind first is that each location would have subtable called "neighbors".
as example:
what could happen during the program is, that i make some temporary table, like "locationstocheck = {}" Where i would use InsertItem to add more country names.
Idea would be that each name in that list, would do so that they would check through all their neighbors and in some certain cases, neighbors could be added to the locationstocheck list:
as you can see, the idea is that when the ForEach command goes through "t_locationstocheck" table, that table might grow during the process.
Hence how does Hollywood work with this?
1. It only executes table in its original form.
2. It also executes everything added to the end of the list during the process.
And if number 2, then how does index 0 work out? Since if i understood right, index 0 is executed last, but what if that index 0 has some neighbors that are added to the t_locationstocheck, does it then happen, that these ones are not executed at all, or will these new ones be executed as well, and if they are as well executed, then will index 0 be executed again?
And as last question regarding this; Are there some other things that I should take into consideration if I am planning to use this method?
Suppose I am making a game with locations, and some sort of pathfinding might become one way or other necessary.
what comes to my mind first is that each location would have subtable called "neighbors".
as example:
Code: Select all
locations = {
["Finland"] = [ neighbors = { "sweden", "norway", "russia", "estonia"} },
["Sweden"] = [ neighbors = { "Finland", "Norway", "denmark"} },
...
}Idea would be that each name in that list, would do so that they would check through all their neighbors and in some certain cases, neighbors could be added to the locationstocheck list:
Code: Select all
foreach(t_locationstocheck, Function (cell, data)
foreach(cell.neighbors, Function (index, value)
if index.friendly=true then insertitem(t_locationstocheck, value)
EndFunction)
EndFunction)Hence how does Hollywood work with this?
1. It only executes table in its original form.
2. It also executes everything added to the end of the list during the process.
And if number 2, then how does index 0 work out? Since if i understood right, index 0 is executed last, but what if that index 0 has some neighbors that are added to the t_locationstocheck, does it then happen, that these ones are not executed at all, or will these new ones be executed as well, and if they are as well executed, then will index 0 be executed again?
And as last question regarding this; Are there some other things that I should take into consideration if I am planning to use this method?