Since most of the teaching tuts here area really just about how to start a server, or fill in the blank, I am posting this to hopefully help noobs use their own mind to help them code.
I am not going to be directly teaching you anything other then the basics of INTs and how they can help you.
Ok, So what is a Int you ask?
Int = Integer
A Int is just one of the many Java Methods that you can use to declare what you want.
Others include booleans, voids, strings, arrays etc.
What makes a int special though, is that it uses number rather then "words values".
A int can hold any number up to like 256000000 or something like that I don't know the exact number.
Ints are a great way to set up a better, easier and more extensive "true or false" statement.
For examples sake I will point you to my barrows tutorial. I needed to find a way to make it so that when you opened the chest, the brother would only jump out at you once. This is probably where I first started to really invest in ints. Realizing there potential after this.
Lets say you want to make it so when you click on a box it first says, "hello". Then the second time it says, "Boo"! Then the third time you click on it it will say "Pilldom rules"!
So the first step like any method is to declare it initially. This is all you have to do.
In your client.java declare this
Code:
public int exampleText = 0;
Easy. You might be asking how you make it say the different text with numbers? Its quiet simple when you get used to it really. If you where going to use my box idea then you would head over to your object click one and add....
Code:
case ####://the box ID
if(exampleText == 0) {
sendMessage("hello");
exampleText = 1;
} else if(exampleText == 1) {
sendMessage("boo!");
exampleText = 2;
} else if(exampleText == 2) {
sendMessage("Pilldom Rules!");
}
break;
Ok, now what exactly is this doing? Well that first bit of code we added the
Code:
public int exampleText = 0;
What that is doing is saying by default, the int exampleText's value is 0. Dosnt mean anything it just equals 0.
So when we added are second bit this is what it is doing
Code:
Line 1: if(exampleText == 0) {
Line 2: sendMessage("hello");
Line 3: exampleText = 1;
The first line is saying ok, if the int example text is 0, then initate lines 2 and 3. If its not equal to 0, then move on to the next if statement.
Line 2 is simply saying ok send the message hello.
Line 3 is the key part to this being effective. What line 3 does is say,"ok, public int exampleText is no longer equal to 0, it now equals 1". So when the next line after it comes
Code:
} else if(exampleText == 1) {
the int now equals 1 so it will do what is under if(exampleText == 1).
credits: pilldom/me