У меня какая то ошибка в вызове thread

Malenko

Новичок
Автор темы
18
3
Версия MoonLoader
.026-beta
samp:
require "lib.moonloader"
local keys = require "vkeys"
local imgui = require "imgui"
local sampev = require 'lib.samp.events'
local encoding = require "encoding"
encoding.default = 'CP1251'
u8 = encoding.UTF8

local tag = "[AutoSobeska]:"
local label = 0
local main_color = 0x5A90CE
local main_color_text = "{5A90CE}"
local white_color = "{FFFFFF}"
local gov_time = 0
local real_time = 0
local govka = 0

thread = lua_thread.create_suspended(thread_function)


local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(5)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand('autosobes', cmd_imgui)
    sampRegisterChatCommand('timesk', cmd_timesk)

    imgui.Process = false

    while true do
        wait(0)
        if main_window_state.v == false then
            imgui.Process = false
        end
    end
end

function cmd_imgui(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function imgui.OnDrawFrame()
    imgui.Begin("AutoSobeska", main_window_state)
    imgui.InputText(u8'Тут час и минута говки в таком формате: 2359', text_buffer)
    imgui.Text(text_buffer.v)
    if imgui.Button(u8"Забить говку") then
        govka = 1
        --gov_hour = string.sub(text_buffer.v, 1, 2)
        --gov_minute = string.sub(text_buffer.v, 3, 4)
        gov_time = text_buffer.v
        real_time = os.date("%H%M")
        while govka == 1 do
            thread:run()
    end
    end
    imgui.End()
end
function cmd_timesk()
    sampAddChatMessage(os.date("%H"), -1)
end
function thread_function(option)
        if real_time == gov_time then
            sampAddChatMessage('bebra', -1)
            wait(10)
    end
end
 

why ega

РП игрок
Модератор
2,550
2,242
samp:
require "lib.moonloader"
local keys = require "vkeys"
local imgui = require "imgui"
local sampev = require 'lib.samp.events'
local encoding = require "encoding"
encoding.default = 'CP1251'
u8 = encoding.UTF8

local tag = "[AutoSobeska]:"
local label = 0
local main_color = 0x5A90CE
local main_color_text = "{5A90CE}"
local white_color = "{FFFFFF}"
local gov_time = 0
local real_time = 0
local govka = 0

thread = lua_thread.create_suspended(thread_function)


local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(5)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand('autosobes', cmd_imgui)
    sampRegisterChatCommand('timesk', cmd_timesk)

    imgui.Process = false

    while true do
        wait(0)
        if main_window_state.v == false then
            imgui.Process = false
        end
    end
end

function cmd_imgui(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function imgui.OnDrawFrame()
    imgui.Begin("AutoSobeska", main_window_state)
    imgui.InputText(u8'Тут час и минута говки в таком формате: 2359', text_buffer)
    imgui.Text(text_buffer.v)
    if imgui.Button(u8"Забить говку") then
        govka = 1
        --gov_hour = string.sub(text_buffer.v, 1, 2)
        --gov_minute = string.sub(text_buffer.v, 3, 4)
        gov_time = text_buffer.v
        real_time = os.date("%H%M")
        while govka == 1 do
            thread:run()
    end
    end
    imgui.End()
end
function cmd_timesk()
    sampAddChatMessage(os.date("%H"), -1)
end
function thread_function(option)
        if real_time == gov_time then
            sampAddChatMessage('bebra', -1)
            wait(10)
    end
end
Скидывай сразу moonloader.log при создании темы на подобную тематику
 

Malenko

Новичок
Автор темы
18
3
Скидывай сразу moonloader.log при создании темы на подобную тематику
[16:09:24.421496] (error) AutoSobeska: attempt to call a nil value
stack traceback:
stack traceback:
[C]: in function 'run'
D:\ARIZONA GAMES\bin\Arizona\moonloader\Autosobes.lua:57: in function 'OnDrawFrame'
D:\ARIZONA GAMES\bin\Arizona\moonloader\lib\imgui.lua:1378: in function <D:\ARIZONA GAMES\bin\Arizona\moonloader\lib\imgui.lua:1367>
[16:09:24.423495] (error) AutoSobeska: Script died due to an error. (12676104)
 

Rezbirp

Известный
72
69
Или функцию запихни выше создания thread:

Lua:
function thread_function(option)
        if real_time == gov_time then
            sampAddChatMessage('bebra', -1)
            wait(10)
    end
end

thread = lua_thread.create_suspended(thread_function)

Или создание thread в main()

Lua:
function main()
    thread = lua_thread.create_suspended(thread_function)
end

function thread_function(option)
        if real_time == gov_time then
            sampAddChatMessage('bebra', -1)
            wait(10)
    end
end
 

Malenko

Новичок
Автор темы
18
3
Или функцию запихни выше создания thread:

Lua:
function thread_function(option)
        if real_time == gov_time then
            sampAddChatMessage('bebra', -1)
            wait(10)
    end
end

thread = lua_thread.create_suspended(thread_function)

Или создание thread в main()

Lua:
function main()
    thread = lua_thread.create_suspended(thread_function)
end

function thread_function(option)
        if real_time == gov_time then
            sampAddChatMessage('bebra', -1)
            wait(10)
    end
end
Теперь просто зависает самп
 

Rezbirp

Известный
72
69
Теперь просто зависает самп
Не выходишь с while:

Lua:
while govka == 1 do
    thread:run()
end

Добавь ещё проверку, запущен ли поток, что б не кидать госку, столько раз, сколько ты нажал на кнопку.

Lua:
 if imgui.Button(u8"Забить говку") then
    
    --gov_hour = string.sub(text_buffer.v, 1, 2)
    --gov_minute = string.sub(text_buffer.v, 3, 4)
    gov_time = text_buffer.v
    real_time = os.date("%H%M")
    thread = lua_thread.create(
    function()
        while real_time ~= gov_time do
            wait(600)
        end
        sampAddChatMessage('bebra', -1)
        
    end)
end