worldobject:RegisterEvent error on indexing worldobject

Oli*_* D. 3 lua azerothcore eluna-lua-engine

When I attempt to use the examples shown on site for making a worldobject registerevent I get an error on the worldobject, implying it is a nil value like so:

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

Tried a few different examples with the same outcome, so naturally I expect its probably some oversight on my part.

Tested examples:

local function YourFunction(eventid, delay, repeats, worldobject)
      worldobject:SendUnitSay("My name is " .. worldobject:GetName(), 255)
end
worldobject:RegisterEvent(YourFunction, 10000, 5)
Run Code Online (Sandbox Code Playgroud)
local function Timed(eventid, delay, repeats, worldobject)
    print(worldobject:GetName())
end
worldobject:RegisterEvent(Timed, 1000, 5)
Run Code Online (Sandbox Code Playgroud)

Both return the error stated in the beginning.

小智 5

您必须指定哪个worldobject应该具有该脚本。

这是一个生物的例子:

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)
Run Code Online (Sandbox Code Playgroud)

在该生物产生物上,该生物会说5次“我的名字是”,延迟10秒。它仅对生物“ 100”起作用,因此,不要忘记更改ID。

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