Jump to content

How and when to use CASE?


shaba123

Recommended Posts

I have this snippet iv just taken from snippet section, could your or someone break it down for me and tell me what it does? id really appreciate it, and thanks for the reply btw :)

	private void hoverskill() throws InterruptedException {
		if (tabs.getOpen() != Tab.SKILLS) {
			tabs.open(Tab.SKILLS);
		}
		switch (attmethod) {
		case ATTACK:
			getWidgets().get(320, 1).hover();
			break;

		case STRENGTH:
			getWidgets().get(320, 2).hover();
			break;

		case DEFENCE:
			getWidgets().get(320, 3).hover();
			break;
		}
		sleep(random(4000, 7000));
	}

	private Skill getAttMethod() {
		switch (getConfigs().get(43)) {
		case 0:
			attmethod = Skill.ATTACK;
			break;
		case 1:
			attmethod = Skill.STRENGTH;
			break;
		case 3:
			attmethod = Skill.DEFENCE;
			break;
		}
		return attmethod;
	}

 

Link to comment
Share on other sites

private void hoverskill() throws InterruptedException {
		if (tabs.getOpen() != Tab.SKILLS) {
			tabs.open(Tab.SKILLS);
		}
		switch (attmethod) { //1
		case ATTACK: //2
			getWidgets().get(320, 1).hover();
			break;

		case STRENGTH://2
			getWidgets().get(320, 2).hover(); 
			break;

		case DEFENCE://2
			getWidgets().get(320, 3).hover(); 
			break;
		}
		sleep(random(4000, 7000));
	}

	private Skill getAttMethod() {
		switch (getConfigs().get(43)) { //3
		case 0:
			attmethod = Skill.ATTACK; //4
			break;
		case 1:
			attmethod = Skill.STRENGTH; //4
			break;
		case 3:
			attmethod = Skill.DEFENCE; //4
			break;
		}
		return attmethod;
	}

I marked some numbers in the code snippit you posted so I can individually address what they mean.

1. the attmethod variable is an enum. An enum is a variable that can only be equal a few specific values, in this example the enum can only be the specific values of any osrs skill such as ATTACK, STRENGTH, DEFENCE....., FARMING (this snippit uses an enum present in the osbot API you can see them listed under Enum Constants section here: https://osbot.org/api/org/osbot/rs07/api/ui/Skill.html). 

2. The attmethod variable is used in a switch statement. You will notice that following this line are multiple occurances of the CASE keyword. Whatever value after the case keyword matches with attmethod is the case statement that gets executed. This is similar to:

if(attmethid == Skill.Attack){
	gitWidgets.get.....;
	break;
}

There is a caveat to switch statements, as soon as one case matches, every subsequent case block regardless of whether the case matches or not is also executed. 

To prevent this from happening add the break keyword into every case block.

In your snippit, getWidgets().get(320, 1).hover(); means to hover over attack simulating a check of current experience. this is "antiban" that is not effective whatsoever. You are not fooling Jagex's anticheat with "human-like behavior" because this action is done client-side, no data of this interaction is sent to Jagex's servers. 

 

3. getConfigs(43) means to check bit strings (varbits) associated with the current attack player attack style. Obtaining varbits for congif 43 will return  either 0,1,2,or 3.

0 correlates with the upper left option selected in the combat (usually associated with attack),

1 with upper right (usually strength),

2 with lower left (usually controlled),

and 3 with lower right (usually defensive)

 

4. This second set of switch and case labels refers to setting up attmethod stay current with the attack method selected by the player. So that the hoverSkill method can correctly (and uselessly) hover over the correct skill being trained. This may also be used to paint the correct statistics of the skill being trained onto the game window. 

 

More detail on switch statments can be found here: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

Edited by PayPalMeRSGP
  • Like 1
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...