PDA

View Full Version : Ehh this isn't looping



rj
07-02-2013, 01:59 PM
Why isn't this script looping? :s infact it does nothing at all

package miner;
import org.parabot.core.ui.components.LogArea;
import org.parabot.environment.api.utils.Time;
import org.parabot.environment.scripts.Category;
import org.parabot.environment.scripts.Script;
import org.parabot.environment.scripts.ScriptManifest;
import org.rev317.api.methods.Bank;
import org.rev317.api.methods.Camera;
import org.rev317.api.methods.Inventory;
import org.rev317.api.methods.Players;
import org.rev317.api.methods.SceneObjects;
import org.rev317.api.methods.Skill;
import org.rev317.api.methods.Walking;
import org.rev317.api.wrappers.scene.Area;
import org.rev317.api.wrappers.scene.SceneObject;
import org.rev317.api.wrappers.scene.Tile;
import org.rev317.api.wrappers.walking.TilePath;


@ScriptManifest(author = "RJJ95", category = Category.MINING, description = "Run this at ::skills", name = "Any Rock Miner", servers = { "CrisisX" }, version = 0.1)
public final class crisisMiner extends Script {
public static Area mine = new Area (new Tile(3008, 3370, 0) , new Tile(3018, 3367, 0));
public static Area bank = new Area (new Tile(3027, 3383, 0) , new Tile(3031, 3375, 0));
private final Tile[] to_Bank = { new Tile(3094,3496,0), new Tile(3013,3369,0) };
private final Tile[] to_Mine = { new Tile(3017,3372,0), new Tile(3023,3376,0), new Tile(3028, 3379, 0) };

static int BANK = 2213;
@Override
public boolean onExecute() {
LogArea.log("");
LogArea.log("Script Started");
while (true) {
loop();
return true;
}
}
@Override
public void onFinish() {
LogArea.log("Script ended");

}
public int loop() {
LogArea.log("Looping");
if(Inventory.isFull()) {
if (atMine()) {
walkBank();
} else if (atBank()) {
openBank();
handleBank();
} else {
LogArea.log("Not at mine or bank");
walkMine();
}
} else if(!Inventory.isFull()) {
if (atMine()) {
mineRock();
} else if (atBank()) {
walkMine();
} else {

}
}
return 5;
}
public void mineRock() {
LogArea.log("Mining rock");

int lvl = Skill.MINING.getLevel();
int rockID = 2091;
if (lvl < 15) {
rockID = 2091;
}
if ((lvl >= 15) && (lvl < 30)) {
rockID = 2093;
}
if ((lvl >=30) && (lvl < 50)) {
rockID = 2097;
}
if ((lvl >=50) && (lvl < 55)) {
rockID = 14850;
}
if ((lvl >=55) && (lvl < 70)) {
rockID = 2103;
}
if (lvl >= 70) {
rockID = 2105;

} else {
rockID = 2091;
}
final SceneObject Rocks[] = SceneObjects.getNearest(rockID);
final SceneObject Rock = Rocks[0];
if (Rock != null) {
if(!Rock.isOnScreen()){
Camera.turnTo(Rock);
Time.sleep(100);
}
Rock.interact("Mine");
Time.sleep(3000);
while (Players.getLocal().getAnimation() == 626) {
Time.sleep(200);
}
}
}
public void walkBank() {
TilePath path = new TilePath(to_Bank);
if(!path.hasReached() && Walking.readyForNextTile()) {
path.traverse();
}
}
public void walkMine() {
TilePath path = new TilePath(to_Mine);
if(!path.hasReached() && Walking.readyForNextTile()) {
path.traverse();
}
}
public void openBank() {
final SceneObject Banks[] = SceneObjects.getNearest(2213);
final SceneObject Bank = Banks[0];
if (Bank != null) {
if(!Bank.isOnScreen()){
Camera.turnTo(Bank);
Time.sleep(100);
}
Bank.interact("Use");
Time.sleep(3000);
while (Players.getLocal().isWalking()) {
Time.sleep(200);
}
}
}
public void handleBank() {
if (atBank()) {
Bank.depositAllExcept(1267,1275);
} else if (!atBank()) {
walkBank();
}
}
public boolean atMine() {
if (mine.contains(Players.getLocal().getLocation())) {
return true;
} else {
return false;
}
}
public boolean atBank() {
if (bank.contains(Players.getLocal().getLocation())) {
return true;
} else {
return false;
}
}
}


The debug says:
Script started
looping
script ended.

I don't get how it's not looping though

riwu
07-02-2013, 02:18 PM
while (true) {
loop();
return true;
}
return is called within the loop (enclosed by {}), which passes the result to the caller and exits the method immediately (hence breaking the loop)

rj
07-02-2013, 02:21 PM
while (true) {
loop();
return true;
}
return is called within the loop (enclosed by {}), which passes the result to the caller and exits the method immediately (hence breaking the loop)
Ahh ok, and if I put the return below then it's unreachable, and if I put it above it breaks the loop,

Should I just create a thread for the loop? How do I do that it says it needs to be a super type or something

Kasi
07-02-2013, 02:25 PM
never coded in parabot. but why do you need it to be a boolean anyways just make it a void and remove the return.

rj
07-02-2013, 02:27 PM
never coded in parabot. but why do you need it to be a boolean anyways just make it a void and remove the return.

Because I am forced to because that's how their api is -.- I can't run locals on powerbot so I'm feeding my needs by using a RSPS bot.. I don't even play the servers lol

Their api doesn't have "loop" loop the script by default like on powerbot were it's just:


@Override
public int loop() {

Kasi
07-02-2013, 02:29 PM
Because I am forced to because that's how their api is -.- I can't run locals on powerbot so I'm feeding my needs by using a RSPS bot.. I don't even play the servers lol

Their api doesn't have "loop" loop the script by default like on powerbot were it's just:


@Override
public int loop() {

ah okay, make your own variable called Running or something and set it true. then do while (Running){}
then put the return under your loop. make sure Running is global.

rj
07-02-2013, 02:33 PM
ah okay, make your own variable called Running or something and set it true. then do while (Running){}
then put the return under your loop. make sure Running is global.
Woot now it's looping, but doing nothing I think I created the areas wrong somehow.. anyway now I can't stop the script

EDIT:

http://img849.imageshack.us/img849/8983/kc0p.png

I start from the top left and bottom right to get area coords correct lol? Because it thinks i'm not inside of that area

public boolean atMine() {
if (mine.contains(Players.getLocal().getLocation())) {
return true;
} else {
return false;
}
}