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.

Can't get the getCamera().toEntity() to work

Featured Replies

Hey guys,

I'm having some problems writing my first script. It is a very basic chicken killer, as I'm just trying to understand the basics of script writing. I understand the logic behind it, but I got stuck when I couldn't get the getCamera().toEntity() to work. I'm pretty sure this is user error, but I can't get my head around exactly WHAT I'm doing wrong.

 

The code

image.thumb.png.befaf0f9eee40d383abb9b741c924bf1.png

The logger

image.png.198e22ab2a6bc5143a7b53394f840142.png

When there a chickens on my screen, I works just fine. It is when I start the script with the camera away from any chickens, that is gets stuck in the loop.

Following what I know: "Not in combat" was printed, so we are not in combat; "Found a chicken" was not printed, instead "No chicken found" was logged, which means chicken equaled null and therefore the block of code after } else { was activated; while the script DID log "No chicken found" it DID NOT move the camera to a chicken which was reachable etc. 

Is my logic flawed? What I'm I doing wrong? 

 

if (chicken != null)

//code

else{

here you do getCamera().teEntity(chicken);

But you only go here when chicken == null and you cant turn your camera to something that does not exist. 

}

Edit: nvm didnt count your bracers correctly. Do nullcheck on chicken before moving the camera. Also where you declare chicken as npc you have, chicken1.isVisible but this cant be true while the chicken IS NOT on your screen so it will always be null while you cant see the chicken. 

You are trying to move your camera to an entity that is only available when its on your screen so there wouldn't be a point turning your camera towards it. 

Edited by zwaffel

48 minutes ago, CJ7 said:

Hey guys,

I'm having some problems writing my first script. It is a very basic chicken killer, as I'm just trying to understand the basics of script writing. I understand the logic behind it, but I got stuck when I couldn't get the getCamera().toEntity() to work. I'm pretty sure this is user error, but I can't get my head around exactly WHAT I'm doing wrong.

 

The code

image.thumb.png.befaf0f9eee40d383abb9b741c924bf1.png

The logger

image.png.198e22ab2a6bc5143a7b53394f840142.png

When there a chickens on my screen, I works just fine. It is when I start the script with the camera away from any chickens, that is gets stuck in the loop.

Following what I know: "Not in combat" was printed, so we are not in combat; "Found a chicken" was not printed, instead "No chicken found" was logged, which means chicken equaled null and therefore the block of code after } else { was activated; while the script DID log "No chicken found" it DID NOT move the camera to a chicken which was reachable etc. 

Is my logic flawed? What I'm I doing wrong? 

 

You are only searching for chickens that are visible.
Thus there are no more chickens to turn the camera to since you only check for those that are visible?

Btw, just get rid of that, interaction of the client API will auto rotate and do what's needed for you.

Edited by Khaleesi

  • Author
1 hour ago, zwaffel said:

if (chicken != null)

//code

else{

here you do getCamera().teEntity(chicken);

But you only go here when chicken == null and you cant turn your camera to something that does not exist. 

}

Edit: nvm didnt count your bracers correctly. Do nullcheck on chicken before moving the camera. Also where you declare chicken as npc you have, chicken1.isVisible but this cant be true while the chicken IS NOT on your screen so it will always be null while you cant see the chicken. 

You are trying to move your camera to an entity that is only available when its on your screen so there wouldn't be a point turning your camera towards it. 

Reading this I can't see how I missed that. Thank you for taking the time to give me constructive feedback, much appreciated!

 

56 minutes ago, Khaleesi said:

You are only searching for chickens that are visible.
Thus there are no more chickens to turn the camera to since you only check for those that are visible?

Btw, just get rid of that, interaction of the client API will auto rotate and do what's needed for you.

I understand now. I was using the interact only, but when it didn't work I thought I misunderstood what it did, so I replaced it with getCamera to check if that worked (which ofcourse it didn't since I'm telling it to look for stuff that isn't there). I appreciate the feedback, thank you!

Why are you doing a null check inside a lamda? Just try except null and put the lamda cast into the try block.

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.