Jump to content
CJ7

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

Recommended Posts

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? 

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...