added solved; better way-check array of players for their surfaces instead.
previous short discussion happened on steam forums "steamcommunity.com/app/427520/discussions/1/1651045226224021692/"
As stated in the title, i'm looking for an option to
1) check all existing surfaces for active players and if it has at least 1 player on it, it gets added to a list
2) pick up a random surface from the list
3) save that surface to a variable
general ideas:
-number 3 is done done via "local surface = game.surfaces[index]" while index is a number.
-number 2 could be potentially done with sth like "local generator = game.create_random_generator()" followed by sth like "generator(1,n+0.99)" (n is the number of different surfaces with players on it, or more precisely, the size of the resulting array of number 1)
-number 1 is the problematic one, the idea looks like this:
Code: Select all
L = empty List
k = 1
while(game.surfaces[k] != nil){
if(curr_surface.has_active_player){
L.add = curr_surface (or do stuff on the current surface the player is on directly)
}
k += 1
}
Code: Select all
1: local surfaces = {};
2: for i, surface in ipairs(game.surfaces[i]) do
3: local entities = surface.find_entities_filtered{force = "player", type="character"};
4: if (entities ~= nil) then
5: local inner_surface = game.surfaces[i]
6: game.player.print(inner_surface.name)
7: --do_more_stuff_here
8: end
9: end
10: end
4-never enters the IF, probably caused by "2"
2-fel stated on steam that "for i, surface in ipairs(game.surfaces) do" is empty and my line with surfaces['i'] doesn't work either.
does anyone knows how to solve that issue?