Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Why is this unreachable code?

Featured Replies

public enum State {
		LIGHT, COOK, BANK, WAIT;
	}

	public State getState() {

		RS2Object fire = objects.closest("Fire");

		if (!inventory.contains("Tinderbox") // NO TINDERBOX?
				|| inventory.onlyContains("Tinderbox") // ONLY TINDERBOX?
				|| !inventory.contains("Filler")) { // YOU'RE DONE COOKING?
			
			return State.BANK;
		} else if (fire != null) { //	HAHAAHAAAA WE DISCOVVEREEEDDD FIREEEE
			return State.COOK;
		} else {
			return State.LIGHT; // aww we have no fire :( BUT WEEEE SHALL MAKEEE ITT
		}
		return State.WAIT;
	}

 

return State.WAIT;

Impossible to get there because your final else will always return first.

} else if (fire.exists() && fire != null) {
  		return State.COOK;
} else if (!fire.exists() && fire == null) {
		return State.LIGHT;
} else {
  		return State.WAIT;
}

on top of what elliot already said, you should also check to see if the fire exists

1 hour ago, superuser said:

} else if (fire.exists() && fire != null) {
  		return State.COOK;
} else if (!fire.exists() && fire == null) {
		return State.LIGHT;
} else {
  		return State.WAIT;
}

on top of what elliot already said, you should also check to see if the fire exists

I laughed :boge:

Thanks

Edited by FrostBug

1 hour ago, FrostBug said:

I laughed :boge:

Thanks

what did you laugh at? did i fuck something up? i posted from my phone but the code looks fine to me

edit: you are very welcome though you fucking legend

Edited by superuser

8 hours ago, superuser said:

what did you laugh at? did i fuck something up? i posted from my phone but the code looks fine to me

edit: you are very welcome though you fucking legend

Well, calling any method on a null reference will throw a NullPointerException; and exists() is a method.

So the irony of doing something like

!fire.exists() && fire == null

can be appreciated, since it can never pass, and will throw errors whenever there's no fire.

9 hours ago, superuser said:

what did you laugh at? did i fuck something up? i posted from my phone but the code looks fine to me

edit: you are very welcome though you fucking legend

rickrolled_profile.png.0d61af42cf6423bf7

  • Author
12 hours ago, Prolax said:

rickrolled_profile.png.0d61af42cf6423bf7

 

So I'm confused what I'm supposed to get out of this.

public State getState() {

		RS2Object fire = objects.closest("Fire");

		if (!inventory.contains("Tinderbox") // NO TINDERBOX?
				|| inventory.onlyContains("Tinderbox") // ONLY TINDERBOX?
				|| !inventory.contains("Filler")) { // YOU'RE DONE COOKING?
			
			return State.BANK;
			
		} else if (fire.exists() && fire != null) { //	HAHAAHAAAA WE DISCOVVEREEEDDD FIREEEE
			return State.COOK;
		} else if (!fire.exists() && fire == null) {
			return State.LIGHT;
		} else {
			return State.WAIT;
		}
		
	}

Did what you said, and it says Dead Code. Also I've never used exists() before.

What's the difference in exists() and != null ?

Read the API and if it doesn't help you out, just have a separate file were you can test behavior of certain methods.  

On 8/30/2017 at 9:06 PM, superuser said:

} else if (fire.exists() && fire != null) {
  		return State.COOK;
} else if (!fire.exists() && fire == null) {
		return State.LIGHT;
} else {
  		return State.WAIT;
}

on top of what elliot already said, you should also check to see if the fire exists

He doesnt need the fire.exists() the else if (fire!=null) should work fine :)

As far as i am aware, the fire can never be null if it exists :think:

Edited by Ollie7xP

you should check if the fire is null BEFORE if you check if it .exists() . so it would look like : if(fire != null && fire.exists())

 

  • Author
1 hour ago, dreameo said:

Read the API and if it doesn't help you out, just have a separate file were you can test behavior of certain methods.  

Um, of course I read the api. 

 

exists

boolean exists()

Checks whether this Entity still exists or not.

Returns:

Whether this Entity still exists or not.

 

Still don't see how's that different from != null . Seems exactly the same to me?

 

Plus that isn't really the main question. Main question is why is my code unreachable and how do I fix it? 

Because the response earlier is giving me a Dead Code.

Stop being silly; all of you.

You should under no circumstance use exists() in this scenario.. It's an expensive method, and the fire will always exist if it isn't null since he just retrieved the instance.

Your question has been answered.

But additionally, make fire a field variable. Otherwise, you're going to have to re-find the fire when you come to cooking on the fire.

:edit:
Be sure to set the fire variable in your getState function.

Edited by liverare

  • Author
15 minutes ago, FrostBug said:

Stop being silly; all of you.

You should under no circumstance use exists() in this scenario.. It's an expensive method, and the fire will always exist if it isn't null since he just retrieved the instance.

You seem to understand the situation, does this look good to you?

I'm trying to use enums in my codes now to make them look cleaner.

public State getState() {

		RS2Object fire = objects.closest("Fire");

		if (!inventory.contains("Tinderbox") // NO TINDERBOX?
				|| inventory.onlyContains("Tinderbox") // ONLY TINDERBOX?
				|| !inventory.contains("Filler")) { // YOU'RE DONE COOKING?
			
			return State.BANK;
			
		} else if (myPlayer().isAnimating()) { // YOU'RE DOING STUFF???
			return State.WAIT;
		}
		else if (fire != null) { // OH LOOKIEE HERE, A FIREEE?
			return State.COOK;
		} else {
			return State.LIGHT; // NO FIREE?? Simple. JUST MAKE ONE!
		} 
		
	}

 

Just now, liverare said:

Your question has been answered.

But additionally, make fire a field variable. Otherwise, you're going to have to re-find the fire when you come to cooking the fire.

 

Sorry I'm dumb. The only answer I saw was the response from superuser, and it was giving me a dead code. The other thing was Frostbug explaining something but I didn't understand it.

 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.