Jump to content

Getting ERROR about adding "Else" statement


Imthabawse

Recommended Posts

package larders;

import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "ImthaBawse", info = "Makes Larders", logo = "", name = "Larders", version = 0)

public class Larders extends Script {

	
	
	@Override
	public void onStart() {
		log("Let's make some Larders!");
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		if (!objects.closest("Larder Space").interact("Build")) {
		return 0;
	} else {
		new ConditionalSleep(3000) {
			@Override
			public boolean condition() {
				RS2Widget widget = widgets.get(458, 5, 4);
				return widget.isVisible();
			}
		}.sleep();
	
        if (widgets != null) {
        	widgets.interact(458, 5, 4, "Build"); {
        		return 0;
        	}
        }
		
		if (!objects.closest("Larder").interact("Remove")) {
			return 0;
		} else {
			new ConditionalSleep(3000) {
				@Override
				public boolean condition() {
					RS2Widget removeMenu = widgets.get(219, 1, 1);
					return removeMenu.isVisible();
				}
			}.sleep();
			
			if (widgets != null) {
				widgets.interact(219, 1, 1, "Remove"); {
					return 0;
				}
			}
				
			if (getInventory().getAmount("Oak plank") > 5) {
			RS2Widget settings = widgets.get(548, 35);
			if(settings == null) {
				return 0;
			}
		settings.interact(); {
			if(settings == null) {
				return 0;
			}
		RS2Widget house = widgets.get(261, 99);
		if(house == null) {
			return 0;
		}
		house.interact(); {
			if(house == null) {
				return 0;
			}
		RS2Widget servant = widgets.get(370, 19, 0);
		if(servant == null) {
			return 0;
		}
		servant.interact(); {
			if(servant == null) {
				return 0;
			}
		RS2Widget unote = widgets.get(219, 1, 1);
		if(unote == null) {
			return 0;
		}
		unote.interact(); {
			if(unote == null) {
				return 0;  // Error is here says: Multiple markers at this line
	                       // - Syntax error, insert "}" to complete Block
	                       // - Syntax error, insert "else Statement" to complete 
	                       // IfStatement
	                        // - Syntax error, insert "}" to complete Statement
	                         // - Syntax error, insert "else Statement" to complete 
	                          // BlockStatements
			}
		

	@Override
	public void onExit() {
		log("Phew..Let's take a break.");
	}
	
}

I'm sure it's something stupid like to many "IF" statements and "returns".. any help would be appreciated! ?

Edited by Imthabawse
Link to comment
Share on other sites

27 minutes ago, Spider Scripts said:

you need to add a "}" to close the else statement

 

So it's not asking me to add "else" statements? I've added another "}" at the indicated error line and I still get: 

- Syntax error, insert "}" to complete Block
	- Syntax error, insert "}" to complete Statement
	- Syntax error, insert "else Statement" to complete 
	 IfStatement

Error occurs here: 

unote.interact(); {
		if(unote == null) {
				return 0;
			}	
		} // This gives off the error asking for "}" to complete block 
	}	// But adding another "}" just adds error some where else I'm lost L

Keep in mind I'm very new to scripting don't h8 to much lol. 

Link to comment
Share on other sites

59 minutes ago, Imthabawse said:

So it's not asking me to add "else" statements? I've added another "}" at the indicated error line and I still get: 


- Syntax error, insert "}" to complete Block
	- Syntax error, insert "}" to complete Statement
	- Syntax error, insert "else Statement" to complete 
	 IfStatement

Error occurs here: 


unote.interact(); {
		if(unote == null) {
				return 0;
			}	
		} // This gives off the error asking for "}" to complete block 
	}	// But adding another "}" just adds error some where else I'm lost L

Keep in mind I'm very new to scripting don't h8 to much lol. 

You've put a semicolon after 'unote.interact()'. This ends the statement and as such your braces aren't doing what you think they are. Here's how your current code should be formatted

unote.interact();
{
  if (unote == null) {
    return 0;
  }
}
}

As you can see, your brackets do not match as you have two closing brackets on the same level.

With that said, I have no idea what you're trying to do in this code?

Apa

  • Like 1
Link to comment
Share on other sites

@Apaec Thanks for the reply so if I'm understanding you correctly the code should read:  

unote.interact();
		{ // <---
			if (unote == null) {
				return 0;
			}
		}

So whats the difference of moving the "{" here:  

unote.interact(); { // <---- 
	    if(unote == null)
				return 0; 
			}			

Also just trying to make a simple Oak larder maker that will, "Build", "Remove", "Call Butler to un-note planks, repeat. Had it working in my first project that used a simple "sleep(time)" but it would continuously build, remove, maybe call butler couple times, then eventually loop on trying to "Build". Example code of v1 here: 

RS2Widget house = widgets.get(261, 99);
				if(house != null) {
					house.interact(); {
						sleep(1000);

Was working on adding ConditionalSleeps example: 

if (!objects.closest("Larder").interact("Remove")) {
			return 0;
		} else {
			
			new ConditionalSleep(3000) {
			    @Override
				public boolean condition() {
					RS2Widget removeMenu = widgets.get(219, 1, 1);
					return removeMenu.isVisible();
				}
			 }.sleep();
		
			if (removeMenu == null || !removeMenu.interact()) { // This line here would not work 
				return 0;                // Kept getting: - removeMenu cannot be resolved to a 
	                                                        variable
	                                                        - removeMenu cannot be resolved

So with that being said I've still got a lot of learning and tinkering around to do lol.. appreciate all the feedback though!

Link to comment
Share on other sites

Started over completely with this project now so far I have: 

@Override
	public void onStart() {
		log("Welcome to Simple larders! Let's get started.");
	}
	
	@Override
	public int onLoop() throws InterruptedException {
	
		Entity larder_space = getObjects().closest("Larder space");
		if (larder_space != null && larder_space.interact("Build")) {
			new ConditionalSleep(5000) {
				@Override
				public boolean condition() {
					return !larder_space.exists();  // Not sure I'm using this right either 
					}
				}.sleep();
		
		RS2Widget buildlarder = getWidgets().get(458, 5, 4);
		if (buildlarder != null && buildlarder.interact("Build")) {
			new ConditionalSleep(5000) {
				@Override
				public boolean condition() {
					return myPlayer().isAnimating();
				}
			}.sleep();
	
		Entity larder = getObjects().closest("Larder");
		if (larder != null && larder.interact("Remove")) {
			new ConditionalSleep(5000) {
				@Override
				public boolean condition() {
					return !larder.exists();
				}
			}.sleep(); // ERROR HERE
		
	
	@Override
	public void onExit() {
		log("Thanks for using Simple larders!");
	}
}

So I'm getting this ERROR so far:  - Syntax error, insert "}" to complete Statement
                                                      - Syntax error, insert "else Statement" to complete IfStatement
                                                      - Syntax error, insert "}" to complete MethodBody

 

My plan was to add a check to see if I had "Oak planks" in my inventory. If not then call servant via widgets maybe widgets containing text and un-note planks and wait if not enough "Oak planks" to build or continue to build till he gets back. Then if he's still holding planks for me grab them when inventory space is available. 

I guess the big question here is if I add a conditional sleep at the end of every interaction like I'm doing is that gonna keep leading to problems like this? I feel like I'm so close to getting this script up and running but 1 or 2 stupid errors are keeping it from happening ? 

But nonetheless not giving up on this project as there isn't anything on the SDN other than 2 "AIO" builders that you have to pay for and I believe the community would greatly benefit from this as a FREE script.

With that being said any suggestions, snippets, bashing, etc are welcome lol. 

 

im-trying-my-best.jpg

Link to comment
Share on other sites

10 minutes ago, Mr_MilkysButler said:

You have 3 missing braces, please learn how to properly brace.

https://imgur.com/a/m6E0WPd

So when I add a } in all indicated spots my script lit up red

 

@Override
	public int onLoop() throws InterruptedException {
	
		Entity larder_space = getObjects().closest("Larder space");
		if (larder_space != null && larder_space.interact("Build")) {
			new ConditionalSleep(5000) {
				@Override
				public boolean condition() {
					return !larder_space.exists();  // Not sure I'm using this right either 
					}
				}.sleep();
		}
		
		RS2Widget buildlarder = getWidgets().get(458, 5, 4);
		if (buildlarder != null && buildlarder.interact("Build")) {
			new ConditionalSleep(5000) {
				@Override
				public boolean condition() {
					return myPlayer().isAnimating();
				}
			}.sleep();
		}
	
		Entity larder = getObjects().closest("Larder"); // error here now
		if (larder != null && larder.interact("Remove")) { // error here now
			new ConditionalSleep(5000) {
				@Override
				public boolean condition() {
					return myPlayer().isAnimating();
				}
			}.sleep(); // error here now
		}
		
	
	@Override
	public void onExit() { // error here now
		log("Thanks for using Simple larders!");
	}
} // error here now 

Could you elaborate a little more on this? Just trying to learn if not I understand. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...