Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Tutorial Correct use of If Statements

Java Warlord
Joined
Nov 17, 2014
Messages
4,906
If statements themselves dont add any real overhead whatsoever. The real cause of unoptimized bots is not reusing already processed data.
For example you should calculate the distance once and save it in a variable, instead of calculating it 3 times in a row for the same block of code.

Doesnt mean that you shouldnt care about an optimized controlflow though, in fact it can solve other problems such as sticking to one action per loop.
 
Also you picked a bad example, the original code is perfectly fine and only 1 of those if statements can be executed anyway. Whereas your version has side effects.
 
Primate
Joined
Oct 30, 2014
Messages
3,448
424450273218527234.png
 
Java Warlord
Joined
Nov 17, 2014
Messages
4,906
Nevertheless the me.distance.other is a variable its just how I prefer to have my naming conventions when writing sudo code
I wasn't immediately referencing your code, i was just expanding on the example you gave for simplicity.

Runemate occassionally spits out the wrong value especially when calculating distance as with almost any client and you want to have some fail safe or a brief update period to verify that the value coming through is actually correct.
I mean this is pretty much irrelevant to the discussion but i dont see how distance calculations could possibly be wrong, assuming you're selecting the correct entities to begin with.

I dont know how you do yours but you couldnt accurately or even effceintly implement advanced playersense into code which is just 100's of if statements.
PlayerSense is merely an API for persisent key-value mapping, how or where you apply it in your code is completely unrelated.


So again, optimizing the control flow will almost naturally result in less redundant computations, but if statements are inherently not a factor considering how complex other computations are in comparison.
 
Joined
May 30, 2019
Messages
13
If you want to prove a point, provide evidence. Make some runtime tests comparing "shitty' if statements with your constructs. You're just guessing right now, wouldn't want to be an ignorant programmer in court now would we? :D
 
12 year old normie
Joined
Jan 8, 2015
Messages
2,769
You're hella clueless brother. 4 years developing bots and you're talking about if statement efficiency?

Almost everything you say isn't fully correct and you sound like you have to Google what stuff means and then insert words that you think make you sound smart.

What the fuck does polymorphism have to do with using if statements... Overloading functions does not cause stability issues.... Reusing implementations is actually a good thing to do to avoid rediscovering the wheel....

And your English is abhorrent.
 
#1 Fabric Cleaner
Joined
Mar 18, 2017
Messages
393
Yes their are more advanced computations but most people who this is aimed at don't actually ever use them correctly and when you put that with their poor basic programming language it stems the overheads and this is because its much easier to optimize a if statement than it is calculations.

Bro what???

Don’t worry about the distance returning the wrong value, that’s a point of abstraction that is not your area of concern but that of the client developer/whoever created that method in the first place... This will hold up in court as it up to the creator of the method to ensure it works properly. If you build your code around these api abstractions, your code will run absolutely fine due to the very nature of Runemates bot architecture which can handle/correct inaccuracies loop to loop. In addition your code will be guaranteed much more efficient if you take saviors advice and cache complex api calculations instead of “optimizing if statements” and this not only creates more efficient code, it is easier to do as you dont have to mess with any of the already established bot logic, assuming that it works fine already.... you should really at least learn fundamental computer science concepts before spouting nonsense.
 
Last edited:
Top