Alek Posted September 20, 2014 Share Posted September 20, 2014 objects.closest("Bank chest").interact("Use"); This method looks for an object called "Bank chest" and attempts to interact with it using "Use". If you attempt to interaction with the "Bank chest" using "Attack", the method will not work because "Bank chest" does not have the action "Attack". npcs.closest("Guard").interact("Attack"); Lets say you are killing guards, as the method shows above. What happens when you kill all the guards and this method is called? You will get an error called a "Null Pointer Exception", meaning that the method was called but it didn't work because the object reference (in this case the Guard) is null (meaning it doesn't exist). Here is how we would solve that problem: NPC guard = npcs.closest("Guard"); if(guard != null){ guard.interact("Attack"); } Here we create the NPC reference called "guard" and we define it using the npcs.closest() method. Now if npcs.closest("Guard") can't find any guards, "guard" will be defined as null. This information is used in the next line where we check if "guard" is null, meaning if no guards exist. If there is at least one guard that exists (not null or != null), we will interact with the guard using "Attack". 11 Link to comment Share on other sites More sharing options...
boyyo11 Posted October 25, 2014 Share Posted October 25, 2014 Hey man, im working on making a simple miner, with this should I use NPC's or objects, nd if I do the objects.get method what should it be put into like if(!myPlayer().isAnimating()){ if(inventory.isFull()){ inventory.dropAll(ore_id); } Entity rocks = objects.closest(rock_id); if(rocks != null){ rocks.interact("Mine"); sleep(random(25, 30)); } } I dont think that would be correc tho, because when I compile and export it has an error loading the class file it says, I came from rsbot so I know the background of coding, I just need help with this api 1 Link to comment Share on other sites More sharing options...
Apaec Posted October 25, 2014 Share Posted October 25, 2014 Hey man, im working on making a simple miner, with this should I use NPC's or objects, nd if I do the objects.get method what should it be put into like if(!myPlayer().isAnimating()){ if(inventory.isFull()){ inventory.dropAll(ore_id); } Entity rocks = objects.closest(rock_id); if(rocks != null){ rocks.interact("Mine"); sleep(random(25, 30)); } } I dont think that would be correc tho, because when I compile and export it has an error loading the class file it says, I came from rsbot so I know the background of coding, I just need help with this api NPC = Non player character. This means anything alive basically - enemies, guards, monsters, town criers, leprechauns, bankers etc etc Entity = the rest - rocks, trees, bank booths, cabbages, so on. Also, export as a jar. Link to comment Share on other sites More sharing options...
Alek Posted October 25, 2014 Author Share Posted October 25, 2014 Hey man, im working on making a simple miner, with this should I use NPC's or objects, nd if I do the objects.get method what should it be put into like if(!myPlayer().isAnimating()){ if(inventory.isFull()){ inventory.dropAll(ore_id); } Entity rocks = objects.closest(rock_id); if(rocks != null){ rocks.interact("Mine"); sleep(random(25, 30)); } } I dont think that would be correc tho, because when I compile and export it has an error loading the class file it says, I came from rsbot so I know the background of coding, I just need help with this api Try using RS2Object instead of Entity. Entity is an interface. 1 Link to comment Share on other sites More sharing options...