SRL Archive - Java Help and Tutorials

Using strategies vs normal loop


rj

2013-07-13 23:34:26

So in my learning of making injection scripts in java, I have encountered 2 ways to construct a script:

1) Using a main loop to do actions such as:

 public int loop() {
if(Inventory.isFull()) {
if (atMine()) {
walkBank();
state = ("Walking to bank");
} else if (atBank()) {
state = ("Banking");
openBank();
countGains();
handleBank();
} else {
if (Inventory.isFull()) {
walkBank();
} else {
walkMine();
}
}
} else if(!Inventory.isFull()) {
if (atMine()) {
mineRock();
state = ("Mining");
} else if (atBank()) {
state = ("Walking to mine");
walkMine();
} else {
if (Inventory.isFull()) {
walkBank();
} else {
walkMine();
}
}
}
return 5;
}

Or I could use strategies:

public class withdrawPotions implements Strategy {
@Override
public boolean activate() {
return !extremesReady() && Bank.isOpen();

}
@Override
public void execute() {
// stuff here if above conditions are met
}
}
public class closeBank implements Strategy {
@Override
public boolean activate() {
return extremesReady() && Bank.isOpen();
}
@Override
public void execute() {
// stuff here if above conditions are met
}
}
public class makePotions implements Strategy {
@Override
public boolean activate() {
return !Bank.isOpen() && extremesReady();
}
@Override
public void execute() {
// stuff here if above conditions are met
}
}
public class bankPotions implements Strategy {
@Override
public boolean activate() {
return !Bank.isOpen() && OverloadsExist() || !extremesReady();
}
@Override
public void execute() {
// stuff here if above conditions are met
}
}

anyway, I was wondering, which was in more memory efficient? All the overrides, is that taking up a lot more memory?

NKN

2013-07-13 23:48:28

From: Officer Barbrady
So in my learning of making injection scripts in java, I have encountered 2 ways to construct a script:

1) Using a main loop to do actions such as:

 public int loop() {
if(Inventory.isFull()) {
if (atMine()) {
walkBank();
state = ("Walking to bank");
} else if (atBank()) {
state = ("Banking");
openBank();
countGains();
handleBank();
} else {
if (Inventory.isFull()) {
walkBank();
} else {
walkMine();
}
}
} else if(!Inventory.isFull()) {
if (atMine()) {
mineRock();
state = ("Mining");
} else if (atBank()) {
state = ("Walking to mine");
walkMine();
} else {
if (Inventory.isFull()) {
walkBank();
} else {
walkMine();
}
}
}
return 5;
}

Or I could use strategies:

public class withdrawPotions implements Strategy {
@Override
public boolean activate() {
return !extremesReady() && Bank.isOpen();

}
@Override
public void execute() {
// stuff here if above conditions are met
}
}
public class closeBank implements Strategy {
@Override
public boolean activate() {
return extremesReady() && Bank.isOpen();
}
@Override
public void execute() {
// stuff here if above conditions are met
}
}
public class makePotions implements Strategy {
@Override
public boolean activate() {
return !Bank.isOpen() && extremesReady();
}
@Override
public void execute() {
// stuff here if above conditions are met
}
}
public class bankPotions implements Strategy {
@Override
public boolean activate() {
return !Bank.isOpen() && OverloadsExist() || !extremesReady();
}
@Override
public void execute() {
// stuff here if above conditions are met
}
}

anyway, I was wondering, which was in more memory efficient? All the overrides, is that taking up a lot more memory?


If this is for powerbot, you're behind.

They've moved to node/branch/tree system.


Learn the first one, as Powerbot is getting rid of all of that, it'll only be loop.
I might make a node system for the new API though, if you'd be interested in that.

rj

2013-07-13 23:53:55

From: NKN
If this is for powerbot, you're behind.

They've moved to node/branch/tree system.


Learn the first one, as Powerbot is getting rid of all of that, it'll only be loop.
I might make a node system for the new API though, if you'd be interested in that.

Plan on trying to run locals for powerbot again -.- why don't they just make it like the old fashion way were there was a compiled scripts folder?