CJ7 Posted May 12, 2018 Share Posted May 12, 2018 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 The logger 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? Quote Link to comment Share on other sites More sharing options...
zwaffel Posted May 12, 2018 Share Posted May 12, 2018 (edited) 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 May 12, 2018 by zwaffel Quote Link to comment Share on other sites More sharing options...
Alek Posted May 12, 2018 Share Posted May 12, 2018 The method will do nothing anyways since you're using interact. 2 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted May 12, 2018 Share Posted May 12, 2018 (edited) 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 The logger 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 May 12, 2018 by Khaleesi Quote Link to comment Share on other sites More sharing options...
CJ7 Posted May 12, 2018 Author Share Posted May 12, 2018 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! 2 Quote Link to comment Share on other sites More sharing options...
Schepto Posted May 13, 2018 Share Posted May 13, 2018 Why are you doing a null check inside a lamda? Just try except null and put the lamda cast into the try block. Quote Link to comment Share on other sites More sharing options...