So I want to be able to use a function to create an NPC:
function create_npc(url,coords,message,event)
The “event” argument is for a function that’s supposed to be stored in the NPC for later use. However, I don’t know how to send a function to be called later on when it’s stored as a variable.
if message_id == hash("end_event") then
end_event = message.event
print(end_event)
end
if end_event then
--something something activate the function
end_event = nil
end
If anyone could help me with this, that would be great. Thanks ahead of time~
In Lua, you can store a function in a variable.
For example, when monkey patching a function:
local oldprint = print
print = function (...)
oldprint("special message!")
oldprint(...)
end
However, since you’re also mentioning the “message” table, it’s actually serialized by the engine, and we only support certain built in types. Functions are not supported.
I recommend sending a string or hash, to tell what mode the npc is in, and what function to execute later.