worldobject:RegisterEvent 索引 worldobject 时出现错误

当我尝试使用网站上的示例来创建一个 worldobject registerevent 时,worldobject 上出现一个错误,说明它是一个 nil 值,如下所示:

lua_scripts/test.lua:5: attempt to index global 'worldobject' (a nil value)

尝试了几个不同的例子,但结果都一样,因此我认为这可能是我的疏忽。

测试的例子:

local function YourFunction(eventid, delay, repeats, worldobject)
      worldobject:SendUnitSay("我的名字是 " .. worldobject:GetName(), 255)
end
worldobject:RegisterEvent(YourFunction, 10000, 5)
local function Timed(eventid, delay, repeats, worldobject)
    print(worldobject:GetName())
end
worldobject:RegisterEvent(Timed, 1000, 5)

两者都返回开始时提到的错误。

点赞
用户11217287
用户11217287

你必须指定哪个世界对象应该具有该脚本。

以下是针对生物的示例:

local npcID = 100;
local YourNPC = {};

function YourNPC.YourFunction(eventid, delay, repeats, creature)
  creature:SendUnitSay("My name is " .. creature:GetName(), 255)
end

function YourNPC.OnSpawn(event, creature)
  creature:RegisterEvent(YourNPC.YourFunction, 10000, 5)
end

RegisterCreatureEvent(npcID, YourNPC.OnSpawn, 5)

在生物生成时,生物会以10秒的间隔说5次“我的名字是”。 它只适用于ID为“100”的生物,因此不要忘记更改ID。

官方Eluna文档:http://www.elunaengine.com/WorldObject/RegisterEvent.html

2019-06-19 21:15:14