如何将此PAWN示例翻译成 LUA?

我有一个新问题想问大家。

我想知道你们是否能在 Lua 中进行枚举(我不确定这是否是正确的名称)。

最好的方式是给你们展示一个使用 PAWN 的示例(如果你知道 C 类型语言的话,就能理解)。

#define MAX_SPIDERS 1000

new spawnedSpiders;

enum _spiderData {
    spiderX,
    spiderY,
    bool:spiderDead
}

new SpiderData[MAX_SPIDERS][_spiderData];

stock SpawnSpider(x, y)
{
    spawnedSpiders++;
    new thisId = spawnedSpiders;
    SpiderData[thisId][spiderX] = x;
    SpiderData[thisId][spiderY] = y;
    SpiderData[thisId][spiderDead] = false;
    return thisId;
}

这就是在 PAWN 中的样子,但我不知道如何在 Lua 中实现这个。目前这是我完成的:

local spawnedSpiders = {x, y, dead}
local spawnCount = 0

function spider.spawn(tilex, tiley)
    spawnCount = spawnCount + 1
    local thisId = spawnCount
    spawnedSpiders[thisId].x = tilex
    spawnedSpiders[thisId].y = tiley
    spawnedSpiders[thisId].dead = false
    return thisId
end

但显然它会出现错误,你们中的任何人都知道正确的做法吗?谢谢!

点赞
用户1009479
用户1009479

我不了解PAWN,但我想这就是你的意思:

local spawnedSpiders = {}

function spawn(tilex, tiley)
    local spiderData = {x = tilex, y = tiley, dead = false}
    spawnedSpiders[#spawnedSpiders + 1] = spiderData
    return #spawnedSpiders
end

给它一个测试:

spawn("第一个", "你好")
spawn("第二个", "世界")

print(spawnedSpiders[1].x, spawnedSpiders[1].y)

输出:第一个 你好

2013-09-24 12:23:21
用户204011
用户204011

像这样吗?

local spawnedSpiders = {}
local spawnCount = 0

function spawn_spider(tilex, tiley)
    spawnCount = spawnCount + 1
    spawnedSpiders[spawnCount] = {
      x = tilex,
      y = tiley,
      dead = false,
    }
    return spawnCount
end
2013-09-24 12:27:23