mcleod63 2 Share Posted February 19, 2023 Hi, can anyone help me understand why my Paint is throwing errors? The error appears to be caused by Players.getLocal().getLevel() throwing errors until the login handler has finished. I say this because the logs show login handler starting, and then repetitive errors pointing to my codeline 143, and the errors stop as soon as the log shows that the login handler finished. I can show the log entries if that will help. This is line 143 in my code: g.drawString("Combat skill level: " + Players.getLocal().getLevel(), 10, 135); I recently returned to botting after taking a 1-2 year break, so I had to update my scripts for the deprecated items since I last played. That included changing getLocalPlayer().getLevel() to Players.getLocal().getLevel() but I don't see how that is the problem. Any help would be appreciated. Link to comment Share on other sites More sharing options...
pharaoh 130 Share Posted February 19, 2023 one solution could be null checking if youre logged in or if the local player is not null before painting the paint text and draw the text getlocalplayer to players.getlevel should not affect that in your onpaint method, something like this pseudocode if (!loggedin) { wait to load in } else { drawstring() drawstring() drawrect() } Link to comment Share on other sites More sharing options...
hashbang 8 Share Posted February 19, 2023 (edited) `Players.getLocal()` can return null, so you need to null check or catch the exception. int level = 0 Player me = Players.getLocal() if (me != null) { level = me.getLevel() } g.drawString("Combat skill level: " + level, 10, 135); OR try { g.drawString("Combat skill level: " + Players.getLocal().getLevel(), 10, 135); } catch (Exception e) { Logger.log("Unable to get player level: " + e.getMessage()) } Edited February 19, 2023 by hashbang Link to comment Share on other sites More sharing options...
mcleod63 2 Author Share Posted February 19, 2023 Oh no, I fell for the 'failed to do a null check"' thing. Thank you both for the responses. Must remember null checks. Must remember null checks. Must remember null checks. holic 1 Link to comment Share on other sites More sharing options...
mcleod63 2 Author Share Posted February 21, 2023 Just a quick update. This one solved my issue. Thanks again for the helpful responses! Player player = Players.getLocal(); if (player != null) { g.drawString("Combat Level: " + player.getLevel(), 10, 90); } pharaoh 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now