Jump to content

Search the Community

Showing results for tags 'introduction'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • RuneLocus
    • News & Announcements
    • Information Booth
    • Website Support
    • Introductions
    • Chat
    • Forum Games
  • RuneScape Development
    • RSPS General
    • RuneScape Private Server (RS2)
    • RuneScape Private Server (503+)
    • RuneScape Private Server (EoC 742+)
  • Other
    • Digital Art
    • Gaming
    • Webdevelopment
    • Computers
  • Marketplace
    • RuneScape Market
    • RSPS Market
    • Others Market
    • Freelance Middleman Services
  • Super Secret Club's Topics

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Found 16 results

  1. I am Warnen and I go by a code computerized only through the normal ones. NORMAL EXCLUSIONS NORMAL BLACKLISTS
  2. Hello everyone, you can refer to me as Quantum or Jirenultra, I have been on this site before years ago but never really got back into coding RSPS so I can't really remember what I used as a username at that point. I am a dedicated programmer/developer in C, C++, Java, Html, Css, and others in less detail. I have never owned a successful server but I did have my own projects that were completely finished and played on a solo/lan connection. I am back to help other developers and develop my self. I am also a big gamer so I do test servers, and since I'm online most of the time, don't hesitate to ask for help. I am not saying I am an expert but I will try to help ALL those who ask for help. I hope everyone had great holidays!! I am glad to be back.
  3. Unfortunately, I do feel the need to make rules for the section since I have noticed an increase in people using it simply to get post count for their advertisement thread. We like to discourage spamming for post count here, as the forums would be quite messy if we allowed it. 1. Introduce Yourself As is the whole purpose of this section, we want you to introduce yourself to us! Just tell us a little about yourself, how you found us, why you're here, etc. No need to go into detail; we don't need to know your street address! NOTE: Please be sure to make your introduction worthwhile. Stuff like, "Hi, I'm (insert username here) and I'm new!" is not acceptable. 2. Welcoming the Newbies We encourage you to welcome the new members! In fact, we want you to! However, if you are the new person, it makes no sense for you to be welcoming someone that has been on the forums longer than you. When you do this, it is obviously for post count and will result in your post being removed. 3. No Advertising This is a global rule, but I feel the need to repeat it here. No advertising of any sort is allowed in this section. Your thread or post will be removed and an infraction will be given.
  4. Hello, As I didn't see anything like this in the section, I decided to make this guide. This guide will be designated towards an audience of people wanting to learn PHP. I will explain the fundamentals of this language, and I hope it's thorough enough for easy understanding. So, sit back, get your reading glasses on, and get ready! I give you a warm welcoming to: An Introduction to PHP Contents: [iurl=#section1]1 - What is PHP?[/iurl] [iurl=#section11]1.1 - What will we be learning?[/iurl] [iurl=#section12]1.2 - What's an IDE?[/iurl] [iurl=#section13]1.3 - Selecting an IDE[/iurl] [iurl=#section14]1.4 - When and when-not to use an IDE[/iurl] [iurl=#section2]2 - Variables[/iurl] [iurl=#section21]2.1 - Integers[/iurl] [iurl=#section22]2.2 - Strings[/iurl] [iurl=#section23]2.3 - Arithmetic[/iurl] [iurl=#section24]2.4 - Echo & Print[/iurl] [iurl=#section25]2.5 - Putting it all together![/iurl] [iurl=#section3]3 - Comparisons[/iurl] [iurl=#section31]3.1 - Comparison expressions[/iurl] [iurl=#section32]3.2 - The if statement[/iurl] [iurl=#section33]3.3 - What else!?[/iurl] [iurl=#section34]3.4 - Combine![/iurl] [iurl=#section4]4 - Let's switch it up![/iurl] [iurl=#section41]4.1 - Testing the waters[/iurl] [iurl=#section42]4.2 - Rack 'em and stack 'em[/iurl] [iurl=#section43]4.3 - Alternative syntax[/iurl] [iurl=#section44]4.4 - Put it together![/iurl] [iurl=#section5]5 - Arrays[/iurl] [iurl=#section51]5.1 - How does it all work?[/iurl] [iurl=#section52]5.2 - To access an array[/iurl] [iurl=#section53]5.3 - Modify, delete, sort, and push your array[/iurl] [iurl=#section54]5.4 - The associative array[/iurl] [iurl=#section55]5.5 - Using it as a map[/iurl] [iurl=#section56]5.6 - Multiple dimensions![/iurl] [iurl=#section57]5.7 - Mash it all together![/iurl] [iurl=#section6]6 - The loop[/iurl] [iurl=#section61]6.1 - The for loop[/iurl] [iurl=#section62]6.2 - Looping an array causes something new[/iurl] [iurl=#section63]6.3 - While this... Maybe this?[/iurl] [iurl=#section64]6.4 - How do you do?[/iurl] [iurl=#section7]7 - Onto functions![/iurl] [iurl=#section71]7.1 - Time to put arrays in them![/iurl] [iurl=#section72]7.2 - Calling these functions[/iurl] [iurl=#section73]7.3 - Messing with parameters[/iurl] [iurl=#section74]7.4 - Apply it![/iurl] [iurl=#section8]8 - PHP is also OO![/iurl] [iurl=#section81]8.1 - Time for class[/iurl] [iurl=#section82]8.2 - Use of properties[/iurl] [iurl=#section83]8.3 - Throw a method in the matter[/iurl] [iurl=#section84]8.4 - The final chapter[/iurl] [iurl=#section9]9 - Hope you liked it![/iurl] [anchor=section1]1 - What is PHP?[/anchor] PHP is a recursive acronym for; 'Hypertext Preprocessor'. It is an immensely popular open-source scripting language. It's designed to be especially beneficial to web development and it is able to be embedded into HTML. It can be extremely useful in the case of where making a specific webpage you'd like, HTML does not have the capabilities to perform certain actions or processes. You can also use it to simplify your time, as opposed to writing hundreds of lines of HTML. What makes PHP standout is that it's a server-based language. As opposed to JavaScript; which is client-sided. What this means is that the code you write is executed on the server, generating the HTML code which is then sent to the client for processing. The client, once received the results of your script, would not know what the underlying code was. You could even program your server to process all of your files with HTML, so your users couldn't exactly tell what you're really up to. One of the best things with PHP is that you can jump right in! It's easy to understand, so don't be afraid of it. You'll come in, start learning, and within just a few hours, start writing some simple scripts. [anchor=section11]1.1 - What will we be learning?[/anchor] In this guide, you will be learning all the basic necessities in PHP. From variables, to functions, to classes, and all sorts of great utilities that will help you in the everyday usage of PHP! This guide is designed for the audience of newcomers in the language. If you're intermediate, above average, or just profound with this language, then I don't think you will find much of this information useful - as you have probably already learned it. PHP is a bold and dynamic language, so I envy you for giving it a shot! Hopefully, you'll end up being a widely successful web developer. [anchor=section12]1.2 - What's an IDE?[/anchor] IDE is an acronym for; 'integrated development environment'. An IDE will help you a long ways in the development field! It will show where you have made a mistake, or what is being used and what's not. It will also compile your code and check it before you can! It's an amazing tool to use if you're a developer, and can make your projects that you construct much more at ease. They have unique tools such as syntax highlighters, code parsers, built-in compilation devices, and etc. If you're working on a large project and aren't using an IDE, then I don't know what you're doing! [anchor=section13]1.3 - Selecting an IDE[/anchor] Selecting an IDE is as simple as pie! There are a few popular IDE's out there, and they are popular for a reason. They have a wide variety of tools, UI's, and plugins that make your coding experience just that much better. There are two 'most-popular' IDE's available for free: Eclipse, and NetBeans. Go and check each one out, decide for your own, and download that one. They may be a little weird to use at first, as it's a strange environment to get used to, but once you get the hang of it - it's a cakewalk! You can find the Eclipse PHP IDE here! You can find the NetBeans PHP IDE here! [anchor=section14]1.4 - When and when-not to use an IDE[/anchor] IDE's are great and all, but there are times when you shouldn't use them. For example, IDE's typically have the capabilities of doing simple work for you. It may sound nice, yes; however, you should be concerned on what you've actually learned. When learning the basics, I recommend to use a simple syntax highlighter, or code editor. Code editors, such as Vim and Notepad++, are great ways to still understand what exactly you're writing, and learn in the process. As they have syntax highlighters and code parsers typically build within them, you needn't worry about your code looking too ugly to work on. In this tutorial, I recommend you use one of the code editors as previously stated in this section. Code editors are especially beneficial to the learning process. [anchor=section2]2 - Variables[/anchor] Now that we're getting into variables, we can finally start getting into programming! Variables are little bits of code to store data. These types of data can be a range of things! Such as integers, strings, arrays, functions, or even instances of a class! Alas, for now, we must stick with the basics. In this section, we'll be introducing you to integers, strings, basic mathematics, and how to call these things. To get things started, I would like to point out that variables are represented by a dollar sign, followed by the title of said variable. For an example of this, you would use: <?php //Your first variable! $exampleVariable; ?> This would indicate that you have set a variable, and might call on it later. [anchor=section21]2.1 - Integers[/anchor] Now that we have a variable set, we can apply a value to this. For starters, let's go ahead and use an integer! An integer is, to put it simply, just a number. It tells the server that there is a variable there, that is a number, and the amount of this number. So, if you wanted this variable to just be the number 10, you would use: <?php //This variable is now an integer! $exampleVariable = 10; ?> That would tell the server that variable 'exampleVariable' is the number 10. [anchor=section22]2.2 - Strings[/anchor] However, not all variables are going to be numbers! You can also turn this into a string as well. Eh... You can turn a variable into lots of things, but these are just the basics of variables for now! Strings are just bits of text. You can make it one word, or even an essay if you so choose! So, if you'd prefer to have exampleVariable as a text instead, you can do that with this example: <?php //This variable is now a string! $exampleVariable = "I'm a string!"; ?> Now remember, strings always have to be in quotes, or single-quotes. I use the term 'single-quotes' as opposed to apostrophes because you are still quoting the string with it. If your text is not inside quotations, then you will receive an error! [anchor=section23]2.3 - Arithmetic[/anchor] Variables may also be used in arithmetic sequences. It's just like punching it into your calculator, it's so simple! You have assignments that you would need to apply to make it an arithmetic sequence. You would use + for addition, - for subtraction, / for division, * for multiplication, and % for modulo. In the example below, you will see a list of variables with their names corresponding to their actions. Read the names of these variables, or the comments above them, to see exactly what each variable is doing: <?php //This variable is adding two numbers $additionVariable = 1 + 2; //value would be 3 //This variable is subtracting two numbers $subtractionVariable = 2 - 1; //value would be 1 //This variable is multiplying two numbers $multiplicationVariable = 1 * 2; //value would be 2 //This variable is dividing two numbers $divisionVariable = 2 / 1; //value would be 2 //This variable is a simple mathematic sequence $mathematicVariable = 2 * 4 / (1+1) - 4; //value would be 0 ?> Now, if you're reading this and understand PHP to an extent, you may ask, "why is the echo part in the variables section?" Well, my friend, I have to have some place to put it! I didn't want it to have it's own section, so I figured after teaching people variables, I can show them how to call them. So, to start off, the echo statement is what outputs data onto the user's screen. So, if you were to put: echo 'Hello!'; all you would see on the screen was "Hello!". Print, however, is virtually the exact same. The only difference is, print has a return value of 1, whereas echo has no return value. Allowing you to use the print statement in expressions. If you wanted to call one of the arithmetic variables in the example above, all you would have to do is add a simple echo statement in the line below. Like so: [anchor=section24]2.4 - Echo & Print[/anchor] <?php //This variable is adding two numbers $additionVariable = 1 + 2; //value would be 3 //This variable is subtracting two numbers $subtractionVariable = 2 - 1; //value would be 1 //This variable is multiplying two numbers $multiplicationVariable = 1 * 2; //value would be 2 //This variable is dividing two numbers $divisionVariable = 2 / 1; //value would be 2 //This variable is a simple mathematic sequence $mathematicVariable = 2 * 4 / (1+1) - 4; //value would be 0 echo $subtractionVariable; //this would print the value of your variable 'subtractionVariable' ?> Though, you do not have to echo or print variables if you don't want to. You can easily just write a string of text onto the screen without calling it from anywhere using something like this: <?php //Time to print our first line! echo 'Hello world!'; ?> From this, all that would display onto the screen would be: Hello world! [anchor=section25]2.5 - Putting it all together![/anchor] Now that we've learned the basics of variables and how to call them - let's write some basic code that will mix all of this together! It may sound challenging, but fret not! What you've just learned is some of the most basics that will be used everyday in PHP. You'll remember these little things quite easily, and once you take a look at the code example below, you will see exactly why: <?php //Indicate your variable(s) $myName = "Example"; $myAge = 23; $sequence = 4 * 12 / 2; //Call your variable(s) via echo echo "Hello! My name is $myName, I am $myAge years old.<br />I've been asked to find out the value of 4 * 12 / 2 which would equal to: $sequence"; ?> This would output to: Hello! My name is Example, and I am 23 years old. I've been asked to find out the value of 4 * 12 / 2 which would equal to: 24 As you can see, in your echo you can apply variables to it without breaking the line of text you are outputting. Also, you are able to add HTML code within your echo statements, providing more organization to your outputs. However, in a case where you would need to have a break in your quotes, you would simply use periods to inform the server that you are making additions into this quote from elsewhere. For an example of this: <?php //Indicate your variable $exampleVariable = "Example"; //Call your variable(s) via echo echo "This is my example text: " . $exampleVariable . "!"; ?> This would print: This is my example text: Example! [anchor=section3]3 - Comparisons[/anchor] In this section, you will learn how to compare two things in PHP. This is an absolute essential for everyday programming. If you don't know how to compare, you won't make it very far. Here, you will learn how to compare integers, strings, and even learn new statements! Hopefully you'll be in for it, because now we're getting into elements just a little more advanced. For an example of this: <?php $name = "John"; if ($name == "Jasmine") { echo "Hey, how's it going!?"; } else { echo "Who are you?"; } ?> But for now, let's get back to the basics! Now, in order to compare, you will need to know the expressions to do so. These expressions will always evaluate out to 'true' or 'false'. These are some of the most commonly used expressions in the programming world, and here's what they are: [anchor=section31]3.1 - Comparison expressions[/anchor] You may wonder, 'what do those last two in the list mean?' Well, quite simply, it's to find out if a certain variable is equal to the same type of something else. However, these are commonly used in if statements, which have not yet been explained. Regardless, I will teach you these now. So, for example, if you want to make sure that a variable is equal to 30 and is an integer at the same time, you would use the === expression. Here's a code snippet example: == / is equal to >= / is greater-than or equal to <= / is less-than or equal to > / is greater-than < / is less-than != / not equal to === / is equal to and same type !== / is not equal to or same time <?php //Setting the variable $myVar = 30; //Calling your if statement if ($myVar === 30) { echo "Yep, that's an int that equals 30!"; } else { echo "Incorrect."; } ?> The result of this would be: Yep, that's an int that equals 30! Now that you've learned what each expression means, how do we apply them? If you hadn't figured it out based on my two if statement examples above: with if statements! Let's continue onto the next section. [anchor=section32]3.2 - The if statement[/anchor] If you're following this guide to the dot, then you've already seen me use an example of an if/else statement. In here, we're going to discuss exactly what "if" does. The if statement sends information to the server regarding whether a current state is true, or false; depending on your comparison expressions you set. If the statement is receiving the value it's looking for, then it will proceed with an action. If not, then it will return nothing. For example: <?php //Two basic variables $a; $b; //These two equal one another $a = $b; //'If' these two variables equal each other, it will return a bit of text if ($a == $b) { echo "That's true!"; } ?> This would print: That's true! However, if you wanted to ensure that this if statement happens only if the two variables did not equal each other, you would instead use this: <?php //Two basic variables $a; $b; //These two equal one another $a = $b; //'If' these two variables do not equal each other, it will return a bit of text if ($a != $b) { echo "That's true!"; } ?> As you can see, our comparison expression changed from example 1, to example 2. In example one, the if statement was checking to see is $a was equal to $b (==); and with our variable statement we made beforehand - that made it true! So, it printed the line. However, in this example, the if statement was checking to see if $a did not equal $b. And because variable $a was equal to $b, then the statement was false; thus no line was printed. [anchor=section33]3.3 - What else!?[/anchor] What if you wanted to have some sort of output if the conditions are not met in your if statement? Well, that's where the else statement comes in handy. As you've seen in my first example on if statements, you may have seen that line of code that says, '} else {'. What this means is - if these conditions are met, an action will be performed. However, when the conditions are not met - this is where the else statement applies it's action. For example, let's make an else action display on screen: <?php //Simple boolean variable $a = true; //If this variable is false, perform an action, 'else' perform a different action if ($a === false) { echo '$a is false'; } else { echo '$a is true'; } ?> The output on screen would be: $a is true. However, this is not the end of the else statement! You can prolong checkups by searching for another condition if the criteria of the first condition is not met using elseif. This statement allows another if statement to be performed if the predecessor statement's conditions were not met. For an example of this: <?php //Simple int variable $a = 46; //If this variable is false, perform an action, 'else' perform a different action if ($a == 50) { echo '$a is 50'; } elseif ($a != 45) { $a = 45; echo '$a is now 45'; } ?> The ladder of checks this does is; first, it checks to see if variable $a is equal to 50. If not, it goes onto the next statement, which is our elseif statement. This then checks to see if variable $a does not equal to 45, and currently - $a is 46. So, this statement sees that $a does indeed not equal 45, so it then changes it to 45, and prints the line, "$a is now 45"; making $a equal to 45. [anchor=section34]3.4 - Combine![/anchor] Now that you know all the basics, it should be known that you can also compare strings! It's just as easy as comparing integers or boolean values. Just remember, strings are always in quotes. So, now let's combine all we've learned here. If you take a look at the very beginning of section 3, you will see my first example. This is almost a combination of everything we've learned so far, all we need to do is just add one thing, and we will be in the go: <?php $name = "John"; if ($name == "Jasmine") { echo "Hey, how's it going!?"; } elseif ($name == "John") { echo "Hey, John! I haven't seen you in ages!"; } ?> This would print: Hey, John! I haven't seen you in ages! Now that we've covered if/else statements; what if there's something you want to add that would go through a large amount of checks depending on the same value? As opposed to writing a mass amount of if/else statements, you could simply run it through a switch statement! Here's an example of what you're going to be building: [anchor=section4]4 - Let's switch it up![/anchor] <?php switch (2) { case 0: echo 'The value is 0'; break; case 1: echo 'The value is 1'; break; case 2: echo 'The value is 2'; break; default: echo "The value isn't 0, 1 or 2"; } ?> This would print, The value is 2 As you can see in the parameters of the switch statement, you see that it's simply "2". This would mean it would go through the cases until it reaches case 2, then output the action it underlies. [anchor=section41]4.1 - Testing the waters[/anchor] As always, we're not going to rush anything here. Nice and easy, slow and steady. We need you to learn, not quickly "get this over with". Each switch statement will be made up of cases. Each case will represent, basically, an if statement. Once you end your case, you will need to (break;) it, showing the server that the case has ended. Once you complete all your cases, you will still need to add your default case. This is there for when every output of your switch would be false, it displays your default case's action. As it is your default case, breaking this will not be necessary. You can also choose what you're switching through, and the properties of the case. If you want to switch through a series of strings, you can do that, if you want to switch through even an array, you can do that! It's very helpful for when you have a lot of things you're checking for. Here's an example of a basic switch statement through strings: <?php $fruit = "Apple"; switch ($fruit) { case 'Apple': echo "Yummy."; break; default: echo "None of the above!"; } ?> As you can see, the switch statement is switching through the cases until it finds the value of variable $fruit. Obviously, the first case is equal to the variable's value of "Apple", therefor, it would print: Yummy. [anchor=section42]4.2 - Rack 'em and stack 'em[/anchor] Another great thing about switch statements is that multiple cases can be applied to the same task! This make things much easier if you want to have the same output for multiple values. Consider the following if statement: if ($n == 0 || $n == 1 || n == 2) { echo '$n is between 0 and 2!'; } else { echo '$n is not found yet'; }[/code] This would check and see if variable $n is equivalent to either 0, 1, or 2. If it is, it would print the string shown in the echo statement. However, there is a much simpler way of doing this, with your switch statement: [code=php] switch($n) { case 0: case 1: case 2: echo '$n is between 0 and 2!'; break; default: echo '$n is not found yet'; }[/code] This would do the same exact thing the if statement provided above does. This could also be applied with strings, and other variables, as I had previously stated. It's quite a nice feature, and is used very commonly! [center][size=6][anchor=section43]4.3 - Alternative syntax[/anchor] [/size][/center] Here, we will kick it back to an earlier section of the tutorial as well. We will learn the alternative syntax for both switch statements, and if statements. "Alternative syntax? What do you mean?" Well, the examples I provided are the most common ways of enacting these statements. However, there's an alternative route you can go for applying these statements. As opposed to the normal braces, perhaps you can use colons? Take a look at the following: [code=php] $fruit = "Apple"; switch ($fruit): case 'Apple': echo "Yummy."; break; default: echo "None of the above!"; endswitch; As you can see, instead of using { } braces as we normally do, we used a colon and ended it with the 'endswitch;' statement. You are able to do this for if statements as well: if ($a == 5): echo "a equals 5"; elseif ($a == 6): echo "a equals 6"; else: echo "a is neither 5 nor 6"; endif;[/code] The same applies. [center][size=6][anchor=section44]4.4 - Put it together![/anchor] [/size][/center] Now that we've learned the basics of a numerous amount of things, perhaps we can put them [b]all[/b] together and see what we've learned so far! Here's what I got: [code=php]<?php //Our variables; check! $myName = "Example"; $myAge = 30; $isAlive = true; //Our arithmetic & echo statement; check! echo 6 * 22 . "<br />"; //if and switch statements; check! if ($isAlive === true) { switch($myName) { case 'Example': echo "Your name is $myName and you are $myAge years old!"; break; default: echo "Cannot locate 'Example'."; } } else { echo "We can't search you up if you aren't alive!"; } ?> The output of this would be: 132 Your name is Example and you are 30 years old! Congratulations! You've finished roughly half of An Introduction to PHP! Keep moving on, you're learning a lot! We're going to keep slowly advancing, but I'll make sure that you have the utilities here in this thread to have a successful start. [anchor=section5]5 - Arrays[/anchor] An array can help with your organization when you have long lists. An array is actually an object, so there is a little object-orientation with PHP; but we'll get to that later! As opposed to generating hundreds to thousands of variables - simply store it in one array! Think about it this way; an array is like a list of items (for example; a shopping list). You don't want to put each item on it's own page (a variable), that's a huge waste of paper! However, if you put your entire list onto one page (the array), then things will be a lot more organized and more efficient. [anchor=section51]5.1 - How does it all work?[/anchor] Well, if you're following this guide all the way through, you would probably remember me telling you that you can apply your variables to be arrays. Yes, I'm finally explaining it to you! You know how variables can become integers, strings, mathematical sequences, and etc. You know how to apply them in if and switch statements. However, this is where things get a little trickier. An array is, as briefly explained in the previous section, is a list of items. Whereas you could write hundreds of lines of variables and call upon those - or you could simply make an array. Take a look at the following: <?php //Your very first array! Congratulations! $myArray = array("Chips", "Salsa", "Rice", "Corn" ); ?> As you can see - the array starts exactly as a variable. You start it with your dollar sign, followed by the name of your variable, then the equal sign. That's because... You guessed it! It is a variable! You're just designating it to be an array. To declare it as an array, you need to first act as if you're just making a regular ol' variable. Once you've gotten passed the '$myVariable = ' part, this is when it gets different! Once you've done this, you'll want to designate the array. To do this, it's simple as, "array( <insert list> );" Each item in your list will be separated by quotations and commas. So, from my example, you can see exactly this for each list. [anchor=section52]5.2 - To access an array[/anchor] Now that you understand how these arrays work - it's time to find out how you call on these arrays! To do this, it's quite simple. You can either access them by Offset with braces, or brackets! Simply call your variable followed by either your brackets or braces. For an example of this: <?php $myArray = array("Chips", "Salsa", "Rice", "Corn" ); echo $myArray[0]; ?> This would simply print: Chips. Now, you can replace the brackets in the echo statement calling the variable with braces, and it would perform the same action. You may wonder, however, what that number means inside the brackets. Well, this number represents which item(s) that I want to call from the array! By default, the first item's identification number will always be 0, and you would increase it from then on for further items. So, if you were wanting to call the "Rice" item, you would use $myArray[2]; - and this would print that item. [anchor=section53]5.3 - Modify, delete, sort, and push your array[/anchor] Well, you know how to create and call on a simple array. How about when you need to modify your array further down the road? Well, to do this; all you would need to do is declare the variable, the item's number, and simply make it equal to a different result. Just like changing an integer variable! Take a look at the code below: <?php $myArray = array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ); echo $myArray[3]; $myArray[3] = 15; echo "<br />" . $myArray[3]; ?> This would output: 40 15 Simple as that! These features for arrays are always beneficial in a case where it's dependent on a user's input. Though, what if you need to delete a section, or item, of an array? Well, honestly; that's easier than modifying an element of one! All you need to do is use the 'unset' statement, declaring your variable and the identification number of the item you want deleted. So, for example: <?php $myArray = array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ); echo $myArray[3]; unset($myArray[3]); echo "<br />" . $myArray[3]; ?> This would print: 40 50 So, as you could see in that example, deleting the element of the array causes the next element in your array to take the place of it's predecessor. Pretty neat, huh? Though, in a scenario where you want to sort your array by numerical or alphabetical order... How would one do this? Well - with 'sort'ing it! Just one simple statement, and it is then placed in numerical or alphabetical order! It depends on what you choose your array to be! Take a gander down below, and see an example of this: <?php $myArray = array("Z", "B", "Y", "A" ); echo $myArray[0]; sort($myArray); echo "<br />" . $myArray[0]; ?> This would print: Z A As you can see, Z was the first option in the array. Though, when the second echo was called, why was A the first? Well, you see, we sorted the array! This detects whether it is alphabetical or numerical, then sorts it regarding the first number(s) or letter(s) in this array. However, there is also a reverse order to this sorting method - 'rsort'. Very cleverly named, yes? Take a look at the example below! <?php $myArray = array("Z", "B", "Y", "A" ); echo $myArray[1]; rsort($myArray); echo "<br />" . $myArray[1]; ?> This would print: B Y Now, just like the sorting method, you see that B is the second item in the array. So, we called that - as you can tell! Though, in the second echo, Y was instead printed. This is because we reverse sorted it. This is a neat feature you can use if you ever want to reverse alphabetically/numerically sort an array. Instead of sorting it dominantly, it takes the last letter(s) or number(s) in cycle and sorts it last-to-first. What if later down the road you'd like to add something to your array? For this, you would use your 'array_push' method. This allows you to add elements to your array with ease! So, for example, if you're working on, let's say, a turn-based game providential to array-based saving, then array_push could come in handy! Observe the following: <?php $stack = array("grape", "cherry"); array_push($stack, "orange", "coconut"); print_r($stack); ?> The output would print: Array ( [0] = grape [1] = cherry [2] = orange [3] = coconut ) Nifty, right? This could come in all sorts of handiness when necessary. I promise, you'll be glad that you remember how to do this! [anchor=section54]5.4 - The associative array[/anchor] So thus far, you've learned to construct an array, sort it, push it, delete items in it, and call it via integer. However, in the case of you wanting to be more descriptive of your data, you could use something called an 'associative array'. Some languages, such as Java, do not view associative arrays to be arrays - and separate them away from any correspondence. For example; Java calls these and utilizes them as 'maps'. However, PHP treats them as the same as an array. It makes use of key => item pairs which make organization much more simple. For example of a difference between the two arrays: <?php //First, the normal array $myArray = array( "Item1", "Item2", "Item3" ); //Now we call it echo $myArray[1]; //Time for our associative array $myAssocArray = array( 'Item1' => 'Value of item1', 'Item2' => 'Value of item2', 'Item3' => 'Value of item3' ); //Now we call it echo "<br />" . $myAssocArray['Item2']; ?> This would print: Item2 Value of item2 So, as you can see in this example - we give each item in our list an identification title, as opposed to it having a number. It can be used for readability and organization. Which would be easier to read; a normal array, or an associative array? The answer is obvious! [anchor=section55]5.5 - Using it as a map[/anchor] Associative arrays, just like Java, are often called maps. These are because as opposed to a specific number relation, it uses a defined key. How much tougher would it be to travel from a map, whether it be an online map, an app, or just a standard paper-map, if it was numerically coordinated? So, in a sense, if you're using an associative array - then you're already using a map! Congratulations! So, for an example, have a look below: <?php $myAssocArray = array('year' => 2015, 'color' => 'red', 'doors' => 4, 'make' => 'Nissan'); echo "My car is a, " . $myAssocArray['make'] . " and was made in " . $myAssocArray['year']; ?> This would print: My car is a Nissan and was made in 2015 As you can see, this form of array is very beneficial for mapping your code and making it more readable. [anchor=section56]5.6 - Multiple dimensions![/anchor] What you may have not knows was: Arrays can store multiple arrays, causing them to become multidimensional arrays. These are especially useful for, say, designating a deck of cards to an array. This way, you could have each card in coordination to their face. Whether it be a 2 of diamonds, or a 9 of spades - this can be done with a multidimensional array. Take a look: <?php $deck = array(array('2 of Diamonds', 2), array('8 of Spades', 8), array('4 of Hearts', 4), array('5 of Diamonds', 5), array('7 of Diamonds', 7), array('2 of Spades', 2)); //Pretend the first card drawn was the 4 of Hearts: echo 'You have the ' . $deck[2][0] . '!'; ?> Now, this is only a two-dimensional array. There can be as many dimensions as you want, but if you exceed five dimensions in your array, it might get a little tough to manage. However, as you can see from the example, we call this in 'rows' and 'columns'. The first bracket defines your row, the second would define your column. If you were to add more dimensions to this, you would add more brackets. [anchor=section57]5.7 - Mash it all together![/anchor] Now that you understand your arrays, I want to know if you can put it all together! Learning interactively is statistically the best way of learning, so hopefully, if you're following this tutorial to the dot, you are doing just that! I know it may be boring, but it's worth it in the long run, I can assure you. So, if you put everything you've learned in this section together, then you should come up with something like this: <?php //A standard array $myArray = array( "Example A", "Example B", "Example C" ); //Calling it echo $myArray[1] . "<br />"; //Then - associative array $myAssocArray = array( 'fruit' => 'Apple', 'veggy' => 'Carrot', 'candy' => 'Chocolate' ); //Now we call it echo $myAssocArray['candy'] . "<br />"; //Finally, our multidimensional array $deck = array(array('2 of Diamonds', 2), array('8 of Spades', 8), array('4 of Hearts', 4), array('5 of Diamonds', 5), array('7 of Diamonds', 7), array('2 of Spades', 2)); //Calling an array yet again echo 'You have the ' . $deck[2][0] . '!'; ?> This would output: Example B Carrot You have the 4 of Hearts! So, as you can tell, arrays are a huge part of PHP and any sort of development in general. If you can't use an array, then you likely won't make it very far. Now, don't get anything distorted - there are times to use arrays, and times to avoid them. However, there tends to be more times to use them, than avoidance. [anchor=section6]6 - The loop[/anchor] Sometimes, you'll encounter a tough time when developing. Especially when you are designated a task that requires the same task to be ran over and over. Let's say we want to print a list containing all the months of the year; I, for example, would use something like this to do so: <?php $months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "December" ); foreach ($months as $month) { echo "<li>$month</li>"; } ?> This would print: That, my friends, would be looping an array. We'll get to that in the meantime. For now, let's focus on the for loop: January February March April May June July August September November October December [anchor=section61]6.1 - The for loop[/anchor] So, as you've seen me provide an example of a for loop already (well, you saw me use the foreach loop, but it's deprived off of the norm - for loop), you can see that you are able to loop through arrays. Great for a list, am I right? Well, before we get into that, let's just start with the basics. Say you want to print the numbers 1 through 20 on separate lines: Instead of writing twenty echo statements, or just one with twenty <br /> tags, you could write a simple three-liner - like so: <?php // Echoes twenty numbers for ($i = 1; $i <= 20; $i = $i++) { echo $i . "<br />"; } ?> This would print: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 So, as opposed to writing twenty lines of echoes to do this - you could simply write just one easy for loop. This can make things much easier when you have a large loop to go through; or even if you just have a small loop to go through. It's more efficient to use than to write, say, three echo lines. [anchor=section62]6.2 - Looping an array causes something new[/anchor] As you have seen in an earlier example, looping an array causes you to use the foreach element. This means - for each item in your variable; this happens. This makes it much easier for you to print a list of items. Just like in my earlier example: <?php $months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "December" ); foreach ($months as $month) { echo "<li>$month</li>"; } ?>[/code] And just like before, this will output: [list][*]January [*]February [*]March [*]April [*]May [*]June [*]July [*]August [*]September [*]November [*]October [*]December [/list] As you can see in the example above - this [i]foreach[/i] loop sets it's own parameters. It first generates it's own parameters [i]as[/i] (using the built in method that the language provides) a custom parameter the statement makes. So, as you can see, you use array $months [i]as[/i] new variable $month - indicating each individual item the array provides. You can also loop associative arrays, check down below: [code=php]<?php $cake = array( 'large cake' => 'I do ', 'medium cake' => 'I do ', 'small cake' => 'I do not ' ); foreach ($cake as $size=>$decision) { echo $decision . 'want a ' . $size . '<br />'; } ?> This would print: I do want a large cake I do want a medium cake I do not want a small cake Looping is so cool, right? It makes things so much easier to perform than a whole bunch of unnecessary code you could use for just this! Man-o-man, could you just imagine all the if/else statements that would be required for all of that? Would rather just loop it! [anchor=section63]6.3 - While this... Maybe this?[/anchor] Maybe you want to loop until a certain condition is equal to a certain value? While this condition is false, it will continue looping until it is true. Hence, for this, you'd need to use your 'while' loop. I know, they are so creative in naming their methods! Either way, it's still the same, if not wildly similar, as in other programming languages such as Java, Python, or the C-languages. Take a look down below: <?php $headCount = 0; $flipCount = 0; while ($headCount < 3) { $flip = rand(0,1); $flipCount ++; if ($flip) { $headCount++; echo "H"; } else { $headCount = 0; echo "T"; } } echo "<p>It took {$flipCount} flips!</p>"; ?> This would display the amount of times it would take to reach three consecutive 'head flips' in a row. As long as there aren't three "H['s]" displaying on screen, it would keep looping until it reaches three H's in a row. While this condition is false, it will continue looping until it reaches proper standards. So, while loops are great for loops that you don't know when will end. Hence the example above. If we were to flip a coin until we received three head placements in a consecutive sequence, we wouldn't necessarily know when to stop this loop. That's basically why the while loop was created. [anchor=section64]6.4 - How do you do?[/anchor] Now that you understand while loops, it's time to learn - how do you do this while this statement remains false? This is where the 'do' part of the while loop comes in handy. You may have noticed that the while loop checks the condition before each individual iteration. What if you wanted to check this after each iteration? Well, that's exactly what the do statement can do for you. If you look at the following: <?php $flipCount = 0; do { $flip = rand(0,1); $flipCount ++; if ($flip) { echo "H"; } else { echo "T"; } } while ($flip); $verb = "were"; $last = "flips"; if ($flipCount == 1) { $verb = "was"; $last = "flip"; } echo "<p>There {$verb} {$flipCount} {$last}!</p>"; ?> This code will keep flipping as long as the result is heads. As long as the result is heads, it flips until there is tails. So, you shouldn't expect more than just two to four outputs on this loop. [anchor=section7]7 - Onto functions![/anchor] Functions are reusable bits of code, saving you much copying and pasting. Yes, one thing to know as a developer, copying and pasting may be a common part of your career. Why would you write out a whole block of code that's just as efficient as the one you've seen online - that you could copy and paste? Why rewrite the same code that you've already written, as opposed to simply copying that function? PHP has a wide variety of built-in functions that we'll be learning. You've already learned some of them, most of which being in your arrays section. That matters nay, however! I will teach you these functions and how to apply them, even in OOP! But, we'll get to OOP in section 8, which is our final section. Take a look below: <?php //An example variable we will be using in this subsection $myName = "Example"; //The substr function allows you to receive a snippet of your string variable $partial = substr($myName, 0, 4); print $partial; echo "<br />"; //The strtoupper simply makes your whole string uppercase $upper = strtoupper($myName); print $upper; echo "<br />"; //The strtolower function does the exact opposite of strtoupper $lower = strtolower($myName); print $lower; ?> This would print: Exam EXAMPLE example Now, as you can see, these built in functions can help with your - eh; functionality. You'll always want your website to be functional to the best of it's abilities. And the best of it's abilities can be basically the best of PHP's abilities. I know that there are other languages that enhance the scripting language of PHP such as JavaScript and MySQL - but that's beside the point! Alternatively, functions can have parameters. These tell the function if there is data that it needs to check over. This can come in handy if one is trying to call an instance of this method more smoothly, calling in the arguments required for the given function. Functions can also return statements as their actions. You can make these return statements variables that you've already set, or that you plan to change in the future. Below, see the following example: <?php $name; function returnName() { return $name = "Example"; } ?> Now, perhaps if you were to call this method via echo statement, it would return an "Example" value. [anchor=section71]7.1 - Time to put arrays in them![/anchor] Putting arrays in functions is as easy as ever. Basically, you just make an array. It's virtually it's own function as is! Just join the array with a print statement, and that's an official function. If you'll take a gander on the example below, you'll know exactly what I mean: <?php //Name your function function arrayFunction() { //Create an array with several elements in it, //then sort it and print the joined elements to the screen $the_array = array("Banana", "Peach", "Mango", "Apple", "Cherry"); sort($the_array); print join(", ", $the_array); } arrayFunction(); ?> So, as you can see in the example above, joining the array with the statement 'print join', you can join these arrays by separation based on whatever you decide to separate it with. Whether it be by slashes, periods, commas, or anything! The output of this would be: Apple, Banana, Cherry, Mango, Peach And as you already know the rsort method, then you shan't worry about all the little nicknacks! [anchor=section72]7.2 - Calling these functions[/anchor] If you're coming from an OOP language, then these parts of the tutorial should be nothing more than a cakewalk. Calling these functions is the easy part. Making them - now that's the real challenge. However, I'll let you figure out the more advanced functions that you're able to construct. In this tutorial - we'll only cover the basics. So, to call these functions, all you'll need to do is list the function followed by the parameters if necessary. Take a look at the example below: <?php $name = "Example"; function greetings($name) { echo "Greetings, " . $name . "!"; } greetings($name); ?> This would print: Greetings, Example! As you can see, if you parameters are set to an existing variable, it would draw the data from said variable and print it onto the screen via echo statement. However, you can make functions into object-orientation; they are mainly designed as scripts via PHP. There are many wonders you can do with this language, just keep researching beyond this tutorial, and you'll surely find out! [anchor=section73]7.3 - Messing with parameters[/anchor] Now that you know how to build and call these functions, but they definitely need to be able to take in some input. If they couldn't, that would just be fairly redundant. This is when parameters come in handy. Take a look below: <?php $name = "Example"; function greet($input) { echo "Greetings, " . $input . "!"; } greet($name); ?> This would print: Greetings, Example! See how in the parenthesis you are naming a new variable $input? Well, this is telling the function that it needs to collect some sort of data in order to process. By calling your method with the variable $name within the parenthesis is just how it's done. It could be very useful for, say, you want to save an array publicly, but need to call it for the given function. [anchor=section74]7.4 - Apply it![/anchor] Now that we've gotten functions down, we need to recap over what we've learned. Apply everything you've learned - try to shoot for something fancy! Don't be dull and boring like I am below: <?php function arrayFunction() { //Create an array with several elements in it, //then sort it and print the joined elements to the screen $the_array = array("Banana", "Peach", "Mango", "Apple", "Cherry"); sort($the_array); print join(", ", $the_array); } ?> [anchor=section8]8 - PHP is also OO![/anchor] A wonderful thing about PHP is that it is, too, OOP. Before we start: What is OOP? Well, object-oriented programming (OOP) is a language that bases it's concept on "object", which is data, typically in the form of fields, built in structures and contain code in procedures; known as methods. Distinguishably, OOP languages have a feature where an object's procedure can access and often alter the data within correspondence. This can be very useful for when you need to access an object with ease. You would have to construct your properties and set your parameters, however, but that's easy! However, most OOP languages are class-based, meaning objects are instances of the given class. Don't let that fool you! There is much diversity in OO languages. Take a look at an example of OO programming in PHP below: <?php //Creating the class class Person { //Creating the properties public $firstName; public $lastName; public $age; //Assigning the values public function __construct($firstName, $lastName, $age) { $this->firstName = $firstName; $this->lastName = $lastName; $this->age = $age; } //Creating a method public function greet() { return "Hello, my name is " . $this->firstName . " " . $this->lastName . ". I am " . $this->age . " years old!"; } } //Create a new Person $newPerson = new Person('Example', 'Last Name', 22); //Greeting the newPerson echo $newPerson->greet(); ?> This would print: Hello, my name is Example Last Name. I am 22 years old! Pretty neat, right? Review the code and try to see how it's doing this. If you figure it out, you'll probably think that it's pretty cool. OO is a very functional style of programming. If you can't figure it out, don't worry and just read the text explaining it below. This calls your object, or instance from the properties designated in the function you're calling from class Person. In the __construct function, you would declare your parameters to set the variables that are associated with the constructor. [anchor=section81]8.1 - Time for class[/anchor] Classes are an absolute essential for OOP. It is your foundation to your data structure. So, I suppose it really is the 'structure' part. You will declare your variables here publicly and call them in your instance after constructing them - making them your properties. When you want to utilize these properties, you will need to add a function to the class and call it with your instance. However, for now, take a look at the following: <?php //Your first class! class Person { } //Your first instance! $newPerson = new Person(); ?> You have now generated an empty class and a blank slate of an instance. To make use of these, you will need to assign properties. [anchor=section82]8.2 - Use of properties[/anchor] To make your properties, it's as easy as declaring a public variable. This would be useful for when you need not any parameters for your instance to utilize it. For example, an if statement would be a great time to use this. Take a look at the following: <?php class Person { public $isAlive = true; } $newPerson = new Person(); if ($newPerson->isAlive) { echo "It's alive!"; } ?> This would print: It's alive! As you can see, once you declare your boolean variable, you can call on it. It makes use of instance->property to check these. If you look closely, you'll see that you in fact do not use a dollar sign to call your property values. Now, if you wanted your instance to have specific properties for each object, then you would need to set your parameters. To do this, you would need to use your __construct method. This declares variables as specific properties for it's instant. Perfect, right? Have a look down below: <?php class Person { public $firstName; public $lastName; public $age; public function __construct($firstName, $lastName, $age) { $this->firstName = $firstName; $this->lastName = $lastName; $this->age = $age; } } $newPerson = new Person('Example', 'Last Name', 22); ?> Now, this makes it to where your instant $newPerson is now under the parameters 'Example', 'Last Name', and 22. This is due to the function in the class. This __construct function follows with parameters for the class, and to declare them; it uses $this->variable = $parameter. Now, what if you wanted to make a custom action in your class for a specific instant? Well, you can do it just as easy as making a simple function! However, this function would typically receive the data based on the properties of the given class. Look below: [anchor=section83]8.3 - Throw a method in the matter[/anchor] <?php class Person { public $firstName; public $lastName; public $age; public function __construct($firstName, $lastName, $age) { $this->firstName = $firstName; $this->lastName = $lastName; $this->age = $age; } public function greet() { return "Hello, my name is " . $this->firstName . " " . $this->lastName . ". I am " . $this->age . " years old!"; } } $newPerson = new Person('Example', 'Last Name', 22); echo $newPerson->greet(); ?> This would print: Hello, my name is Example Last Name. I am 22 years old! As you can see, the function declares the input of the properties the construct method set. Making use of the very same $this->variable. Then, since it's drawing the properties, it reads the properties set in the instance calling it. And to call the method, you use, $instant->method(). [anchor=section84]8.4 - The final chapter[/anchor] Now that you've learned the basics of OOP, let's see what you've learned! Try to be innovative and venture down from everything you've learned in this tutorial. You'll be amazed at some of the things you can accomplish! However, for a review of this section, take a look at my following example: <?php class Person { public $isAlive = true; public $firstName; public $lastName; public $age; public function __construct($firstName, $lastName, $age) { $this->firstName = $firstName; $this->lastName = $lastName; $this->age = $age; } public function greet() { return "Hello, my name is " . $this->firstName . " " . $this->lastName . ". I am " . $this->age . " years old!"; } } $newPerson = new Person('Example', 'Last Name', 22); if($newPerson->isAlive) { echo "It's alive!"; } echo "<br />"; echo $newPerson->greet(); ?> This would print: It's alive! Hello, my name is Example Last Name. I am 22 years old! I hope that everything was all clear in this section. I know that it can sometimes be confusing, but once you get the hang of it, you'll be on the fly! Though, as you can see, object-orientation is very effective for data. [anchor=section9]9 - Hope you liked it![/anchor] I hope that you've learned a lot from this guide. It has been my sole pleasure in bringing this to you. A lot of hard work and dedication was put into this! Nonetheless, if you've made it this far, from head to toe, then wow! Congratulations! I honestly was not expecting many, if any, to read this guide all the way through. As long as someone's learned from this guide, it was an accomplishment for me. If you have any questions regarding something in the guide, please post below and I'll do my best in assisting you. Hopefully, most of the sections here were explained thoroughly and to the point. I've done my best in trying to get a detailed description, however, I can understand if things may get a bit blurry. Thank you for reading, and I hope you've learned something today!
  5. Here to advertise my server and make some friends possibly
  6. Audi0


    Hello, I'm [B]thaBoom[/B]. I'm new here and looking forward working with RuneScape servers and making some friends, so greetings to you all. I'm 17 and I was born in Canada. Apologies this is a short introduction. Good to meet you all.
  7. Hello i would like an introduction board to be made for many reasons which i will list below it will be a nice innovative/unique way for people to introduce them selves and when i say unique i do not say it compared to other communities since they most likely have that already since it is an original idea... but i mean unique as in to this community since i see that the way to introduce your self at the moment is by replying to a thread now that thread has been made since 2010 and by looking through it all i see is some stupid replies and not a proper introduction some one word replies and people replying to introductions welcoming members to the community this is not how it should be done in fact makes the community look unorganized another reason on why we should have an introduction board is because it will be a more easy format for people to use and moderate and write a proper introduction for people to read and reply to... a mod told me that this will cause spam well i was just wondering whats your voluntary job as a mod for? im pretty sure its to punish those who do and looking at that introduction thread and many other sections\threads have spamm and nothing is being done about it.... also another suggestion is more staff loyal and respectful ones to thanks :)
  8. Made a new intro for my server. Took around 4 hours (due to dynamic region, and the cutscene). [video=youtube;jmG9E0TYdE0]https://www.youtube.com/watch?feature=player_embedded&v=jmG9E0TYdE0[/video] Sorry if this is considered advertising.
  9. [I]Table of contents[/I]: [LIST=1] [*]Introduction [*]Basics [*]Preparing objects for seralization [*]Code Snippets [*]Other [/LIST] [B][SIZE=4]1. Introduction[/SIZE][/B] With [URL="http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html"]Java Sockets[/URL] you can send things like raw text, bytes, UTF, and class instances (objects). In this thread we are going to focus on sending and receiving objects. It's actually not as easy as you might think. [SIZE=4][B]2. Basics[/B][/SIZE] To send and receive objects via sockets you need to have an [URL="http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html"]ObjectInputStream[/URL] and an [URL="http://docs.oracle.com/javase/7/docs/api/java/io/ObjectOutputStream.html"]ObjectOutputStream[/URL] and ofcourse a socket. When working with these you might encounter quite some obstacles that can take very long to get rid of. I too have spent many hours debugging and trying several things. First of all, when creating new instances of the ObjectOutputStream and the ObjectInputStream you have to make sure the ObjectOutputStream comes [B]FIRST[/B] and then the ObjectInputStream. This is because the ObjectInputStream will wait until there is an ObjectOutputStream in existance. This is commonly referenced to as the "Chicken and the egg" problem. [I][B]See Snippet 1.[/B][/I] Secondly, when sending an object, you always have to send an UTF header first. Java uses [URL="http://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8"]Modified UTF-8[/URL] to work with serialized data. Using this header which can be anything (I mostly just send a random letter as the header) you tell the other side that it should now expect an object to come in. [B][I]See Snippet 2[/I][/B] To receive an object you simply have to read it from the ObjectInputStream and then check its name and cast it to the class. [B][I]See Snippet 3.[/I][/B] [B][SIZE=4]3. Preparing objects for serialization[/SIZE][/B] Serialization is required in order to be able to send objects via sockets. To do this you simply implement the [URL="http://docs.oracle.com/javase/6/docs/api/java/io/Serializable.html"]Serializable[/URL] interface to the class of the object you want to send. You can do everything you want with the class as transient variables and methods (including getters and setters) are not serialized. This means that only variables get serialized. [B][I]See Snippet 4.[/I][/B] Object classes have to be in the same package on both sides too otherwise the receiving side will throw an [URL="http://docs.oracle.com/javase/7/docs/api/java/io/OptionalDataException.html"]OptionalDataException[/URL] that basically means the received data cannot be used. [B][I]See image below[/I][/B]. [IMG]http://cdn.codiction.com/sockets.png[/IMG] [spoiler=4. Code Snippets] [B][SIZE=4]4. Code Snippets[/SIZE][/B] [I][SIZE=2][COLOR="#FF0000"]Note: these snippets are pseudo language and thus cannot be used without modification.[/COLOR][/SIZE][/I] [B]Snippet 1:[/B] [CODE] public void createStreams(Socket s) { ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream()); ObjectInputStream in = new ObjectInputStream(s.getInputStream()); } [/CODE] [B]Snippet 2:[/B] [CODE] public void sendObject(Object o) { out.sendUTF("bla"); //you can send anything out.sendObject(o); out.flush(); //this is used to guarantee that everything gets sent. } [/CODE] [B]Snippet 3:[/B] [CODE] (inside a method): String utf; while((utf = in.readUTF()) != null) { parseObject(in.readObject()); } private void parseObject(Object o) { if(o.getClass().getSimpleName().equals("name of the class, for example Test")) { Test t = (Test) o; //t will have all the contents that it had at the other socket (client & server application) } } [/CODE] [B]Snippet 4:[/B] [CODE] public class Bla implements Serializable { int lol = 2; transient int lol2 = 5; //will not be sent public void test() { } } [/CODE] [/SPOILER] [B][SIZE=4]5. Other[/SIZE][/B] This is a basic introduction to the Java ObjectInputStream and ObjectOutputStream. There are many possibilities and things I haven't covered here but they are more advanced. If you have any questions you can ask them here.
  10. Gircat

    [AE] Introduction

    Proud of the way this actually turned out. :gg: Want to show it to you guys though. [video=youtube;843lxe8Upk4]http://www.youtube.com/watch?v=843lxe8Upk4[/video]
  11. This tutorial will be a introduction into android development. This is a basic tutorial and is only meant to help a begginer programmer on the feel of android applications and how they are developed. So don't expect a big application because this is not. Also this will help you to begin with setting the Android into eclipse est. [B]This application will contain:[/B] [LIST] [*]A button [*]A Toggle Button [*]A text box [*]A text label. [/LIST] [B]This application will:[/B] [LIST] [*]Once you click the toggle button it will change the text in the textbox to a password like text Ie ****=pass [*]Once you click the normal button it will: [*]Check what text is in the textbox then: [*]Change the text in the text label according to what is in the textbox. [/LIST] As you can see nothing fancy but it should help some people get started into android development. [B]What an android application is:[/B] [LIST] [*]A mobile software application developed for use on devices powered by Google's Android platform. [*]This can be anything from a game to a calculator and so on....... [/LIST] [B]NOTE:[/B] I will not be posting loads of pictures. Instead I will use the printscreen application on my computer and I will post the link for you to view if you wish. This makes it allot faster for me to make this tutorial. [B]Difficulty:[/B] Not hard at all 2/10 Depending on if you know a little about java or not. [B]1st off what your going to need:[/B] [LIST] [*][B]Eclipse IDE[/B]: Which can be downloaded from [url=http://Eclipse.org]Eclipse - The Eclipse Foundation open source community website.[/url] [*][B]The android SDK[/B]: Which can be downloaded from [URL="http://developer.android.com/sdk/index.html"]developer.android.com[/URL] [*][B]The eclipse plugin[/B]: I will show you how to get that now: [/LIST] [LIST=1] [*]Start Eclipse, then select Help > Install New Software. [*]Click Add, in the top-right corner. [*]In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location: [CODE]https://dl-ssl.google.com/android/eclipse/[/CODE] [*]Print screen of what it should look like:[url=http://prntscr.com/12ycvv]Screenshot by Lightshot[/url] [*]Click OK. [*]If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" [*]In the Available Software dialog, select the checkbox next to Developer Tools and click Next. [*]In the next window, you'll see a list of the tools to be downloaded. Click Next. [*]Accept the license agreements, then click Finish. [*]Once the installation completes, restart Eclipse. [/LIST] And your done you should now be able to start making [B]android applications Via though eclipse[/B] :) What I wont be showing you is how to setup the android emulator as I've not set it up my self. I just use my Android phone instead. [B]Anyway on with the Tutorial:[/B] [U][B]Part 1: Setting up the project folder[/B][/U] If this is your 1st time ever starting up eclipse your going to be a bit puzzled at all the features but do not worry you wont be using most of them :p Well with any project you will 1st have to start a new project(obviously lol). The way I do it is: [LIST=1] [*]Right click on the project explore(The left panel) This should be blank for the moment. [*]Hover over > new > then click other. Printscreen: [url=http://prntscr.com/12ydjv]Screenshot by Lightshot[/url] [*]Once you clicked other a wizard will pop up asking you which type of project you would like to create. In the wizard click the android folder and choice the option Android application project. Printscreen: [url=http://prntscr.com/12ydvc]Screenshot by Lightshot[/url] [*]On the next screen it will ask you for a project/application/package name you should understand what these mean as the names say what they are :P If you don't just copy what I've got Printscreen: [url=http://prntscr.com/12yee3]Screenshot by Lightshot[/url] [*]From here on just keep clicking next until you can click finish. [*]Once you have clicked finish you will see your project folder in the project explorer to the left Printscreen:[url=http://prntscr.com/12yesm]Screenshot by Lightshot[/url] [/LIST] [B][U]Part 2: Setting up the layout[/U][/B] This is the boring part and I really don't even want to explain this as its so easy and you should be able to understand what it means just from what each line says. So I'm not going to lol :D I will just post the code and you can copy and paste but if you would like to know then ask and I would be happy to explain it to you. [LIST] [*]Anyway open up the folder called: layout [*]and open the file named: activity_main.xml Printscreen: [url=http://prntscr.com/12yg22]Screenshot by Lightshot[/url] NOTE: Your file may not have that name. Just open the only XML file in that folder. [*]Once it opens make sure you are in XML view by clicking the file_name.xml Next to the graphical layout at the bottom. Printscreen: [url=http://prntscr.com/12ygbh]Screenshot by Lightshot[/url] [*]Copy and paste this code into it: [/LIST] [CODE]<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:padding="25dp" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/etCommands" android:hint="Type A Command" android:password="true" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="100" > <Button android:text="I'm a button! Click me lol!" android:layout_weight="20" android:id="@+id/bResults" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <ToggleButton android:paddingTop="8dp" android:layout_weight="80" android:id="@+id/tbPassword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="ToggleButton" android:checked="true"/> </LinearLayout> <TextView android:text="Invalid" android:id="@+id/tvResults" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>[/CODE] If you now click on the graphical layout you will now see what it will look like on a mobile screen. Printscreen: [url=http://prntscr.com/12ygmb]Screenshot by Lightshot[/url] If yours looks like that then you have did it correctly :) Part 3: On with the java :D I will post the code with comments all the way though it saying what each line dose: [CODE]package com.example.rune_server_tut; //PACKAGE NAME..... //CLASSES THAT WE WILL BE USING import java.util.Random; import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android.text.InputType; import android.view.Gravity; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.ToggleButton; //public class means any other class can use it //MainActivity is the class name //extends Activity means we will use some methods from the activity class //implements .......... Means we will use all methods from that class //Not going to explain fully just use google for full deff public class MainActivity extends Activity implements View.OnClickListener { Button button; //Creates a new variable ToggleButton togButton; //Creates a new variable EditText input;//Creates a new variable TextView display;//Creates a new variable @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);//Sets the screen view to the activity_main.xml getXmlVaribles(); //gets the xml variables defined below togButton.setOnClickListener(this);//checks if the toggle button is clicked button.setOnClickListener(this);//checks if the button is clicked } private void getXmlVaribles() { button = (Button) findViewById(R.id.bGetResults);//gets the id of the button togButton = (ToggleButton) findViewById(R.id.tbToggle);//gets the id of the toggle button input = (EditText) findViewById(R.id.etCommands);//gets the id of the command textbox display = (TextView) findViewById(R.id.tvResults);//gets the id of the results textbox } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onClick(View v) {//Once clicked switch (v.getId()) { //If what it clicks id is = case R.id.tbToggle: //If id is the togglebutton if (togButton.isChecked()) { //if its checked input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); //change type of text to ********* } else { //otherwise do this //change text type to normal input.setInputType(InputType.TYPE_CLASS_TEXT); } break; //end statement for the togglebutton case R.id.bGetResults: //if id is the normal button String check = input.getText().toString(); //change textbox data into a string display.setText(check); if (check.contentEquals("left")) { //if text in box = left display.setGravity(Gravity.LEFT); //change text label results location to the left } else if (check.contentEquals("center")) {//if text in box = center display.setGravity(Gravity.CENTER);//change text label results location to the center } else if (check.contentEquals("right")) {//if the text in box = right display.setGravity(Gravity.RIGHT);//change text label results location to the right } else if (check.contentEquals("blue")) {//if the text in the box = blue display.setTextColor(Color.BLUE); //change text label colour to blue } else if (check.contentEquals("random")) {//if the text in the box = random Random crazy = new Random(); //Creates a new variable which is random display.setText("MADNESS :D"); //sets the text to madness :d display.setTextSize(crazy.nextInt(75));//randomly change text size display.setTextColor(Color.rgb(crazy.nextInt(265),crazy.nextInt(265),crazy.nextInt(265))); //randomly changes text color switch(crazy.nextInt(3)) { case 0://random number = 0 display.setGravity(Gravity.LEFT); //change text label location to the left break; case 1: display.setGravity(Gravity.CENTER); //change text label location to the center break; case 2: display.setGravity(Gravity.RIGHT);//change text label location to the right break; } } else {//if the textbox dose not contain any of what we have defined then : display.setText("INVALID"); //text in the label = INVALID display.setGravity(Gravity.CENTER); //Center the label text } break; } } } [/CODE] Well that's about it I would make a video and show what it exactly dose but I don't see the need for it tbh lol Can't really see anyone actually making this application. This tutorial is more for understanding some of the text methods that are available to you when you are making an Android application. [SIZE=4][COLOR="#AFEEEE"]Hope some of you learnt something this :) Any help just post and I will try to help :D[/COLOR][/SIZE]
  12. Gircat

    Short Introduction

    [CENTER]Only 8 seconds long, took me about an hour to do. Let me know what you think. :gg: [video=youtube;fSLzSdiK9yI]http://www.youtube.com/watch?v=fSLzSdiK9yI[/video][/CENTER]
  13. [CENTER][B][U]MySQL with PHP - The Introduction[/U][/B][/CENTER] This is the start of a many (or a few) tutorials for using MySQLi with PHP. My most recent projects I've been involved with I've been using a MySQL "class" that I have from an old tutorial over at TutsPlus so it's what we'll be using throughout these small tutorials/guides. [B][U]What can be done with MySQL?[/U][/B] Simply put, MySQL is a Database Management System that runs partly as a server. Almost all dynamic websites you see these days use MySQL to complete many primary tasks. RuneLocus, for an example has databases for pretty much all their features: Toplist, Server Status, Item Database, Forums and pretty much anything else that "remembers" something. MySQL works well with PHP GET and POST. For an example when you visit the page of a server on the toplist there's a lot that goes on behind the scenes. Normally you'll see the "pretty" URL's. [B][I]Example 1:[/I][/B] We'll use the Fatality614 server which at this time has the ID "277" which is unique to only that server. The pretty URL (that you'll see) is like this - [url]http://www.runelocus.com/toplist/details-277-Fatality614_CHRISTMAS_EVENT.html[/url] however we can also view this server a different way. As we, RuneLocus has made it show the action first, then the ID and then finally the name of that server. We can also view this server by specifying the action and ID like this. [url]http://www.runelocus.com/toplist/index.php?action=details&id=277[/url]. By each and every server having its own, unique ID the system that RuneLocus use can then easily use a MySQL Query that looks for something in the database. The SQL would look something like this: [CODE]SELECT * FROM `servers` WHERE `id` = 277 LIMIT 1[/CODE] This SQL query is saying to SELECT * (all data) from the table named 'servers' and where the ID is equal to 277 (Fatality614's unique ID). After running this query we can then also run others which can return an array of the all the data about id 277 such as the votes, name, status and more. [B][I]Example 2:[/I][/B] Use it with your own RSPS! A common function with MySQL in RSPS are things such as website hiscores, auto-donate or vote4cash scripts. Java is easily implemented into Java but we won't be going over that just yet. Maybe in a later tutorial? An auto-donate script can be used by storing data from a transaction (learn about the PayPal IPN) such as the item they donated for and then in-game the character can type something such as ::donate which checks the database to see if they've ordered anything and if yes, give it to their character. [B][U]I hear MySQL has lots of vulnerabilities?[/U][/B] Whoever says this generally has no idea what they're talking about. MySQL or databases in general are only as safe as you make them. This can include by stripping out tags/sanitizing variables or using a pre-made MySQL class for which we'll be using in for these tutorials. [B][U]What's this class you speak of?[/U][/B] It's a highly secure class that has been proven to myself multiple times. It can help cut back on code and best of all, you don't have to worry about SQL Injections. It's close to 300 lines so I have put it on Pastebin, which can be viewed [URL="http://pastebin.com/XWatcB4B"]here[/URL]. [B][U]OMG, it looks so confusing![/U][/B] Don't worry, you'll learn everything that you'll need to know about this class in these tutorials. It will become like a second language to you! [B][U]For the next step:[/U][/B] To be prepared for the next step, ensure that you have a webserver that has PHP and MySQL installed. I recommend using [URL="http://www.wampserver.com/en/"]Wamp.[/URL] Make the following path by creating new folders. "location_to_wamp/www/tutorials/mysql/includes". Add the MysqlDB.php class to the includes folder. [B][U]To sum it up:[/U][/B] So in this first, relatively short tutorial you've learnt what MySQL Databases are and how it can be used for website based applications and how you can implement it with your very own RSPS.
  14. Hello, my name is Ask im new here. since i joined i got some answers on my problem im hosting a rsps server btw. it called pvpscapez still starting up but loving to be here :)
  15. haze012


    Hi I'm new to RuneLocus, just introducing myself. I didn't see a board for it so I'll just do it here. I'm Matt, I'm 17, I really like punk and hardcore. That's about it.
  16. I've noticed, specifically on this site, many people have dull, boring introductions to their stories. This is an absolute NO! Your introductory sentence, and even paragraphs, need to tantalize and enchant your audience. You don't want to give them to much, but you want to give just enough to set in the hook. Remember that the first sentence will set the mood of the entire work. e.g [I]The sky above the port was the color of television, tuned to a dead channel. - William Gibson, Neuromancer (1984)[/I]