April 2, 20187 yr 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())); } */ } }
April 2, 20187 yr 1 hour ago, TrekToop11 said: Check your getState() Wouldn't that be a Nullpointerexception?
April 2, 20187 yr 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.
Create an account or sign in to comment