- Joined
- Nov 6, 2015
- Messages
- 541
- Thread Author
- #1
Hi I am trying to create a TreeBot and I am now trying to count to max traps of 3 and I tried by using setters and getters but when the variable is loaded in another class it seems that it's 0 again for some reason.
If there is any other way that I can detect the amount of traps I've placed please explain it to me I know it's isn't effecient like it is now but I want to make the base first and then try to make it more effecient as this is my first script.
SetTraps is called before Collect Traps.
SetTraps:
CollectTraps:
Debug:
It had to be a static variable.
should've been: private static int trapsSet;
Rookie mistake can be closed
If there is any other way that I can detect the amount of traps I've placed please explain it to me I know it's isn't effecient like it is now but I want to make the base first and then try to make it more effecient as this is my first script.
SetTraps is called before Collect Traps.
SetTraps:
Code:
package com.remco1337.bots.ImpHunter;
import com.runemate.game.api.hybrid.Environment;
import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
import com.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;
import com.runemate.game.api.hybrid.region.Players;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.tree.LeafTask;
/**
* NOTES:
*
*/
public class SetTraps extends LeafTask {
private int trapsSet;
public int getCount() {
System.out.println("getCount called: " + trapsSet);
return trapsSet;
}
public void deleteTrap() {
trapsSet--;
System.out.println("deleteTrap called: " + trapsSet);
}
public void addTrap() {
trapsSet++;
System.out.println("addTrap called: " + trapsSet);
}
@Override
public void execute() {
SpriteItem magicBox = Inventory.getItems("Magic box").first();
if(trapsSet < 3) {
if(magicBox != null && magicBox.interact("Activate")) {
Execution.delay(3000, 4000);
Execution.delayUntil(() -> Players.getLocal().getAnimationId() == -1, 5500, 7000);
addTrap();
}
}
return;
}
}
CollectTraps:
Code:
package com.remco1337.bots.ImpHunter;
import com.runemate.game.api.hybrid.entities.GameObject;
import com.runemate.game.api.hybrid.entities.GroundItem;
import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
import com.runemate.game.api.hybrid.location.Coordinate;
import com.runemate.game.api.hybrid.location.navigation.Traversal;
import com.runemate.game.api.hybrid.location.navigation.web.WebPath;
import com.runemate.game.api.hybrid.region.GameObjects;
import com.runemate.game.api.hybrid.region.GroundItems;
import com.runemate.game.api.hybrid.region.Players;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.tree.LeafTask;
/**
* NOTES:
*
*/
public class CollectTraps extends LeafTask {
@Override
public void execute() {
SetTraps setTraps = new SetTraps();
System.out.println("COLLECTTRAPS: " + setTraps.getCount());
GameObject magicBox = GameObjects.newQuery().names("Magic box").actions("Retrieve").results().first();
GroundItem magicBoxDeactivated = GroundItems.newQuery().names("Magic box").actions("Take", "Activate").results().first();
GameObject magicBoxFailed = GameObjects.newQuery().names("Magic box failed").actions("Deactivate").results().first();
if (magicBox != null && magicBox.interact("Retrieve")) {
Coordinate destination = magicBox.getPosition();
Execution.delay(1000, 2000);
WebPath webPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(destination);
if(webPath != null){
webPath.step();
} else {
getLogger().warn("Could not generate webPath in Walk");
}
Execution.delay(3000, 4000);
setTraps.deleteTrap();
System.out.println("Trap collected : count | " + setTraps.getCount());
}
if (magicBoxDeactivated != null && magicBoxDeactivated.interact("Activate")) {
Coordinate destinationDeactivated = magicBoxDeactivated.getPosition();
Execution.delay(1000, 2000);
WebPath webPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(destinationDeactivated);
if(webPath != null){
webPath.step();
} else {
getLogger().warn("Could not generate webPath in Walk");
}
Execution.delay(3000, 4000);
setTraps.deleteTrap();
System.out.println("Trap collected : count | " + setTraps.getCount());
}
if (magicBoxFailed != null && magicBoxFailed.interact("Deactivate")) {
Coordinate destinationDeactivated = magicBoxFailed.getPosition();
Execution.delay(1000, 2000);
WebPath webPath = Traversal.getDefaultWeb().getPathBuilder().buildTo(destinationDeactivated);
if(webPath != null){
webPath.step();
} else {
getLogger().warn("Could not generate webPath in Walk");
}
Execution.delay(3000, 4000);
setTraps.deleteTrap();
System.out.println("Trap collected : count | " + setTraps.getCount());
}
}
}
Debug:
Code:
addTrap called: 1
addTrap called: 2
addTrap called: 3
getCount called: 0
COLLECTTRAPS: 0
It had to be a static variable.
should've been: private static int trapsSet;
Rookie mistake can be closed