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
  • Errors in state enum?


    beefsteak

    Recommended Posts

    Getting some errors in my zamorak monk killing script (Github link here) and the state machine is not working. Still have to finish the script, but need to resolve these errors first. Newbie scripter here, learned DB2 scripting sorta but learning db3 now. Any tips appreciated. 

    lines 53 and 57 say "Type mismatch: cannot convert from String to Zmonks.State" 

    line 68 "state cannot be resolved to a variable" (guessing because of line 53, 57 errors)

     

    Link to comment
    Share on other sites

    In your State enum you have to make the `state` variable a String instead of "State". Later on when you do `this.state = state` you try to assign a State enum to a String, which is the problem.

    	public enum State {
    		FIGHTING("Fighting"), BANKING("Banking"), WINE("Wine");
            
    		// This needs to be changed to type String
    		private State state; // Should be `private String state;` instead
    
            ...
    	}

    Line 68 -- Don't forget to give your variable a type. Should be `State state = getState();`

    Link to comment
    Share on other sites

    2 hours ago, flipjazz said:

    In your State enum you have to make the `state` variable a String instead of "State". Later on when you do `this.state = state` you try to assign a State enum to a String, which is the problem.

    
    
    	public enum State {
    		FIGHTING("Fighting"), BANKING("Banking"), WINE("Wine");
            
    		// This needs to be changed to type String
    		private State state; // Should be `private String state;` instead
    
            ...
    	}

    Line 68 -- Don't forget to give your variable a type. Should be `State state = getState();`

    Great thank you, that helped a lot. Now I'm getting error line 89 on the break, saying I need to insert a }, but this makes more errors. Same at the end line 148, and the else in 142. Heres the updated code

    Link to comment
    Share on other sites

    randomNum isn't a method, it doesn't do anything. If you want the script to sleep for a random amount of time use:

    sleep(Calculations.random(min, max));
    Example: 
    	sleep(Calculations.random(1000, 3000)); // Sleeps 1-3 Seconds

    Inventory and DepositBox are static and should be used like this:
     

    DepositBox.Whatever()
    Inventory.Whatever()
    
    NOT: DepositBox().Whatever()
    	 Inventory().Whatever()


    Hope this helps! Welcome to Scripting :)

    Link to comment
    Share on other sites

    8 hours ago, PhilBox said:

    randomNum isn't a method, it doesn't do anything. If you want the script to sleep for a random amount of time use:

    
    sleep(Calculations.random(min, max));
    Example: 
    	sleep(Calculations.random(1000, 3000)); // Sleeps 1-3 Seconds

    Inventory and DepositBox are static and should be used like this:
     

    
    DepositBox.Whatever()
    Inventory.Whatever()
    
    NOT: DepositBox().Whatever()
    	 Inventory().Whatever()


    Hope this helps! Welcome to Scripting :)

    Thanks that was super helpful, still learning difference between static and dynamic. Only 2 small errors now, in lines 88 (says I need to insert a } to complete statement, but causes more errors) and on line 146 (says to delete else, but also causes more errors). Any thoughts? Updated the Github here 

    Thanks again

    Link to comment
    Share on other sites

    I think you still have a couple if-statements with `if {` but not closing it with a closing brace `}` later on.

    You might still have more errors after. If you're still stuck, I would recommend starting from scratch and just focus on adding one small thing at a time. Just focus on getting fighting working, then add in getting wines, and then banking. Would be a better learning experience then trying to get it all right in one go.

    Also are you using IntelliJ? It would help you a lot with getting your indents/tabs right and figuring out these errors. Would recommend the dreambot guides about intellij

    Link to comment
    Share on other sites

    23 hours ago, flipjazz said:

    I think you still have a couple if-statements with `if {` but not closing it with a closing brace `}` later on.

    You might still have more errors after. If you're still stuck, I would recommend starting from scratch and just focus on adding one small thing at a time. Just focus on getting fighting working, then add in getting wines, and then banking. Would be a better learning experience then trying to get it all right in one go.

    Also are you using IntelliJ? It would help you a lot with getting your indents/tabs right and figuring out these errors. Would recommend the dreambot guides about intellij

    Okay, thank you, I will try to find those missing closing brackets. I'm using Eclipse at the moment. Do the indents cause errors too or is it just a matter of formatting? Thanks

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • 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.