Jump to content

"Or" ||


Vurqol

Recommended Posts

I hadn't seen this anywhere in snippets over a quick glimpse.
Could be used to avoid a setting in a GUI, or shortening some code, making something look neater, all comes down to preference.

 

if (Banks.FALADOR_EAST.contains(myPlayer()) &&
        getInventory().contains("Rune essence") || getInventory().contains("Pure essence"));
walking.webWalk(ENTRANCE);


 

 

Edited by Vurqol
  • Like 1
Link to comment
Share on other sites

2 hours ago, Vurqol said:

I hadn't seen this anywhere in snippets over a quick glimpse.
Could be used to avoid a setting in a GUI, or shortening some code, making something look neater, all comes down to preference.


if (Banks.FALADOR_EAST.contains(myPlayer()) &&
        getInventory().contains("Rune essence") || getInventory().contains("Pure essence"));
walking.webWalk(ENTRANCE);

An if-statement terminated by ';' has no effect other than evaluating the expression. The webwalk will be executed regardless of your inventory content or location.
Additionally you should use parantheses to clarify your logic groupings; otherwise you'll quickly end up with results that weren't what you expected.

To clarify on the precedence a bit:
I assume by your example, you want to webwalk if you are in the bank and have either essence type. Like so:

inBank && (hasRuneEss || hasPureEss)

But since && has higher precedence than ||, what's actually happening is this:

(inBank && hasRuneEss) || hasPureEss

Which means that is doesn't matter if you are in the bank or not, as long as you have pure essence

Bit of an odd snippet still though.

Edited by FrostBug
  • Like 8
Link to comment
Share on other sites

1 hour ago, Vurqol said:

While you're right there are a lot of people who like to make their own scripts, or try too.

But rather lack the knowledge, and the basics to know what they're doing.

So they use methods such as copy and pasting until they understand the script that they're using.

A snippet is a snippet.


If you don't have any need for it, then it's not useful to you. Although it may be useful to others.

It'd be slightly useful if any part of it was correct. :boge:

As mentioned above, your walking call will be made no matter the outcome of your if statement, and your if statement as it stands currently checks if you're in the bank and your inventory contains rune essence OR your inventory contains pure essence, with no bank check.

The correct code would be:

if (Banks.FALADOR_EAST.contains(myPlayer()) && (getInventory().contains("Rune essence") || getInventory().contains("Pure essence"))) {
	// walk
}

although, you could just simplify it to:

if (Banks.FALADOR_EAST.contains(myPlayer()) && getInventory().contains("Rune essence", "Pure essence")) {
	// walk
}

 

Edited by HeyImJamie
Link to comment
Share on other sites

It's always great learning new things and being able to make your application more powerful. These operators are part of the basic set of Java operators, so most people here are confused as to why you are posting it.

Here is a list of all Java operators, make sure to familiarize yourself with all of them (except bitwise). Once you master everything, then try out the bitwise operators:

https://www.tutorialspoint.com/java/java_basic_operators.htm

 

 

  • Like 2
Link to comment
Share on other sites

  • Alek locked this topic
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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