Thread: ints/how you can use them

Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1 ints/how you can use them 
    xxdeadxx
    Guest
    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
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Jul 2008
    Posts
    939
    Thanks given
    0
    Thanks received
    3
    Rep Power
    781
    Horribly put, xxdeadxx.

    Ints are a great way to set up a better, easier and more extensive "true or false" statement.
    Each primitive data type has it's own specific function.

    A Int is just one of the many Java Methods that you can use to declare what you want.
    An int isn't really a method, it's a type.

    What makes a int special though, is that it uses number rather then "words values".
    Couple other primitive data types use numbers however unlike int, some can hold decimal's and numbers greater then what an int can hold.

    What that is doing is saying by default, the int exampleText's value is 0. Dosnt mean anything it just equals 0.
    This deceleration's value is set at 0 upon initialization of the class file. 0, can actually mean something if you give it meaning, however in this case it doesn't.
    I'm Rog3r, fool.
    Reply With Quote  
     

  3. #3  
    Member

    Join Date
    Sep 2007
    Posts
    614
    Thanks given
    0
    Thanks received
    1
    Rep Power
    0
    # int: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use long instead.
    [Only registered and activated users can see links. ]

    Otherwise this is a good tutorial. Helpful, and there are some extra uses you should probably include.
    Reply With Quote  
     

  4. #4  
    xxdeadxx
    Guest
    ok thanks for the feedback
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Oct 2008
    Posts
    842
    Thanks given
    81
    Thanks received
    53
    Rep Power
    0
    This was a very helpful post. Ive always wondered how to use ints for commands. Thanks for posting this rep++.

    Also thanks to you I created cooking. :-).
    Reply With Quote  
     

  6. #6  
    Registered Member
    Vox''s Avatar
    Join Date
    Nov 2008
    Age
    28
    Posts
    3,114
    Thanks given
    49
    Thanks received
    181
    Rep Power
    731
    do you even know who pilldom is..??

    Quote Originally Posted by Zirtrix View Post
    So I've recently changed some things in the server, but when i compile it says
    Code:
    source\server\model\players\packets\Commands.java: 58: error: cannot find symbol
    This.Antileech("Remove This Line");
    ^
    Anyone know the problem?
    Student and Developer for [Only registered and activated users can see links. ]
    Reply With Quote  
     

  7. #7  
    Registered Member
    AMG A Bear's Avatar
    Join Date
    Jun 2008
    Posts
    1,157
    Thanks given
    27
    Thanks received
    87
    Rep Power
    945
    Code:
    	case #:
    		if(exampleText == 0) 
    		{
    			sendMessage("hello");
    			exampleText = 1;
    		} 
    		else if(exampleText == 1) 
    		{
    			sendMessage("boo!");
    			exampleText = 2;
    		} 
    		else if(exampleText == 2)
    			sendMessage("Pilldom Rules!");
    	break;
    Much neater and a lot easier to read.
    Quote Originally Posted by The Night Life View Post
    Errm. I had a similar idea a very long time ago, about instead of current rs's gameframe, (622) making a rsps with about a 1645 or something. Make it look like you walked outside. I even gathered proffesional computer programmers to help, but bailed on the idea after i realized if we all worked on it non-stop for months at a time, we'd barely get any progress. (unless you wanted to half ass it)
    Reply With Quote  
     

  8. #8  
    Cascade1
    Guest
    Ints are a great way to set up a better, easier and more extensive "true or false" statement.
    How the hell is an Integer a better way to hold a true or false value when there is a type specifically for this? I find that amusing.

    Also;

    Code:
    Others include booleans, voids, strings, arrays etc.
    An array isn't a type, you have arrays of types if you understand that.

    Put right an Integer or Int holds an Integer value(a whole number) between -2147m - 2147m(From the top of my head).

    Sorry, useless tutorial.
    Reply With Quote  
     

  9. #9  
    Community Veteran

    Dexter Morgan's Avatar
    Join Date
    Nov 2008
    Age
    16
    Posts
    4,364
    Thanks given
    1,027
    Thanks received
    703
    Discord
    View profile
    Rep Power
    2991
    Teach me about the variable 'char'
    Reply With Quote  
     

  10. #10  
    brb ridin da storm

    blakeman8192's Avatar
    Join Date
    Dec 2012
    Age
    28
    Posts
    2,010
    Thanks given
    802
    Thanks received
    1,357
    Rep Power
    286
    There are a lot of things wrong with your tutorial, however, good effort - at least you tried.
    rest in peace Qemist, Izzy, TeChNo PuNk, Impulser, & bootnecklad
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •