Ошыбка в коде, хелп пж

Статус
В этой теме нельзя размещать новые ответы.

Afakalix

Новичок
Автор темы
6
0
Форматирование кода
Версия MoonLoader
.027.0-preview
require "moonloader"
local keys = require "vkeys"
kd = 1
function main()
if not isSampLoaded() or not isSampfuncsLoaded()
then return
end
while not isSampAvailable() do wait(100) end
sampAddChatMessage('Shortcuts script downloaded succesfully', 0xC0C0C0)
sampRegisterChatCommand("checkanim", checkanim)
while true do
wait(0)
end

function checkanim()
while true do
wait(5000)
sampSendChat("/anim 8")
end
end




Ошыбка:

[ML] (error) shortcuts.lua: C:\Games\ARIZONA GAMES\bin\Arizona\moonloader\shortcuts.lua:99: attempt to yield across C-call boundary
stack traceback:
[C]: in function 'wait'
C:\Games\ARIZONA GAMES\bin\Arizona\moonloader\shortcuts.lua:99: in function <C:\Games\ARIZONA GAMES\bin\Arizona\moonloader\shortcuts.lua:97>
[ML] (error) shortcuts.lua: Script died due to an error. (id:6)


Если что речь о wait(5000)
цель: писать /anim 8 каждые 5 секнуд
 
Решение
Lua:
require "moonloader"
local keys = require "vkeys"

kd = 1
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
        sampAddChatMessage('Shortcuts script downloaded succesfully', 0xC0C0C0)
        sampRegisterChatCommand("checkanim", checkanim)

    wait(-1)
end

function checkanim()
    lua_thread.create(function()
        while true do wait(5000)
            sampSendChat("/anim 8")
        end
    end)   
end

Хотя я бы рекомендовал такой код
Если понадобится могу оставить комментарии
Lua:
require "moonloader"
local keys = require "vkeys"

local kd = 1
local timer = -1
local check = false
function main()
    if not isSampLoaded() or...

qdIbp

Автор темы
Проверенный
1,450
1,190
Lua:
require "moonloader"
local keys = require "vkeys"

kd = 1
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
        sampAddChatMessage('Shortcuts script downloaded succesfully', 0xC0C0C0)
        sampRegisterChatCommand("checkanim", checkanim)

    wait(-1)
end

function checkanim()
    lua_thread.create(function()
        while true do wait(5000)
            sampSendChat("/anim 8")
        end
    end)   
end

Хотя я бы рекомендовал такой код
Если понадобится могу оставить комментарии
Lua:
require "moonloader"
local keys = require "vkeys"

local kd = 1
local timer = -1
local check = false
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
        sampAddChatMessage('Shortcuts script downloaded succesfully', 0xC0C0C0)
        sampRegisterChatCommand("checkanim", function() check = not check print(check) end)

    while true do wait(0)
        if timer < os.time() and check then
            sampSendChat("/anim 8")
            timer = os.time() + 5
        end
    end
end
 
Статус
В этой теме нельзя размещать новые ответы.