creationx Posted February 4, 2016 Share Posted February 4, 2016 Hello everyone! I am currently having issues using values that were determined in a previous case. So what's happening is I have two cases, Case A and Case B. In Case A I've declared the following long BuyPriceNew = grandExchange.getAmountSpent(Box.BOX_1); Which Logs the amount spent in the GE box into the Long "BuyPriceNew" However when I go into Case B and try to call upon BuyPriceNew I get the following error. The local variable BuyPriceNew may not have been initialized. Note that a problem regarding missing 'default:' on 'switch' has been suppressed, which is perhaps related to this problem main.java /XMerch/src line 136 Java Problem What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
Token Posted February 4, 2016 Share Posted February 4, 2016 You have to initialise your variable before the switch statement with an actual value. long buyPriceNew = 0; switch (...) { case A: buyPriceNew = grandExchange.getAmountSpent(Box.BOX_1); return; case B: ... // the variable is initialised here so you can use it } Use null as a default value for all types except for numerical ones. 1 Quote Link to comment Share on other sites More sharing options...
creationx Posted February 4, 2016 Author Share Posted February 4, 2016 Thanks man! A second question...I want my script to perform a profit check function first and then move on to repeating the merch function until a certain time. My issue is that I cannot even get it to move from the ProfitCheck Case to the Merch Case Here is my Code NPC clerk = npcs.closest("Grand Exchange Clerk"); if (clerk !=null && grandExchange.isOpen() == false) return State.ExchangeBanker; int OpenedIt = 1; int CheckedIt = 0; if (OpenedIt <= 2 && CheckedIt == 0) return State.ProfitCheck; OpenedIt += 1; CheckedIt += 1; if(CheckedIt >= 0) return State.MerchTime; return State.Wait; } Here you see that I'm simply trying to get the script to recognize that if the previous case was completed it can move onto the next case, but for some reason it keeps hanging on the profit check case. Quote Link to comment Share on other sites More sharing options...
zScripz Posted February 4, 2016 Share Posted February 4, 2016 Thanks man! A second question...I want my script to perform a profit check function first and then move on to repeating the merch function until a certain time. My issue is that I cannot even get it to move from the ProfitCheck Case to the Merch Case Here is my Code NPC clerk = npcs.closest("Grand Exchange Clerk"); if (clerk !=null && grandExchange.isOpen() == false) return State.ExchangeBanker; int OpenedIt = 1; int CheckedIt = 0; if (OpenedIt <= 2 && CheckedIt == 0) return State.ProfitCheck; OpenedIt += 1; CheckedIt += 1; if(CheckedIt >= 0) return State.MerchTime; return State.Wait; } Here you see that I'm simply trying to get the script to recognize that if the previous case was completed it can move onto the next case, but for some reason it keeps hanging on the profit check case. The code where you increment OpenedIt and CheckedIt is unreachable also camelCase pls also you probably want to learn Java before writing a massive merch script Quote Link to comment Share on other sites More sharing options...
Explv Posted February 4, 2016 Share Posted February 4, 2016 Thanks man! A second question...I want my script to perform a profit check function first and then move on to repeating the merch function until a certain time. My issue is that I cannot even get it to move from the ProfitCheck Case to the Merch Case Here is my Code NPC clerk = npcs.closest("Grand Exchange Clerk"); if (clerk !=null && grandExchange.isOpen() == false) return State.ExchangeBanker; int OpenedIt = 1; int CheckedIt = 0; if (OpenedIt <= 2 && CheckedIt == 0) return State.ProfitCheck; OpenedIt += 1; CheckedIt += 1; if(CheckedIt >= 0) return State.MerchTime; return State.Wait; } Here you see that I'm simply trying to get the script to recognize that if the previous case was completed it can move onto the next case, but for some reason it keeps hanging on the profit check case. No code after a return statement will be executed. 1 Quote Link to comment Share on other sites More sharing options...
creationx Posted February 4, 2016 Author Share Posted February 4, 2016 Awesome!Thanks for the help guys. I have problems learning java by just reading "How to Java", I do a lot better learning it when I actually type it and do trial and error. Quote Link to comment Share on other sites More sharing options...