• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua AddEvent

Shadowman321

Member
Joined
Mar 27, 2010
Messages
205
Reaction score
22
Test script with addEvent:
PHP:
function onThink(interval, lastExecution)    
	doBroadcastMessage("Started", MESSAGE_EVENT_ADVANCE)
	addEvent(spawn, 2 *1000)

function spawn()
	doBroadcastMessage("It works!", MESSAGE_EVENT_ADVANCE)
end
end
Errors:
> Broadcasted message: "Started".

[Error - GlobalEvent Interface]
data/globalevents/scripts/test.lua:onThink
Description:
(luaAddEvent) Callback parameter should be a function.
[Error - GlobalEvents::think] Couldn't execute event: a
> Broadcasted message: "Started".
[Error - GlobalEvents::think] Couldn't execute event: a
> Broadcasted message: "It works!".
> Broadcasted message: "Started".
[Error - GlobalEvents::think] Couldn't execute event: a
> Broadcasted message: "It works!".

In game:
04:52 Started
04:52 Started
04:52 It works!
04:53 Started
04:53 It works!

Can someone explain me some things with it?
First: Why it works even with error "Couldn't execute event"? And why it does not work first time?
Second: What is correct form of use:
addEvent(spawn, 2 *1000)
function spawn()
 
Last edited:
Callback parameter should be a function.
Ahh it not help.
What parameter and what function?!?
@Korrex
I tried this before and it not help, like said Fallen.

- - - Updated - - -

@Fallen
You are wrong.
Now i have fully working script:
function spawn()
doBroadcastMessage("It works!", MESSAGE_EVENT_ADVANCE)
end

function onThink(interval, lastExecution)
doBroadcastMessage("Started", MESSAGE_EVENT_ADVANCE)
addEvent(spawn, 2 *1000)
return true
end

Return true ok, but i have to moge function spawn() to the top and now it work fine.
But thanks for help :)
 
Back
Top