我已经习惯了使用 foreach 语句在 PHP 中编程:
Lua中是否有与此等价的功能?
谢谢!
相关部分:
function renderobjects()
o1 = object:new{x = 30, y = 30, roomx = 0, roomy = 0, symbol = "t", name = "Tree"}
o2 = object:new{x = 47, y = 60, roomx = 0, roomy = 0, symbol = "w", name = "Water"}
o3 = object:new{x = 42, y = 30, roomx = 1, roomy = 0, symbol = "C", name = "Cactus"}
table.insert(o1, objects)
table.insert(o2, objects)
table.insert(o3, objects)
table.foreachi(objects, object) do
if player.roomx = object.roomx and player.roomy = object.roomy then
rb.putsxy(object.x, object.y, symbol)
end
end
end
local object = {
x = 30,
y = 30,
roomx = 0,
roomy = 0,
name = "Unknown Object",
touchingplayer = false,
symbol = "u"
}
function object:new (o)
o = o or {} -- create object if user does not provide one
setmetatable(o, self)
self.__index = self
return o
end