Hey !
Good effort! As @TheWind said, the key is to have one and only one 'action' line execute in one onLoop iteration. The reason for this is that you are programming for a live game and as such issues such as latency fluctuations can result in interactions failing. If you're relying on an interaction to succeed for future lines of code, this can cause horrible errors! A classic example is banking. For example calling:
getBank().open();
getBank().withdraw("Example", 500);
Is a big error - ask yourself, what if the first line fails? The the script will try to withdraw stuff from the bank but it's not open - uh oh! Instead, you want to make it only do what it needs to based on the current situation:
if (getBank().isOpen()) {
if (getBank().contains("Example") && getBank().getAmount("Example") >= 500) {
getBank().withdraw("Example", 500);
//Conditional sleep here
} else {
log("Not enough Example in bank");
stop();
}
} else {
getBank().open();
}
-Apa