简体   繁体   English

Lua 睡眠和循环 function 问题

[英]Lua Sleep and Loop function problems

So my script currently stops on conditions所以我的脚本目前在条件下停止

if profit >= 0.1 then
    stop()
end

i want to implement this code into mine so after the target satified it will sleep for 30 secs and then restart my dobet function我想将此代码实现到我的代码中,因此在目标满足后它将休眠 30 秒,然后重新启动我的 dobet function

if found this如果发现这个

function sleep()
t0 = os.clock()
while os.clock() - t0 <= n do
      end

but i cant find a way to restart after sleep and restart my dobet() function但我找不到在睡眠后重新启动并重新启动我的 dobet() function 的方法

my code sample我的代码示例

https://pastebin.com/2Vi2iC81 https://pastebin.com/2Vi2iC81

try:尝试:

local function sleep(seconds)
    local time = os.time() + seconds
    repeat until os.time() > time
end

chance = 49.5
multiplier = 2
basebet = 0.00000010
bethigh = false
​
function dobet()
    while true do
        if profit >= 0.1 then
            break
        end
    
        if win then
            nextbet = basebet
        else
            nextbet = previousbet * multiplier
        end
        sleep(30)
    end
end

this should fix it, let me know if it does not fix it.这应该可以解决它,如果它没有解决它,请告诉我。

You can use goto to re-execute a code.您可以使用goto重新执行代码。

Example:例子:

-- Use local variable instead using global variable, the global method can slowdown your script

local function sleep(s) -- Define a sleep function 
  local ntime = os.time() + s
  repeat until os.time() > ntime
end


-- Setup
local chance = 49.5
local multiplier = 2
local basebet = .00000010
local bethigh = false


-- Main field
local function dobet()
  if profit >= .1 then
    stop()
    
    sleep(30) -- Sleep/Wait for 30 seconds
    goto restart -- Go back to "restart" point
  end

  if win then
    nextbet = basebet

    sleep(30) -- Doing the same thing
    goto restart
  else
    nextbet = previousbet * multiplier

    sleep(30)
    goto restart
  end
end

::restart:: -- Define a "goto" point
dobet()

You can also use the factorial function method to re-run the function inside the function itself您还可以使用factorial function方法重新运行 function 本身内部的 function

local n = 0

local function printHelloWorld()
  if n >= 10 then
    return -- Stop the function basically
  else
    print('Hello World!')

    n = n + 1
    printHelloWorld()
  end
end

printHelloWorld()

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM