Jack Shep Posted November 20, 2018 Share Posted November 20, 2018 (edited) I know this seems like a rookie problem but I can't find the issue. Here's my paint. @Override public void onPaint(Graphics2D g) { DecimalFormat df = new DecimalFormat("#"); timeRan = System.currentTimeMillis() - this.timeBegan; currentXp = skills.getExperience(Skill.FLETCHING); if (currentXp > logXp) { itemsMade += 15; logXp = currentXp; } if (guiOptionChose == "Arrow shafts") { int temp = Integer.parseInt(logPrice); int temp2 = Integer.parseInt(arrowShaftPrice); int temp3 = Integer.parseInt(headlessArrowPrice); int temp4 = Integer.parseInt(featherPrice); xpGained = currentXp - beginningXp; gpGained = (itemsMade * temp2) - (temp * itemsMade); totalGpGained = gpGained / 1000; gpPerHour = (int)(gpGained / ((System.currentTimeMillis() - timeBegan) / 3600000.0D)); totalGpPerHour = gpPerHour / 1000; } if (guiOptionChose == "Headless arrows") { int temp = Integer.parseInt(logPrice); int temp2 = Integer.parseInt(arrowShaftPrice); int temp3 = Integer.parseInt(headlessArrowPrice); int temp4 = Integer.parseInt(featherPrice); int temp5 = temp2 + temp4; xpGained = currentXp - beginningXp; gpGained = (itemsMade * temp3) - (temp5 * itemsMade); totalGpGained = gpGained / 1000; gpPerHour = (int)(gpGained / ((System.currentTimeMillis() - timeBegan) / 3600000.0D)); totalGpPerHour = gpPerHour / 1000; } g.setColor(Color.WHITE); g.drawString("Run Time: " + ft(timeRan), 5, 260); g.drawString("Xp Gained: " + xpGained, 5, 280); g.drawString("Gp Gained: " + df.format(totalGpGained) + " k", 5, 300); g.drawString("Gp Per Hour: " + df.format(totalGpPerHour) + " k/hr", 5, 320); } Edited November 20, 2018 by Jack Shep Quote Link to comment Share on other sites More sharing options...
Juggles Posted November 20, 2018 Share Posted November 20, 2018 use gui.equals(""); not == Quote Link to comment Share on other sites More sharing options...
Jack Shep Posted November 20, 2018 Author Share Posted November 20, 2018 18 hours ago, Juggles said: use gui.equals(""); not == Didn't work Quote Link to comment Share on other sites More sharing options...
Juggles Posted November 20, 2018 Share Posted November 20, 2018 Does your GUI work and is typed exactly like it? Quote Link to comment Share on other sites More sharing options...
Jack Shep Posted November 20, 2018 Author Share Posted November 20, 2018 22 minutes ago, Juggles said: Does your GUI work and is typed exactly like it? Yeah, my GUI works fine and is written the same way. I also use the same two if statements in my onLoop() and it works fine. Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted November 21, 2018 Share Posted November 21, 2018 Print the value of guiOptionChose and make sure it's being set correctly. Quote Link to comment Share on other sites More sharing options...
Jack Shep Posted November 21, 2018 Author Share Posted November 21, 2018 57 minutes ago, HeyImJamie said: Print the value of guiOptionChose and make sure it's being set correctly. The value of guiOptionChose is being set correctly, I have a set of if statements identical to the pair in my paint in my onLoop() and they work fine. Quote Link to comment Share on other sites More sharing options...
liverare Posted November 21, 2018 Share Posted November 21, 2018 if (guiOptionChose == "Headless arrows") { Change to if (true) { If it's still not rendering, then it's a different issue. Quote Link to comment Share on other sites More sharing options...
Jack Shep Posted November 21, 2018 Author Share Posted November 21, 2018 4 hours ago, liverare said: if (guiOptionChose == "Headless arrows") { Change to if (true) { If it's still not rendering, then it's a different issue. Yeah, that didn't work either. I still have no clue what the issue is Quote Link to comment Share on other sites More sharing options...
liverare Posted November 21, 2018 Share Posted November 21, 2018 (edited) I just noticed you're parsing a lot of strings to integers, so I suspect that's throwing an NumberFormatException error which is preventing the paint from being rendered. I would avoid parsing anything on the paint method, as the rendering is called a stupid amount of times per second and so you're re-parsing again and again. It's both inefficient and likely causing problems. You should perhaps paint the raw string values and see whether they display as numbers, null, or empty. You can actually test this by going back to my earlier comment and making it "if (false)" instead, that way you're not parsing anything and are instead going straight to the drawing code. Edited November 21, 2018 by liverare Quote Link to comment Share on other sites More sharing options...
Jack Shep Posted November 21, 2018 Author Share Posted November 21, 2018 44 minutes ago, liverare said: I just noticed you're parsing a lot of strings to integers, so I suspect that's throwing an NumberFormatException error which is preventing the paint from being rendered. I would avoid parsing anything on the paint method, as the rendering is called a stupid amount of times per second and so you're re-parsing again and again. It's both inefficient and likely causing problems. You should perhaps paint the raw string values and see whether they display as numbers, null, or empty. You can actually test this by going back to my earlier comment and making it "if (false)" instead, that way you're not parsing anything and are instead going straight to the drawing code. The only issue with leaving the variables as 'string' is that I don't actually print those values. I use them in my formulas to calculate the values of the variables that I do actually print. So I need those variables as 'int's. However, what you're saying about re-parsing again and again makes sense. I only need to convert the variables from 'string' to 'int' once as they're just the OSBuddy prices of a few items. So I'll try parsing my strings to integers in my onStart() method and see if that fixes the issue. Quote Link to comment Share on other sites More sharing options...
Jack Shep Posted November 21, 2018 Author Share Posted November 21, 2018 1 hour ago, liverare said: I just noticed you're parsing a lot of strings to integers, so I suspect that's throwing an NumberFormatException error which is preventing the paint from being rendered. I would avoid parsing anything on the paint method, as the rendering is called a stupid amount of times per second and so you're re-parsing again and again. It's both inefficient and likely causing problems. You should perhaps paint the raw string values and see whether they display as numbers, null, or empty. You can actually test this by going back to my earlier comment and making it "if (false)" instead, that way you're not parsing anything and are instead going straight to the drawing code. What I tried worked, my paint finally prints now, thank you for the help. But of course this generated another issue, now the script stops moments after I start it, although it sounds like an unrelated issue, the script worked 100% (besides for the paint) before I made the change. I tried parsing the strings in my onLoop() instead which fixed the new issues but again the constant re-parsing caused some issues. (So much lag that the script wouldn't run). Any Ideas? Quote Link to comment Share on other sites More sharing options...
liverare Posted November 22, 2018 Share Posted November 22, 2018 int something; @Override public int onLoop() throws InterruptedException { try { something = Integer.parseInt("12345"); } catch (NumberFormatException e) { logger.error(e); } return 200; } @Override public void onPaint(Graphics2D g) { g.drawString(25, 25, "Something: " + something); } Quote Link to comment Share on other sites More sharing options...
Jack Shep Posted November 23, 2018 Author Share Posted November 23, 2018 On 11/22/2018 at 3:20 AM, liverare said: int something; @Override public int onLoop() throws InterruptedException { try { something = Integer.parseInt("12345"); } catch (NumberFormatException e) { logger.error(e); } return 200; } @Override public void onPaint(Graphics2D g) { g.drawString(25, 25, "Something: " + something); } It works! Thank you so much for your help Quote Link to comment Share on other sites More sharing options...