ChunkIterator with next
Posted: Sat Apr 15, 2017 2:46 pm
Hi guys,
I've been trying to use the ChunkGenerator as an iterator and have finally managed to do so in a somewhat elegant way. However, I'm still not sure about some things. Maybe someone can help me out with this!
As for why I'm using it as an iterator is due to the fact that I want to get some info from all the chunks, but I think limiting the chunks checked by tick is probably a good way to go.
Let's start:
From http://lua-api.factorio.com/latest/LuaC ... rator.html, we can see that some_surface.get_chunks() provides a ChunkIterator.
From various documentations I've seen, getting the next element of an iterator can be reached either calling the iterator function or next (I might be waaaay off here, but that was my conclusion of what I read).
So I set off trying both things:
This yields:
Let's try with calling the iterator:
The two arguments was what I found worked (as the function arity was complaining).
This seems to work, but now comes the question: what do those arguments mean?
Thanks in advance and sorry if this might seem a stupid question!
I've been trying to use the ChunkGenerator as an iterator and have finally managed to do so in a somewhat elegant way. However, I'm still not sure about some things. Maybe someone can help me out with this!
As for why I'm using it as an iterator is due to the fact that I want to get some info from all the chunks, but I think limiting the chunks checked by tick is probably a good way to go.
Let's start:
From http://lua-api.factorio.com/latest/LuaC ... rator.html, we can see that some_surface.get_chunks() provides a ChunkIterator.
From various documentations I've seen, getting the next element of an iterator can be reached either calling the iterator function or next (I might be waaaay off here, but that was my conclusion of what I read).
So I set off trying both things:
Code: Select all
local chunk_iter = surface.get_chunks()
local chunk = next(chunk_iter)
print(chunk, chunk.x, chunk.y)
So, wrong step.__self nil nil
Let's try with calling the iterator:
Code: Select all
local chunk_iter = surface.get_chunks()
local chunk = chunk_iter(1,1)
print(chunk, chunk.x, chunk.y)
This seems to work, but now comes the question: what do those arguments mean?
Thanks in advance and sorry if this might seem a stupid question!