Athylus Posted April 2, 2018 Share Posted April 2, 2018 Not sure what is happening here. My RAM is filling up and processor usage is skyrocketing. What is going wrong here? public class Combat extends Script { private Player me; private boolean changeToAttack = true; private boolean changeToDefence = true; private enum State { ATTACK, EAT } private State getState() { if (getSkills().getDynamic(Skill.HITPOINTS) < 4) { return State.EAT; } else if (!getCombat().isFighting()) { return State.ATTACK; } else { return null; } } @Override public void onStart() { log("Welcome!"); me = getPlayers().myPlayer(); } @Override public void onExit() { } @Override public int onLoop() throws InterruptedException { switch(getState()) { case ATTACK: Attack(); break; case EAT: Eat(); break; default: break; } return 225; } private void Eat() { // TODO Auto-generated method stub } private void Attack() { /* if (changeToAttack) { if (getSkills().getStatic(Skill.STRENGTH) > 9) { if (getWidgets().interact(548, 48, null)) { if (getWidgets().interact(593, 3, null)) { changeToAttack = false; } } } } if (changeToDefence) { if (getSkills().getStatic(Skill.STRENGTH) > 9 && getSkills().getStatic(Skill.ATTACK) > 9) { if (getWidgets().interact(548, 48, null)) { if (getWidgets().interact(593, 15, null)) { changeToDefence = false; } } } } */ @SuppressWarnings("unchecked") NPC monster = getNpcs().closest(new Filter<NPC>() { @Override public boolean match(NPC npc) { return npc != null && npc.getName().equals("Chicken") && npc.exists() && getMap().canReach(npc) && npc.getHealthPercent() > 0 && npc.getInteracting() == null; } }); if (monster.isVisible()) { if (monster.hasAction("Attack")) { if (monster.interact("Attack")) { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } } } } @Override public void onPaint(Graphics2D g) { /* List<Position> areaList = choppingArea.getPositions(); g.setColor(Color.GREEN); for (int i = 0; i < areaList.size(); i++) { g.draw(areaList.get(i).getPolygon(getBot())); } */ } } Quote Link to comment Share on other sites More sharing options...
TrekToop11 Posted April 2, 2018 Share Posted April 2, 2018 Check your getState() Quote Link to comment Share on other sites More sharing options...
k9thebeast Posted April 2, 2018 Share Posted April 2, 2018 1 hour ago, TrekToop11 said: Check your getState() Wouldn't that be a Nullpointerexception? 1 Quote Link to comment Share on other sites More sharing options...
d0zza Posted April 2, 2018 Share Posted April 2, 2018 Instead of returning null in your getState() which is what's causing the problem, return a state in which you do nothing. For future problems check the osbot logger when you're having issues, it'll tell you where exactly in your code there is an NPE, etc. 1 Quote Link to comment Share on other sites More sharing options...
FrostBug Posted April 3, 2018 Share Posted April 3, 2018 one trillion NullPointerExceptions 1 1 Quote Link to comment Share on other sites More sharing options...
Athylus Posted April 3, 2018 Author Share Posted April 3, 2018 Great! Thanks d0zza & co. It's working now. Quote Link to comment Share on other sites More sharing options...