假设我在 {game} 中有多个表格,例如 {bullets},其中 {bullets} 有多个表格,如下所示。我将如何遍历并调用 {game} 中包含的所有更新函数?
--下面是一个简化的例子,假设 {bullets} 中的每个表都有多个条目,而不仅仅是更新。并且最终代码必须在像 game={bullets,coins,whatever} 这样的情况下工作,每个条目都与子弹具有相似的性质。
game={}
game.bullets={{update=function(self) end,...}, {update=function(self) end,...},...}
for obj in all(game) do
for things in all(obj) do
things:update() end end
--我不确定我做错了什么以及是否需要双 for 循环。
--如果子弹没有嵌入到 {game} 中,它只是:
for obj in all(bullets) do
obj:update()
end
我也试过:
for obj in all(game.bullets) do
obj:update()
end
*更正:这行得通,但我想解决的问题是如果我在 {game} 中有多个像 {bullets} 这样的表,那么我要解决这个问题。因此,第一次尝试双迭代失败了。因此,与其在 {game} 中有项目一样多次重复上述内容,我想键入一个语句。