Легенда форума
- Статус
- Оффлайн
- Регистрация
- 16 Сен 2018
- Сообщения
- 4,045
- Реакции
- 1,944
Небольшая функция для вызова функций с определенной задержкой, наговнокодила ночью за 5 минуток
JavaScript:
local functions_to_delay = {}
local current_time = g_GlobalVars.realtime
local function call_delay(fn, arguments, time)
current_time = g_GlobalVars.realtime
if fn == nil or time == nil then
if #functions_to_delay < 1 then return false end
for i = 1, #functions_to_delay do
if functions_to_delay[i] ~= nil and current_time > functions_to_delay[i].time_to_delay then
if functions_to_delay[i].params ~= nil then
functions_to_delay[i].funct(functions_to_delay[i].params)
else
functions_to_delay[i].funct()
end
table.remove(functions_to_delay, i)
end
end
return true
end
table.insert(functions_to_delay, {
funct = fn,
params = arguments,
time_to_delay = math.max(current_time + time + 0.01, current_time + time)
})
return true
end
local function test(params)
if params == nil then print("Arguments is nil")
elseif type(params) == "table" then print("Arguments is table") end
print(string.format("Called test function with '%s' argument.", params))
end
call_delay(test, {1, 2}, 1)
call_delay(test, "hello, cute traps!", 2)
local function onDraw()
call_delay()
end
Последнее редактирование: