Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • for loop, unused variable help?


    Banker
     Share

    Recommended Posts

    Okay so im working on a script that involves a spammer (as you can already tell from the code below), I'm trying to have it where i can stop/start the spamming at any point.

     

    When i try have the wait (return wait;) between messages the final part of the for loop code is reporting as unused, when i remove the return statement it is 'used' again and the warning disappears.

     

    Code:

    for(x = 0; x<messages.size(); x++) {
    				getKeyboard().type(messages.get(x));
    				//return wait;
    			}
    

    Note: messages is an ArrayList<String> && the variable 'x' is created at the top of the code.

    public int x = 0;
    

     This is so i can perform checks on the positioning of the bot, outside of the loops.

     

    Thanks.

    Link to comment
    Share on other sites

    What's the point of the loop if you just return out of it the first time it's called?

     

    shit, that would be the issue then, would sleep(wait); be more appropriate in having time between each message.

     

    Was pretty tired when i wrote it so mustve used return my mistake and not realised

    Link to comment
    Share on other sites

    shit, that would be the issue then, would sleep(wait); be more appropriate in having time between each message.

     

    Was pretty tired when i wrote it so mustve used return my mistake and not realised

    Yes, a return breaks the loop and returns the value of the wait variable.

    If you want the loop to wait a certain amount of seconds before executing again, you should use the sleep function

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.