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.

check if i have 2 logs in my inventory

Featured Replies

I'm pretty sure it's

boolean hasLogs = getInventory().getAmount("Logs") == 2;

if(hasLogs) {
    //...
}

Edited by fixthissite

Ya I guess so, but why waste a boolean on it?

Just put it straight in the condition? smile.png

We can look at:

if(hasTwoLogs)

without needing extra cognition to work out the 

getInventory().getAmount(...) == 2

in our heads. If we really care about how we determine we have two logs (which there is no reason to, unless there's a bug), we can look at the assignment, but now we aren't forced to; we are instead given an actual name to read.

 

It's a lot more useful when the condition has multiple expressions (|| or &&), but I still prefer it over placing the expression in the if statement. Slightly lowers the amount of thinking needed, as we can ignore the assignment (of the expression) without any confusion about the code.

 

Compilers will inline the value if they see it's effectively final (not modified after initialization), so there's no performance impact; it's just to make things easier to understand when it comes to reading the actual processing part. On top of that, worrying about such small changes should be avoided (micro-optimizations) as they can consume quite a bit of time over the course of a project, while giving no noticable performance boost. You should never pre-optimize anyways: always monitor your program AFTER writing it, to see where optimization is really needed :)

 

Keep in mind, that expression is a boolean, we are just storing it somewhere and giving it a name. Either way you do it, a single boolean is being allocated to the stack.

Edited by fixthissite

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.