简体   繁体   English

我应该采取什么方法来连续跳到有条件且没有循环的函数?

[英]What approach should I take to continuously skip to a function with conditions and no loops?

//Skip to 3rd paragraph for main point. //跳到第三段为要点。

First I want to mention I am a beginner to programming. 首先,我想提一下我是编程的初学者。 I have decided to start editing before I can create from scratch. 我决定开始编辑,然后才能从头开始创建。 So I found a script that can be used within an Internet Browser's Console (The inspect element thing) to perform many tasks. 因此,我找到了一个可以在Internet浏览器的控制台(检查元素)中使用的脚本来执行许多任务。 So at first the script was only the size of a paragraph but over the course of few days I have been adding and editing it (which I find really fun) to create a more custom script. 因此,起初脚本只是一个段落的大小,但是在几天的过程中,我一直在添加和编辑它(我觉得这很有趣)以创建更多自定义脚本。 I want to get to the point but without context it may be difficult to help me. 我想说清楚一点,但是如果没有上下文,可能很难帮助我。

So basically the script I have come up with uses alot of "Functions" I am not 100% what anything is even after studying but I know enough about what they do. 因此,基本上,我想出的脚本使用了很多“功能”,即使学习后,我也不是100%是什么,但是我对它们的作用了解得足够多。 So I use the functions to define conditions and to perform different tasks. 因此,我使用这些函数来定义条件并执行不同的任务。 I keep many functions to keep everything organized and to find mistakes. 我保留许多职能,以使一切井井有条,并找出错误。 However; 然而; the problem I am having now is the script is not working properly and I cant find my mistake. 我现在遇到的问题是脚本无法正常工作,我找不到我的错误。

MAIN POINT 重点

I have many functions going down in order but I want the script to go back up to the first function after certain conditions occur. 我有许多功能按顺序下降,但我希望脚本在某些情况发生后返回至第一个功能。 I want to do this without using loops if possible. 我想在不使用循环的情况下做到这一点。 The way I do it is by calling the function like "NameOfFunction"(); 我这样做的方式是通过调用“ NameOfFunction”()之类的函数;

Here is some of my code: 这是我的一些代码:

function roll() {
        if (Dloss === false) {
            if (loop === true) {
                tbBet.value = start;
                btRoll.click();
                refreshIntervalId = setInterval(roll2, delay);
            }
        }
        if (Dloss === true) {
            if (loop === true) {
                tbBet.value = start;
                btRoll.click();
                refreshIntervalId = setInterval(decision, delay);
            }
        }
    }
    function decision() {
        if (Dloss === true) {
            var thestring = document.getElementById('roll').value;
            var thenumber = retnum(thestring);
            if (thenumber < rollUnder) {
                start = (start * remain).toFixed(2);
            }
            if (thenumber > rollUnder) {
                start = (start * MultLoss).toFixed(2);
                if (start > maxBetValue) {
                    loop = false;
                }
                btRoll.click();
                clearInterval(refreshIntervalId);
                roll();
            }
            btRoll.click();
            clearInterval(refreshIntervalId);
            roll3();
        }
    }

So you can see where I have roll(); 这样您就可以看到我在哪里roll(); within an if statement. 在if语句中。 I want it to loop back up to the start but it doesnt seem to work. 我希望它循环回到开始,但似乎不起作用。 I am sorry if this is something that is obvious. 很抱歉,如果这是显而易见的话。 I am learning and after struggling for a while I have decided to post my question here. 我正在学习,经过一段时间的努力后,我决定在这里发表我的问题。 Thanks in advance for anyhelp. 在此先感谢您的帮助。

---------Edit 1----------- So what I want to do is call the function roll() over here: ---------编辑1 -----------所以我想做的就是在这里调用函数roll():

                     btRoll.click();
                    clearInterval(refreshIntervalId);
                    roll();

So am I calling this correctly as from what I have researched this is the only way? 那么我是否正确地称呼这是唯一的方法呢? Should I post the whole script here? 我应该在此处发布整个脚本吗? (BTW sorry I am new to the site aswell still learning how to use) (顺便说一句,对不起,我还是这个网站的新手,仍然在学习使用方法)

When a function ends, it returns to where the function was called. 当函数结束时,它返回到调用该函数的位置。 If you want the code in your decision function to happen after every roll you need to explicitly call decision() 如果您希望decision函数中的代码在每次roll后发生,则需要显式调用decision()

function roll() {
    if (Dloss === false) {
        if (loop === true) {
            tbBet.value = start;
            btRoll.click();
            refreshIntervalId = setInterval(roll2, delay);
        }
    }
    if (Dloss === true) {
        if (loop === true) {
            tbBet.value = start;
            btRoll.click();
            refreshIntervalId = setInterval(decision, delay);
        }
    }
    decision() // <--- Like so
}
function decision() {
    if (Dloss === true) {
        var thestring = document.getElementById('roll').value;
        var thenumber = retnum(thestring);
        if (thenumber < rollUnder) {
            start = (start * remain).toFixed(2);
        }
        if (thenumber > rollUnder) {
            start = (start * MultLoss).toFixed(2);
            if (start > maxBetValue) {
                loop = false;
            }
            btRoll.click();
            clearInterval(refreshIntervalId);
            roll();
        }
        btRoll.click();
        clearInterval(refreshIntervalId);
        roll3();
    }
}

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

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