Hi,
I'm trying to implement a simple Component Entity System. The amount of systems (which are actually functions) is getting bigger, and I'm putting them in a table to iterate over to avoid implementing back and forth.
However, my iterator function using all(t)
does not work at all.
Here's the structure of my systems:
updatesystems = { system1 = function(t) [...] end, system2 = function(t) [...] end, system3 = function(t) [...] end, system4 = function(t) [...] end, } |
t
is a table which includes raw data of all entities.
This is my current codes, which work:
function _update() updatesystems.system1(world) updatesystems.system2(world) updatesystems.system3(world) updatesystems.system4(world) end |
What I would like to do
function _update() for system in all(updatesystems) do system(world) end end |
And I have no idea why it doesn't work. None of the systems updates.
Any suggestion?
all(t) only goes through the entries at t[1],t[2],t[3]...
I think you want this:
for key,system in pairs(t) do |
However, order is not guaranteed then! So maybe it would be better to drop the named table entries, and just store your functions in the default places, so you can use all(t) and know the order that the update functions happen in, like this:
updatesystems = { function(t) [...] end, --system1 function(t) [...] end, --system2 ... |
Omg, thank you so much. I scoured the web to no avail of how these were supposed to work.
This works:
for key,system in pairs(updatesystems) do system(world) end |
Thanks for the suggestion with the order as well. While order is not important for the update systems, I'm going to need it for the draw systems.
Thanks a bunch again. You're a lifesaver today!
[Please log in to post a comment]