JAG98 4 Share Posted November 12, 2020 Just getting into scripting, okay-ish knowledge about JAVA. Second attempt at a combat script. Did not get this problem with the first one. Cross-checked and couldn't find any diff. Code snippet: Spoiler private enum State{ HEALING, FIGHTING, LOOKING, MOVING } private State getState(){ if(healArea.contains(getLocalPlayer())){ if(getCombat().getHealthPercent() != 100){ state = State.HEALING; } else{ state = State.MOVING; } } if(combatArea.contains(getLocalPlayer())){ if(getLocalPlayer().isInCombat()){ if(getLocalPlayer().getHealthPercent()<30){ state = State.MOVING; } else{ state = State.FIGHTING; } } else{ state = State.LOOKING; } } return state; } } The error: Spoiler [ERROR] Exception has occurred while running! Please report error to developer if problem persists: java.lang.NullPointerException: Cannot invoke "Main$State.ordinal()" because the return value of "Main.getState()" is null at Main.onLoop(Main.java:33) at org.dreambot.api.script.AbstractScript.run(AbstractScript.java) at java.base/java.lang.Thread.run(Thread.java:832) Pretty sure the return value of getState() is not null. Any help will be much appreciated! Link to comment Share on other sites More sharing options...
TheCloakdOne 389 Share Posted November 12, 2020 the bottom line `return state` returns null as its never set within your `getState` loop. either give it a default value at the top of your function or ensure your states are complete to the point where it would never return a null state. Currently if the local player is outside of the heal area and the combat area it will fail Link to comment Share on other sites More sharing options...
JAG98 4 Author Share Posted November 12, 2020 3 hours ago, TheCloakdOne said: the bottom line `return state` returns null as its never set within your `getState` loop. either give it a default value at the top of your function or ensure your states are complete to the point where it would never return a null state. Currently if the local player is outside of the heal area and the combat area it will fail Thanks! that helped! can't believe i overlooked that! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.