简体   繁体   中英

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. 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. 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"();

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(); within an if statement. 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:

                     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()

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();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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