xXx-=MistiKmaN's guide to Java basics=-xXx
Intro
Today I will be teaching you the very, very, very, very basics of Java Scripting. I am writing this because it will help you with RSBot and this also helps me to learn. When I am done learning omething, I write up a guide and it helps me. You will be learning about commonly known things called
Variables. There are 3 main kinds of variables, named:
Integer,
String and
Boolean. I will also be showing you how to use them. Variables are used in all forms of programming and once you have learnt these, everything else isn't so hard, so let's get started then, shall we? No? Oh ok then... Just kidding.

I will be using this in conjunction with RSBot as I assume that is what most people here would like to use it with, as do I.
Integers
If you're in year 10 (Australia) you may have heard about these in your maths class. Integers are just numbers. BUT. They are
whole numbers. Meaning they mustn't have decimal points or fractions etc. Yes, they can be negative. You would use an Integer for such things as, the amount of ore you've mined, skill levels, amount of items in your inventory and things such as that.

Onviously, as you would know from my other guides(In sig.) you have to declare things like this. To declare an Integer you would have to type in this;
CODE
int IntegerName = 69;
The code explained:
int This is the name of the variable you're using, in this case an Integer, which as you can plainly see is abbreviated to "int"
IntegerName I trust you are all smart enough to know that this is the name of the Integer, which is what you use to call upon it later in script designing.(Don't worry if you didn't understand that, it will be explain in another guide.) Another thing, which would be
very helpful, would be to say that it
IS case sensitive.
= This is just telling the computer that the integer is going to equal whatever follows the equal sign.
69; 69 Is what the Integer equals, and the semi-colan(;) is telling the computer to go to the next line of the script. Now how easy was that!?

Moving on.
Strings
You NEED these! In RSBot, you'll need these for things like Auto-Talkers, Auto-Logins and such. Strings can contain letters, numbers, even symbols! To setup a String one would input the following:
CODE
String StringName = "1MistiKmaN1";
If you followed the Integers quite easily you should get this quite simply, it's exactly the same, just with different words.
String This is declaring the type of Variable to be used. In this case, a String. :D
StringName Self explanatory, this is what you decide to name your String. Once again, you would use this to call upon it later in the script design. ;)
= Telling the computer, once again, that the String is going to equal(Be.) whatever follows.
"1MistiKmaN1"; And this would be the actual String. The String
MUST be contained within quotation marks(" ") and the semi-colon(;, in case you forgot what that is.) telling the computer it is the end of the line.
Moving on again.
Booleans
Booleans are
True or
False statements. They return whether you are in a random, your hitpoints are at a certain level, you are fighting the correct monster and things like that. declaring the Booleans is the same as other Variables:
CODE
boolean InRandom = false;
Eh, same as before...
boolean Type of Variable.
InRandom Name of the Boolean. Once again, this is what you'd use to call upon it.
= Boolean will equal what follows.
false; Saying that the Boolean is false and you are in fact(If the name is used correctly)
not in a random. Semi-Colon saying that it's the end of the line.
Using Variables
This part could take a little time to understand, but before you flood me with questions, read it a few times and read it in full.
CODE
int HpLevel = 50;
int NextHpLevel = HpLevel + 1;
Before I explain anything further, you must learn how to use Addition, Subtraction, Multiplication and Division in your script.
Addition symbol = +
Subtraction Symbol = -
Multiplication Symbol = *
Division Symbol = /
The Division Symbol must be a forward slash.
Now you know what the first line of the code above was, but let me explain the next line. Well, what I would assume you wouldn't know.
HpLevel + 1; The "HpLevel", you just called upon an Integer! It used your stored Integer and added 1 onto it to tell you what your next HitPoints level would equal! WooHoo!
Now for using Strings. -.-
CODE
String Username = "mistikman";
String Pass = "ummno";
String ScammerQuestion = "What's your password?";
String SnappyResponse = "My pass is " + Pass;
And you just did exactly the same as before but with Strings! :D
Now, using Booleans. Should be simple enough.

CODE
boolean attackMonster = true;
boolean weCanAttack = attackMonster;
boolean doSpecial = false;
Methods
Methods are what we make the computer do. :D That's a little less work for us. xD To use a method, you must first write it up, and then tell the computer when to use it. This is something we will be using a bit later:
CODE
int HP = getMyHitpoints();
Thankfully, SpelJohan has provided us with some "functions" that will gather values for us, which is what we did just now. By typing in
getMyHitpoints() it called upon a function that returns and stores your hitpoints into the integer entitled "HP".
Now on your way to writing up your first method:
CODE
public void HeyNoob();{
}
public Do not worry about this, you will not need it.
void This is where a Variable
should be. All method's must return a type of Variable, but if you put this in there, you're telling the computer you do not want a Variable returned.
HeyNoob();{ HeyNoob() is the name. Yes, you must have the parenthesis(()) there. ; Next line. And the bracket ({) is symbolising the start of the method.
} This bracket, as you should be able to figure out, is telling the computer to stop the method.

If you ran that, it would do nothing. Let's try adding the basic's basic code, eh?
CODE
log("Hey, what's up?")
log Is a function that tells the computer you want whatever's inside the brackets and quotation marks to be brought in the RSBot thingy down bottom.
("Hey, what's up?") This is called an argument, it will be put into the RSBot chat thingy, I can't remember what it's called, but yeah... What you want said must be within quotation marks.
Arguments in Methods
CODE
public void HeyName(String UserName){
log("Hello");
log("My username is " + UserName);
}
Now if you're down this far, you should be able to understand it. You should also know that this method will not do anything without this:
CODE
String UserName = "MistiKmaN";
HeyName(UserName);
If you added that it would come out like this:
"Hello
My username is MistiKmaN"
Aiight, now for "Returning" things.
CODE
public int getMyHP(){
return (How to get HP here);
}
As you can see, instead of void, it now contains int. This is because you want the value to be returned as an Integer.

The returned value would be stored in the Variable "getMyHP()". return is the function to be used to get the HP and whatevers in the brackets, is the method used to actually get your HP. Understand? Good.
Now you must use this. :D Use this code instead, in order to use it:
CODE
public int getMyHP(){
return (How to get HP here);
int myHp = getMyHP();
log("Hp level is " + myHp)
}
And here's the explanation:
int myHp = getMyHP(); This is like telling the computer, "Hey, I want the Integer "myHP" to equal whatever the function "getMyHP()" returned.
log("Hp level is " + myHp) Now you're telling the computer to write into the RSBot box thingy down bottom, "Hp level is 50" See? How easy was all that.
Outro
Now how easy was all that? If you didn't get it, go and clear your heads of any thought and then come back and read again until you do understand it.

And if you did understand it, congratulations, read it again tommorrow, just to make sure you got it right! Now, I'm working on a part 2 of this guide, so look forward to it! Another great guide by MistiKmaN! Ciao.