Jump to content

Returning wrong state for no reason?


IHB

Recommended Posts

Whenever I run this script on a low-end pc instead of my main one if I switch bot tabs it always ends up returning the state OUT_OF_FOOD straight away, even when the conditions aren't true? It also happens when the bot first logs in, it immediately returns OUT_OF FOOD and I can't figure out why. On my main pc it works properly but it's just on this other pc with lower specs

 

This is where my script grabs it's state: 

public State GetState() {
    	if (!players.inventory.contains(FOOD) && AREA.contains(myPlayer())) {
    		return State.WALK;
    	}
    	if (!players.inventory.contains(FOOD)&& COMBAT_AREA.contains(myPlayer())) {
    		return State.OUT_OF_FOOD;
    	}
    	if (myPlayer().isUnderAttack()) {
    		return State.IN_COMBAT;
    	}
    	if (!myPlayer().isUnderAttack() && COMBAT_AREA.contains(myPlayer())){
        	return State.ATTACKING;
        }
    	else
    		return State.ATTACKING;
    }

For eg: inventory contains food and its in combatarea but still returns it? As soon as i stop the script and start it again it returns the correct state which is attacking

Edited by IHB
Link to comment
Share on other sites

Remove players. from players.inventory as the inventory field is inherited in your class that extends Script, that would be first step. Try posting more code as I don't think that's the only issue in there.

 

 

 

whats "players"?

 

try using 

getInventory().contains(FOOD)

 

 

As the two said above I don't see anything wrong other then what is stated above.

 

Thanks for the replies I'll try removing the players. from it, it was auto-generated before so I just used it   It works on my normal pc but on the login on a bad pc it returns the wrong state right away (but after that it's fine)

 

Edit: Nope still having the same issue :( if I start the script already logged in it is fine it's just when it auto-logs in for me?

Edited by IHB
Link to comment
Share on other sites

Instead of 

public State GetState() {
    	if (!players.inventory.contains(FOOD) && AREA.contains(myPlayer())) {
    		return State.WALK;
    	}
    	if (!players.inventory.contains(FOOD)&& COMBAT_AREA.contains(myPlayer())) {
    		return State.OUT_OF_FOOD;
    	}
    	if (myPlayer().isUnderAttack()) {
    		return State.IN_COMBAT;
    	}
    	if (!myPlayer().isUnderAttack() && COMBAT_AREA.contains(myPlayer())){
        	return State.ATTACKING;
        }
    	else
    		return State.ATTACKING;
    }

try swapping the if() statements for attacking and out of food like this

public State GetState() {
    	if (!players.inventory.contains(FOOD) && AREA.contains(myPlayer())) {
    		return State.WALK;
    	}
         if (!myPlayer().isUnderAttack() && COMBAT_AREA.contains(myPlayer())){
        	return State.ATTACKING;
        }
    	if (!players.inventory.contains(FOOD) && COMBAT_AREA.contains(myPlayer())) {
    		return State.OUT_OF_FOOD;
    	}
    	if (myPlayer().isUnderAttack()) {
    		return State.IN_COMBAT;
    	}
    	
    }

It might help temporarily solve the issue, but the problem could be somewhere else in your script that leads to this issue

Link to comment
Share on other sites

Instead of 

public State GetState() {
    	if (!players.inventory.contains(FOOD) && AREA.contains(myPlayer())) {
    		return State.WALK;
    	}
    	if (!players.inventory.contains(FOOD)&& COMBAT_AREA.contains(myPlayer())) {
    		return State.OUT_OF_FOOD;
    	}
    	if (myPlayer().isUnderAttack()) {
    		return State.IN_COMBAT;
    	}
    	if (!myPlayer().isUnderAttack() && COMBAT_AREA.contains(myPlayer())){
        	return State.ATTACKING;
        }
    	else
    		return State.ATTACKING;
    }

try swapping the if() statements for attacking and out of food like this

public State GetState() {
    	if (!players.inventory.contains(FOOD) && AREA.contains(myPlayer())) {
    		return State.WALK;
    	}
         if (!myPlayer().isUnderAttack() && COMBAT_AREA.contains(myPlayer())){
        	return State.ATTACKING;
        }
    	if (!players.inventory.contains(FOOD) && COMBAT_AREA.contains(myPlayer())) {
    		return State.OUT_OF_FOOD;
    	}
    	if (myPlayer().isUnderAttack()) {
    		return State.IN_COMBAT;
    	}
    	
    }

It might help temporarily solve the issue, but the problem could be somewhere else in your script that leads to this issue

 

Thanks for the reply but the logic in that would be flawed as it would return ATTACKING before OUT_OF_FOOD in the case that it was actually out of food, meaning it would never bank :/  and where else do you think it could be going wrong?

Link to comment
Share on other sites

Your logic is flawed. You should have more/better conditions. 

 

Sorry if I upset you, my logic works fine for 12 hours straight IF I start the script already logged in, however if it does an auto-login it returns the outoffood state straight away and banks, after that it is fine though. I'm just trying to work out why it thinks that those conditions are true in the first getState when it logs in?

Link to comment
Share on other sites

I'm just trying to work out why it thinks that those conditions are true in the first getState when it logs in?

 

Because your logic is flawed.

 

Trust me, you will never make me upset.

 

 

EDIT: Why do you even have an OUT_OF_FOOD state? What purpose does it have?

 

Just do: if out of food -> go to bank to retrieve food (return state.WALK)

Edited by Woody
Link to comment
Share on other sites

Because your logic is flawed.

 

Trust me, you will never make me upset.

 

 

EDIT: Why do you even have an OUT_OF_FOOD state? What purpose does it have?

 

Just do: if out of food -> go to bank to retrieve food (return state.WALK)

 

That's what the state is for, banking

case OUT_OF_FOOD:
    	log("State: OUT_OF_FOOD");
    	CURRENT = "OUT OF FOOD";
    	Banking();
    	break;
Edited by IHB
Link to comment
Share on other sites

Sorry if I upset you, my logic works fine for 12 hours straight IF I start the script already logged in, however if it does an auto-login it returns the outoffood state straight away and banks, after that it is fine though. I'm just trying to work out why it thinks that those conditions are true in the first getState when it logs in?

Lmfao its because when u run script when not logged in it wont be able to retrieve your inventory probably until fully logged in. Try adding a boolean to the out of food portion that states that the account is fully logged in as well

  • Like 1
Link to comment
Share on other sites

 

That's what the state is for, banking

case OUT_OF_FOOD:
    	log("State: OUT_OF_FOOD");
    	CURRENT = "OUT OF FOOD";
    	Banking();
    	break;

Ugh.. Your conditions and naming your states are so flawed.

 

If you want help, post your code and perhaps we can help you with your problem.

 

Edit: try something like this

if got food
  if in combat area
    if not under attack
     return state.FIGHT
    else
     return state.WAIT
  else
    return state.WALK_TO_COMBAT_AREA
else
 if in bank area
  return state.BANK
 else
  return state.WALK_TO_BANK
Edited by Woody
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...