как остановить поток из функции?

Oxygenius

Потрачен
Автор темы
91
11
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Версия MoonLoader
.026-beta
как остановить поток из функции? напримере такого кода:

123:
require "moonloader"
local sampev = require "lib.samp.events"

function main()
    repeat wait(0) until IsSampAvailable()
    SampRegisterChatCommand('tt', tt1)
    status = false
    while true do
        wait(0)
    end
end

function tt1()
    if status == false then
        status = true
        lua_thread.create(function(ll)
            while true do
                print('один - 1')
                wait(1500)
                print('два - 2')
            end
        end)
    else
        --как тут остановить поток вызванный выше?
    end
end
 

whyega52

Eblang головного мозга
Модератор
2,866
2,846
как остановить поток из функции? напримере такого кода:

123:
require "moonloader"
local sampev = require "lib.samp.events"

function main()
    repeat wait(0) until IsSampAvailable()
    SampRegisterChatCommand('tt', tt1)
    status = false
    while true do
        wait(0)
    end
end

function tt1()
    if status == false then
        status = true
        lua_thread.create(function(ll)
            while true do
                print('один - 1')
                wait(1500)
                print('два - 2')
            end
        end)
    else
        --как тут остановить поток вызванный выше?
    end
end
lua_thread:terminate()

в теории так:
Lua:
require "moonloader"
local sampev = require "lib.samp.events"


local thread


function main()
    repeat wait(0) until IsSampAvailable()
    SampRegisterChatCommand('tt', tt1)
    status = false
    while true do
        wait(0)
    end
end

function tt1()
    if status == false then
        status = true
        thread = lua_thread.create(function(ll)
            while true do
                print('один - 1')
                wait(1500)
                print('два - 2')
            end
        end)
    else
        thread:terminate()
    end
end
 

Oxygenius

Потрачен
Автор темы
91
11
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
lua_thread:terminate()

в теории так:
Lua:
require "moonloader"
local sampev = require "lib.samp.events"


local thread


function main()
    repeat wait(0) until IsSampAvailable()
    SampRegisterChatCommand('tt', tt1)
    status = false
    while true do
        wait(0)
    end
end

function tt1()
    if status == false then
        status = true
        thread = lua_thread.create(function(ll)
            while true do
                print('один - 1')
                wait(1500)
                print('два - 2')
            end
        end)
    else
        thread:terminate()
    end
end
не то, потом уже еще раз не запустишь
 

Dmitriy Makarov

25.05.2021
Проверенный
2,514
1,140
не то, потом уже еще раз не запустишь
 

wojciech?

Известный
Проверенный
404
360
не то, потом уже еще раз не запустишь
Lua:
local status = false
local thread

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    repeat wait(0) until isSampAvailable()
    
    sampRegisterChatCommand("test", callback)
    wait(-1)
end

function callback()
    status = not status
    if status then
        thread = lua_thread.create(function()
            while true do
                wait(0)
            end
        end)
    else
        thread:terminate()
    end
end
 

Oxygenius

Потрачен
Автор темы
91
11
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Lua:
local status = false
local thread

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    repeat wait(0) until isSampAvailable()
   
    sampRegisterChatCommand("test", callback)
    wait(-1)
end

function callback()
    status = not status
    if status then
        thread = lua_thread.create(function()
            while true do
                wait(0)
            end
        end)
    else
        thread:terminate()
    end
end
Попробую