重复一组代码,但是增加值

早上好。

我尝试编写一个相当冗长的脚本,我想知道是否可以让我的生活更轻松。

这是我正在编写的示例:

-- 静态变量
chance = 49.5
nextbet = 0.00000010
base = 0.00000010
base2 = 0.00000010
a1 = 0
stage = 0
bethigh = false
a1b = 0
bigbalance = 0
bigloss = 0
bigbet = 0
counter = 0

function dobet()

counter += 1

--每次滚动数字时将此变量增加1
a1 += 1

-- 检查上次滚动的数字是否小于1,如果为真,则将变量重置为0
if (lastBet.roll < 1) then
    a1 = 0
end

-------------- 阶段--------------
if stage == 0 then
    if win then
        stage = 0
        nextbet = base
        chance = 49.5
    else
        nextbet = base
    end
end

if stage == 1 then
    if win then
        stage = 0
        a1 = 0
        nextbet = base2
        chance = 49.5
    else
        nextbet = previousbet*1.02
    end
end

------------ 阶段设定---------

if stage == 0 then
    if a1 >= (99/1*5) then
        stage = 1
        chance = 1
        nextbet = base2
    end
end
end

我希望实现的是。是复制此部分:

if (lastBet.roll < 1) then
    a1 = 0
end

并重复它,但增加数字1,如下所示:

if (lastBet.roll < 1) then
    a1 = 0
end

if (lastBet.roll < 2) then
    a2 = 0
end

if (lastBet.roll < 3) then
    a3 = 0
end

下一节将采用相同的方法:

if a1 >= (99/1*5) then
    stage = 1
    chance = 1
    nextbet = base2
end

我想复制/粘贴它,但也要增加数字1:

if a1 >= (99/1*5) then
    stage = 1
    chance = 1
    nextbet = base2
end

if a2 >= (99/2*5) then
    stage = 2
    chance = 2
    nextbet = base2
end

if a3 >= (99/3*5) then
    stage = 3
    chance = 3
    nextbet = base2
end

这不是关于我的脚本功能的问题,它按预期工作。但我需要让它变得更长,我想知道是否有一种方法可以重复代码部分,稍微更改一下值,以便我不必手动输入所有内容。

点赞
用户353147
用户353147

如果你将 aN 变量定义为一个 a 数组,那么你可以使用一个函数来处理第一个问题,并使用一个循环来处理第二个问题。

function CheckLast(last, roll)
    if last.roll < roll
        a[roll] = 0
    end
end

for i=1,10 do
    if a[i] >= (99/i*5) then
        stage = i
        chance = i
        nextbet = base2
    end
end
2018-04-16 15:43:54
用户9382587
用户9382587

在我和朋友之间,我们弄清楚了这个问题。

这里的问题是如何复制代码,因为我不知道数组或添加函数。

对于其他遇到这个问题的人,这里是我们的解决方法。

--定义静态变量
chance = 49.5
nextbet = 0.00000010
base = 0.00000010
base2 = 0.00000100
stage = 0
maxChance = 99
previousBetWasFail = false
counter = 0
betHigh = false
losspercent = 0
turnaround = 0
turn = 0
first = 0
lossstreak = 0
bb = 0

targets = {}
for i = 0, 3300, 1 do
    targets[i] = 0
end

function resetAll ()
    nextbet = base
    stage = 0
    chance = 49.5
    losspercent = 0
    turnaround = 0
    turn = 0
    first = 0
    lossstreak = 0
end

function dobet()

    counter += 1

    if win then
        lossstreak = 0
    end
    for i = 0, 3300, 1 do
        targets[i] = targets[i] + 1
    end

    for i = 0, 3300, 1 do
        if (lastBet.roll < (i/100)) then
            targets[i] = 0
        end
        if turnaround == 0 then
            if (targets[i] >= ((99/(i/100))*10)) then
                turnaround = 1
                nextbet = base2
                if turn == 0 then
                    chance = (i/100)
                    turn = 1
                end
            end
        else
            nextbet = (previousbet*((chance/50)+1))
            if win then
                resetAll()
            end
        end
    end
    if turnaround == 1 and first == 0 then
        nextbet = base2
        first = 1
    else
        if first >= 1 and turnaround == 1 then
            if !win then
                nextbet = (previousbet*((chance/50)+1))
            else
                resetAll()
            end
        end
    end
    if balance >= bb then
        bb = balance
    end
    print(balance)
    print(bb)
end
2018-04-17 05:42:37