Jump to content

Script does nothing


EPLS

Recommended Posts

5 hours ago, liverare said:

Whoever keeps telling new scripters to use states - stop it.

You've made this new guy's script so fucking unreadable and overly complicated that I would be aghast if he can even get it to work.

States are horrible! Stop using them!

Here's what I can do without states; compare for yourself:


String status = "Ready"

Position cowTile = new Position(3259, 3269, 0);
NPC banker;
NPC cow;

@Override
public void onLoop() throws InterruptedException {
	if (shouldGoToBank()) {
		goToBank();
	} else if (shouldWithdrawFood()) {
		withdrawFood();
	} else if (shouldGoToCows()) {
		goToCows();
	} else if (shouldKillCows()) {
		killCows();
	}
}

private boolean shouldGoBank() {
	return inventory.isEmpty();
}

private void goToBank() {
	status = "Going to the bank";
	getWalking().webWalk(Banks.LUMBRIDGE_UPPER);
}

private boolean shouldWithdrawFood() {
	return Banks.LUMBRIDGE_UPPER.contains(myPosition());
}

private void withdrawFood() {
	status = "Withdrawing food";
	banker = npcs.closest("Banker");
	if (banker != null && banker.interact("Bank")) {
		// now sleep until the bank interface opens
		// hint: https://osbot.org/api/org/osbot/rs07/utility/ConditionalSleep.html
	}
}

private boolean shouldGoToCows() {
	return inventory.isFull();
}

private void goToCows() {
	status = "Going to the cows";
	getWalking().walk(cowTile);
}

private boolean shouldKillCows() {
	return inventory.contains("Salmon");
}

private void killCows() {
	status = "Killing cows";
	cow = npcs.closest("Cow"); // better filtering needed - you might attack a cow someone else is already attacking, or you might be fighting a cow and attempt to attack another cow in non-multi zone
	if (cow != null && cow.interact("Attack")) {
		// now sleep until you've killed the cow or are running low on health
		// hint: https://osbot.org/api/org/osbot/rs07/utility/ConditionalSleep.html
	}
}

 

 

Relax my dude, no need to be mad. People just made his script whatever it was intended to be, whether he used states or not. The point was to fix the code.

By the way 

private boolean shouldGoBank() {
	return inventory.isEmpty();
}

tl;dr

Why not just 

private boolean shouldBank = inventory.isEmpty();

 

Link to comment
Share on other sites

2 minutes ago, luminlumin said:

 

Relax my dude, no need to be mad. People just made his script whatever it was intended to be, whether he used states or not. The point was to fix the code.

By the way 


private boolean shouldGoBank() {
	return inventory.isEmpty();
}

tl;dr

Why not just 


private boolean shouldBank = inventory.isEmpty();

 

Because that is a variable. If you set a variable, it'll never be updated unless you set it again. That's why we have functions. :)

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...