<?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0">
<channel>
	<title>RMXP Unlimited - Tutorials: RGSS Scripting Tutorials</title>
	<link>http://www.rmxpunlimited.net/forums/tutorials/category/8-rgss-scripting-tutorials/</link>
	<pubDate>Thu, 09 Sep 2010 08:31:21 +0000</pubDate>
	<ttl>1800</ttl>
	<description></description>
	<item>
		<title>Tutorial 3 : Control Flow - Part B</title>
		<link>http://www.rmxpunlimited.net/forums/tutorials/article/35-tutorial-3-control-flow-part-b/</link>
		<description><![CDATA[<span style='font-size: 17px;'><strong class='bbc'>Tutorial 3 : Control Flow - Part B</strong></span><br />
<br />
<span class='bbc_underline'><strong class='bbc'>Conditional Statements</strong></span><br />
<br />
The hero of light was sent on a mission to retrieve defeat the evil dragon king, he does that and returns to the king. The king (of happyland) asks for proof and the hero presents the 'evil dragon king's magical nose™' which makes the king happy and everyone lives happily ever after. This could be the story of your upcoming groundbreaking RPG that you plan to send to Squaresoft, they will use it part of it (because it's too complicated to be fully used) as the story for the next Final Fantasy game and you'll be very rich and famous. There's one problem though... how would the king know that the hero has the 'evil dragon king's magical nose™'? Maybe we want the king to say "You did it! You have the nose so you must have defeated the dragon" if the player has the item and "Oh, you don't have the magical nose™! Go defeat the evil dragon king before it's too late!” In English we might say "If the hero has the item, the king will say the 'you did it!' thing. Otherwise the king will say the 'go defeat the dragon' thing". Another example is saying "If I was Alex, I would be strong". Notice the pattern? If some condition is met, something will happen. Conditional statements are used to evaluate if something is true or false and do something if it's true.<br />
<br />
<strong class='bbc'>if</strong><br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>if condition
do something (true)
else
do something (false)
end </pre></div><br />
<br />
The condition is simply a statement that can be true or false, a Boolean expression in other words, it could also be a simple Boolean variable. And the first 'do something' could be a block of code that would be executed if condition is true. The other do something (after else) is another block of code that'd be executed if the condition is false. So basically, the if statement allows you to have branches in your script, different thing would happen depending on different situations. If you used rm2k/3, you might remember the conditional branch command, which is simply a form of if statements. Here's an example demonstrating how to use if:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>cow = true
if (cow == true)
p 'cow is true!'
else
p 'this will never be executed!'
end

cat = false
if (cat == true)
p 'this will never be executed!'
else
p 'cat is false'
end</pre></div><br />
<br />
Note that you can simply use if cow or if cat, there's no need for the parenthesis surrounding the condition; I just do it because I feel it'd be clearer that way. One thing you can add to the if statement is an elsif (stands for else if), elsif is followed by a condition and is executed if the preceding if condition isn't met. An example might make it clearer:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>age = 15
if (age &lt; 13)
p 'child'
elsif (age &lt; 18)
p 'teenager'
elsif (age &lt; 150)
p 'adult'
else
p 'Man, you're too old. You should be dead by now'
end</pre></div><br />
<br />
If you run that program you'd get 'teenager' as output. How does it work? First it checks if the age is less than 13, it's not so you'd expect it to go to the else statement. However, elsif is actually an else statement followed by an if, it checks for another condition if the one before it wasn't met. The elsif condition checks if age is less than 18, and prints a message (because the first if failed we know that the age will be &gt;= 13). If you change the age value to 40 instead of 15 the first elsif will fail and the second elsif condition will be evaluated. If you change age to 200 for example then all the conditions will fail and the code after the last else will be executed.<br />
The last thing you need to know about if is that you can nest ifs, like this:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>if 1 == 1
if 2 == 2
p 'Hello world!'
end
end</pre></div><br />
<br />
The inner if will be executed only if the outer one succeeds. It might look confusing if you next too ifs inside each other so don't overdo it if you don't need it. You can also nest loops the same way (as well as classes and methods, basically all blocks can be nested inside each other, I think...)<br />
<br />
<strong class='bbc'>unless</strong><br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>unless (condition)
do something (false)
else
do something (true)
end </pre></div><br />
<br />
Unless is the opposite of if. It executes the first statement if the condition is false, and the second if it is true. It's like saying "if not(condition)".<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>boolean = false
unless boolean
print 'hi'
end</pre></div><br />
<br />
As you can see, we didn't use else in this example, it's optional. You can also have if statements without else... actually, most of the time you wouldn't need an else case.<br />
<br />
<strong class='bbc'>Ternary operator</strong><br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>var = condition ? value (true) : value (false)</pre></div><br />
<br />
There's a shortened form of the if statement, the ternary operator (the ?) checks if condition is true, if it is the first value (left of will be returned and stored in var, otherwise it'd store the second value (right of the ":") in var. In other words, the value of var will be value (true) if condition is true, and value (false) if it is false. <br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>monkey = true
my_var = monkey ? 1 : 2
p my_var # 1</pre></div><br />
<br />
<strong class='bbc'>case</strong><br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>case var_name
when val1
do something
when val2
do something
when val3
do something
when val4
do something
else
do something
end </pre></div><br />
<br />
<br />
	<br />
Tutorial 3 : Control Flow - Part B<br />
<br />
Conditional Statements<br />
The hero of light was sent on a mission to retrieve defeat the evil dragon king, he does that and returns to the king. The king (of happyland) asks for proof and the hero presents the 'evil dragon king's magical nose™' which makes the king happy and everyone lives happily ever after. This could be the story of your upcoming groundbreaking RPG that you plan to send to Squaresoft, they will use it part of it (because it's too complicated to be fully used) as the story for the next Final Fantasy game and you'll be very rich and famous. There's one problem though... how would the king know that the hero has the 'evil dragon king's magical nose™'? Maybe we want the king to say "You did it! You have the nose so you must have defeated the dragon" if the player has the item and "Oh, you don't have the magical nose™! Go defeat the evil dragon king before it's too late!” In English we might say "If the hero has the item, the king will say the 'you did it!' thing. Otherwise the king will say the 'go defeat the dragon' thing". Another example is saying "If I was Alex, I would be strong". Notice the pattern? If some condition is met, something will happen. Conditional statements are used to evaluate if something is true or false and do something if it's true.<br />
<br />
<strong class='bbc'>if</strong><br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>
if condition
do something (true)
else
do something (false)
end</pre></div><br />
<br />
<br />
The condition is simply a statement that can be true or false, a Boolean expression in other words, it could also be a simple Boolean variable. And the first 'do something' could be a block of code that would be executed if condition is true. The other do something (after else) is another block of code that'd be executed if the condition is false. So basically, the if statement allows you to have branches in your script, different thing would happen depending on different situations. If you used rm2k/3, you might remember the conditional branch command, which is simply a form of if statements. Here's an example demonstrating how to use if:<br />
<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>cow = true
if (cow == true)
p 'cow is true!'
else
p 'this will never be executed!'
end

cat = false
if (cat == true)
p 'this will never be executed!'
else
p 'cat is false'
end</pre></div><br />
<br />
<br />
Note that you can simply use if cow or if cat, there's no need for the parenthesis surrounding the condition; I just do it because I feel it'd be clearer that way. One thing you can add to the if statement is an elsif (stands for else if), elsif is followed by a condition and is executed if the preceding if condition isn't met. An example might make it clearer:<br />
<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>age = 15
if (age &lt; 13)
p 'child'
elsif (age &lt; 18)
p 'teenager'
elsif (age &lt; 150)
p 'adult'
else
p 'Man, you're too old. You should be dead by now'
end</pre></div><br />
<br />
<br />
If you run that program you'd get 'teenager' as output. How does it work? First it checks if the age is less than 13, it's not so you'd expect it to go to the else statement. However, elsif is actually an else statement followed by an if, it checks for another condition if the one before it wasn't met. The elsif condition checks if age is less than 18, and prints a message (because the first if failed we know that the age will be &gt;= 13). If you change the age value to 40 instead of 15 the first elsif will fail and the second elsif condition will be evaluated. If you change age to 200 for example then all the conditions will fail and the code after the last else will be executed.<br />
The last thing you need to know about if is that you can nest ifs, like this:<br />
<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>if 1 == 1
if 2 == 2
p 'Hello world!'
end
end</pre></div><br />
<br />
<br />
The inner if will be executed only if the outer one succeeds. It might look confusing if you next too ifs inside each other so don't overdo it if you don't need it. You can also nest loops the same way (as well as classes and methods, basically all blocks can be nested inside each other, I think...)<br />
<br />
<strong class='bbc'>unless</strong><br />
<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>unless (condition)
do something (false)
else
do something (true)
end</pre></div><br />
<br />
<br />
Unless is the opposite of if. It executes the first statement if the condition is false, and the second if it is true. It's like saying "if not(condition)".<br />
<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>boolean = false
unless boolean
print 'hi'
end</pre></div><br />
<br />
<br />
As you can see, we didn't use else in this example, it's optional. You can also have if statements without else... actually, most of the time you wouldn't need an else case.<br />
<br />
<strong class='bbc'>Ternary operator</strong><br />
<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>var = condition ? value (true) : value (false)</pre></div><br />
<br />
<br />
There's a shortened form of the if statement, the ternary operator (the ?) checks if condition is true, if it is the first value (left of will be returned and stored in var, otherwise it'd store the second value (right of the ":") in var. In other words, the value of var will be value (true) if condition is true, and value (false) if it is false.<br />
<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>monkey = true
my_var = monkey ? 1 : 2
p my_var # 1</pre></div><br />
<br />
<br />
<strong class='bbc'>case</strong><br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>case var_name
when val1
do something
when val2
do something
when val3
do something
when val4
do something
else
do something
end</pre></div><br />
<br />
<br />
The case statements compares the expression following it (var_name) with each expression after a when (val1, val2, val3, val4), it executes the code (do something) following the matched when and if no when is matched the code after else (which is optional) will be executed. You can have as many whens as you like and you can think of the case statement as a long list of if...elsif, but the only condition we check is equality between the expression after case and the other expressions after the whens. Here's an example:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>number = 1
case number
when 0
p 'The number is zero.'
when 1
p 'The number is one.'
when 2
p 'the number is two.'
Else
p 'The number isn't zero, one or two.'
end</pre></div><br />
<br />
<span class='bbc_underline'><strong class='bbc'>Summary</strong></span><br />
<br />
- Conditional statements check if a condition (Boolean expression) is true or false, then executes some code depending on the result.<br />
- If and unless are conditional expressions, you can also add an else or an elsif (else if) to them<br />
- The case statement compares one expression with many other expressions.]]></description>
		<pubDate>Wed, 14 Apr 2010 20:37:03 +0000</pubDate>
		<guid isPermaLink="false">35</guid>
	</item>
	<item>
		<title>Tutorial 3 : Control Flow - Part A</title>
		<link>http://www.rmxpunlimited.net/forums/tutorials/article/34-tutorial-3-control-flow-part-a/</link>
		<description><![CDATA[<span style='font-size: 17px;'><strong class='bbc'>Tutorial 3 : Control Flow - Part A</strong></span><br />
<br />
<span class='bbc_underline'><strong class='bbc'>Introduction</strong></span><br />
<br />
Our little variable and print programs were executed line by line; they weren't interactive and just displayed some text on the screen. Real programs aren't like that, they interact with users and other things to produce the desired output. Ruby (and all high level languages) introduces some statements (commands) that we can use to add interactivity to our scripts, mainly it introduces conditional statements and loops. A conditional statement (or expression) basically checks if a condition is met. If it is met, then some commands will be executed, otherwise some other commands might be executed,. As for loops, they allow you to execute a block of code over and over until a condition is met. Loops and conditional statements are essential in programming, if you don't learn them then you'll probably stay a worthless noob till the end of time! <img src='http://www.rmxpunlimited.net/forums/public/style_emoticons/default/wink.gif' class='bbc_emoticon' alt=';)' /><br />
<br />
<span class='bbc_underline'><strong class='bbc'>Boolean Expressions</strong></span><br />
<br />
A Boolean value is a value that can either be true or false. Think of a switch that can be either on or off, or a path that only goes left and right; there's no gray about Booleans, everything is black and white. You might be asked: "is u alex???", thre are two valid answers for that question, either "lol yes im alex!!!", or "no im not r u???". So if we had a Boolean variable called is_u_alex?, (variables can't have spaces, so we use underscores) the value of the variable could be true if you are Alex and false if you aren't. Makes no sense, I know. Let's try something more simple, the mathematical statement "1 is equal to 2" is false, while the statement "1 is equal to 1" is true. Here are some other statements that can be true or false:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>"3 is bigger than 2"
"98 is equal to 89"
"0.01 is smaller than 0.1"
"3 is smaller or equal to 3"</pre></div><br />
<br />
I think you know which ones are true and which ones are false, if you don't then check this statement: "RGSS for Dummies isn't equal to RGSS for Idiots". Now, in programming we can compare two values to get a Boolean value that evaluates the comparison. We use "==" to indicate equality. Remember when I talked about variable assignment and I said that the = operator means assignment and not equality? "var = 5" means assign 5 to var, while "var == 5" means that var is equal to 5. Let's just try an example:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>p 1 == 1</pre></div><br />
<br />
This will output 'true'. Basically we're asking RGSS to evaluate the statement "1 is equal to 1", just like we were evaluating statements earlier. Now, change both numbers and see the various results. "p 1 == 4" would output false, p "0.1 == 0.1" would output true, etc. You can even use strings like "cow" == "cow" or 1 == cow. It's really simple, the statement can be either true or false and RGSS evaluates it for us. Other than the equality operator "==", we can use "&gt;" for bigger than, "&lt;" for smaller than, "&gt;=" for bigger or equal to, "&lt;=" for smaller or equal to and "!=" for not equal to. These examples will help:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>p 1 &gt; 2 # false
p 5 == 5 # true
p 0 &gt;= 0 # true
p 4 &lt; 1 # false
p -19 &lt;= 0 # true
p 1 == 8 # false
p 1 + 3 == 2 + 2 # true
p 4 != 7 # true</pre></div><br />
<br />
I just stored Boolean values in Boolean variables, this should help you understand the difference between "=" and "==", you use the former to store the values on the right of the "=" in the variable on the left of it, and you use "==" to compare two values for equality. Also, note that we can directly store true or false values in variables, just like I did with my_bool3.<br />
Another thing you can do is to evaluate multiple statements at once. You can use "and", "or" and "not". You place an "and" between two statements and the new statement (statement1 and statement2) will evaluate to true if both statements are true, and to false if one or both of the statements are false. Examples:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>p 1 == 1 and "hello" == "hello" # true
p 1 &gt; 5 and 5 &gt;= 1 # false
p 9 &lt; 3 and 6 == 3 # false</pre></div><br />
<br />
You place an "or" between two statements and the new statement (statement1 or statement2) will evaluate to true if at least one of the statements is true (one is true or both are true), and to false if both statements are false. Examples:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>p 1 == 1 or "hello" == "hello" # true
p 1 &gt; 5 or 5 &gt;= 1 # true
p 9 &lt; 3 and 6 == 3 # false</pre></div><br />
<br />
Finally, place a "not" before a statement and the new statement (not statement1) will evaluate to true if the original statement (statement1) is false, and to false if the original statement is true. In other words, it returns the opposite of the original statement. "not 1 == 1" is the same as "1 != 1" or "1 is not equal to 1", which is false. Example:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>p not 1 == 1 # false
p not 4 &lt; 2 # true
p not (3 &lt;= 8) # false</pre></div><br />
<br />
In the last example, I used parenthesis around the statement, it's generally a good practice because it can make your code more readable, especially if you have many statements joined with and's or or's.<br />
There's one more thing you need to know about "and", "or" and "not"; you can abrriviate them to &&, || and !. Actually, there's a difference in precedence between the word forms and the symbol forms, but it's not really that important (at the moment). Basically, using "&&" is the same as using "and", "||" is like "or" and "!" is like "not". Why do we use two &s and two |s instead of one? Well, both & and | have different meanings in ruby so remember not to confuse them with && and ||. I've rewritten some of the previous and-or-not example with the new symbols:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>p 1 == 1 && "hello" == "hello" # true
p 1 &gt; 5 || 5 &gt;= 1 # true
p !(4 &lt; 2) # true</pre></div><br />
<br />
The last example is interesting, "not 4 &lt; 2" works, but "! 4 &lt; 2" doesn't. ! has higher precedence than "&lt;" and than "not". So RGSS reads "! 4 &lt; 2" as "the opposite of true is less than 2", wait... the opposite of true? Well, you see... every value in RGSS is true expect for the values false and nil, so the value 4 on its own is true. You don't understand? Never mind then! Just forget all about this precedence thing for now, but remember to always (most of the time actually) use parenthesis around statements when using ! instead of not.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Important Note</strong></span><br />
<br />
= is NOT the same as ==, I know I mentioned that already but this is one common mistake in programming. Even professionals working for Microsoft might fell for it and use = instead of ==. Always remember that = is only used to assign values, and that == is used to test for equality of two values. I know you'll do this mistake sooner or later (I did, a lot!), but when something isn't working in your program, it's a good idea to check the comparisons to see if you used = instead of ==.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Summary</strong></span><br />
<br />
- A Boolean expression is an expression that evaluates to either true or false.<br />
- Comparison operators such as (&gt;, ==, &lt;) are used to compare two values and produce a Boolean value.<br />
- More complex Boolean expressions can be formed by combining two or more expressions with && (and) or ||. (or)]]></description>
		<pubDate>Wed, 14 Apr 2010 20:27:55 +0000</pubDate>
		<guid isPermaLink="false">34</guid>
	</item>
	<item>
		<title>Tutorial 2 : Variables</title>
		<link>http://www.rmxpunlimited.net/forums/tutorials/article/33-tutorial-2-variables/</link>
		<description><![CDATA[<span style='font-size: 17px;'><strong class='bbc'>Tutorial 2 : Variables</strong></span><br />
<br />
<span class='bbc_underline'><strong class='bbc'>Introduction</strong></span><br />
<br />
Forget all about the first tutorial (the basics), I only wrote it to give you a general idea about scripting/programming. You need to understand the example from the last tutorial though, you need to know that ( print stuff ) displays stuff on the screen (in RMXP's case, it displays a message box) and that ( # stuff ) is a comment ignored by the compiler, it's just there to remind you of stuff or comment stuff out. Enough with stuff, let's get to some fun stuff. Variables are storage places for your stuff, you stuff your stuff in variables and then use them for other stuff. Did I mention that the Finnish word for stuff is Juttuja? And no, I'm not Finnish but I thought it was some interesting stuff.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Values</strong></span><br />
<br />
There are cases (many of them!) where you'd need to store some value in the computer's memory. But before discussing how or why would we do such a thing, let's try to understand what a value is. Most of the time, the value is a number. It could be someone's age, an enemy's HP, an ID number, a random number, number of saves, etc. The values of those 'variables' (they vary from person to person, enemy to another, game to game, etc.) could be 34 for age, 9999 for Enemy HP, 1921 for ID, 0.3563 for random numbers, 3 for saves. So basically, a numeric value is a number! Isn't that awesome? Now, a number could be an integer or a float. An integer has no fraction, like: 1, 34, -57, 9834, 0, -346. Integers are useful because you don't need fractions often, you can't have 3.5 living cows for example. Most of the time you'll be dealing with integers. (Actually, the variables used in RPG Maker XP/2K/3's point scripting are always integers) Sometimes you might want to use fractions, if you and your friend had one apple that you wanted to share, each of you would get half an apple. If we're using integers, you can't divide the apple so one would get the whole thing and the other won't get anything. We need to use fractions so that each of you get 0.5 (1/2) apple, and we use floats to represent such values. I can't think of many situations where you'd need to use floats in programming, they're useful in programs where you need to get scary things like angles, circles, flying cows and other stuff that gets you an F in school.<br />
A special case of integer values are Booleans, values that can be either on or off, true or false. They are like RPG Maker XP/2K/3 switches, you either opened the chest or didn't, talked to the king or didn't, killed the cow or didn't. I said they're a special case of integer values while they are not, but thinking of them as the integers 1 and 0 could be useful. 0 could be off (false) and 1 could be on (true), but Boolean values aren't integers and you can't add two Booleans for example. Basically, the value of a Boolean is either true or false. You can either turn a light on (true) or off (false), and your nose could be green (true) or red (false), etc. The real use of Booleans is to evaluate expressions, which we'd discuss in the 3rd tutorial. (next one)<br />
The final type of values that we are going to discuss here is strings. A string is basically a string (array) of characters, but that doesn't really tell anything, does it? Basically, a string is a sentence, or maybe a group of them, or maybe just some random words. Just think of strings as text, you might need to store the someone's name, some messages, etc. Strings in Ruby (RGSS) are placed within quotation marks (either ' ' or " "), some examples of strings would be: 'Alex RTPson', "Hello!", 'I had a big monkey and it was funny', "sretpok jifrjio uhure", 'abc'. It is recommended that you use single quotes ( ' ' ) whenever possible, I'd rather use double quotes myself (because most programming languages do) but using in Ruby isn't very efficient because the compiler (RMXP in this case) will need to check more things and that might slow things down. Back to strings, you store text as string values, you can also add some strings together, for example 'I like ' + 'cows'. Enough said.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Advanced Note</strong></span><br />
<br />
I'll often use the term 'store' to refer to how variables and values (objects) interact. In Ruby's case, the variable doesn't really store the value but rather refer to it. The value is stored in the memory and a variable or more refer to it. A variable is a reference to some value and two variables might refer to the same value and changing one variable's value also changes it in the other. However, I think using 'store' might make variables easier to understand for beginners, but that's just me.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Variables</strong></span><br />
<br />
Now, sometimes we might need to store a value for later use. We use variables to do that. A variable is basically a name (identifier) that represents a value stored in memory. For example, my_age could be a variable that stores your age. You can later use variables as you use their values; for instance, you can do arithmetic operation on numeric variables. In Ruby (RGSS) variables are all objects, but you don't need to worry about that for now. Keep in mind that variable names (identifiers) can't start with a capital letter for some reason (except in certain cases), here are some valid names: age, enemyHP, id_number, RaNdOm, num_of_saves. Variable names are also case sensitive, password and passworD aren't the same thing. Here's a little example of variables:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>number1 = 9
number2 = 1
number3 = number1 + number2
print number3 # 10</pre></div><br />
<br />
Basically, we declare two variables (number1 and number2) with values 9 and 1. We add the two variables and store the sum in a third variable (number3). Finally, we display the value of the third variable (number3). You can test it yourself, make a new event, go to the third page of the command list and paste the example. When you activate the event you should get a message box with the number 10. (another way to do it is adding a new section to the script editor and pasting that, you'll see the message box when you start the game) As you can see, variables act just like their values. The same example could be written as ( print 9 + 1 ). Also notice the comment ( # 10), it's on the same line as the print command. You can always do that, as long as it's after the code. In this series of tutorials, I'll always place a comment with the display value after the print command (function), there are times when you don't know the output value though... actually, you use variables because you don't! Our example is really stupid actually, why would we need to store these values in variables if we can use them directly? Why use variables?<br />
<br />
<span class='bbc_underline'><strong class='bbc'>The Need for Variables</strong></span><br />
<br />
There are cases where you don't really know the values you're dealing with. Maybe you wrote a program that asks the user for two numbers and then displays the sum. The user might type any two numbers, you can't just guess the numbers or anything. So, if we store the number (without knowing what the number is) in a variable, we can operate on it with ease. Another example is the stats of the hero in some game, you can't always know what the HP, level, strength, etc of the hero is, and you might not be able to know how many potions does the party hold. Why not? Because the game stats vary from time to time and from a person to another; we can just store the hero's HP in a variable and then use it as we please. A final example of the uses of variables would be constant values that you change, sometimes you know the value of something (someone's age for example) and you use that value heavily in your code. But what if the value changed? (that someone's birthday came and they're one year older) You'll have to change all the occurrences of that value in your code. Note that the value is constant (it doesn't change during the execution of your program) but it could change outside your program, so you just use a variable and change it's initial value whenever you like. As we can see from the previous examples, variables are used for values that 'vary'. In other words, variables are used to store 'variable' (changing) data. It might not be very clear at the moment, but you'll see how important they are as you learn more.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Assignment</strong></span><br />
<br />
Assignment refers to assigning a value to a variable, i.e saying that this variable stores this value. We use the equal sign for assignment, it might look mathematically incorrect as in the following example:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>my_var = my_var + 7</pre></div><br />
<br />
It doesn't mean that my_var is equal to my_var + 7, it means that we calculate the stuff on the right side of the equal sign and then store it in the variable on the left side. So, think of the equal sign as an assignment (assign some value to some variable) rather than an equality. The variable is declared (the program knows about it) when you assign some value to it, here are some examples of assignment:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>cow = "Hello this is some random text"
magic = 7 + 13 - 9 * 100 / (1 - 3)
teh_var = true
heroHP = 9999</pre></div><br />
<br />
And some different ways to assign things:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>cow = magic = teh_var = 3
cow, magic = 1, 2</pre></div><br />
<br />
The first line is like saying "store 3 in cow, magic and teh_var". The second line is like saying "store 1 in cow, store 2 in magic".<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Variable Fun</strong></span><br />
<br />
Now, let's have some examples of variables. Each example is basically a comment describing how things work, some variable operations and then a print statement. I'll use ( p stuff ) instead of ( print stuff ) from now on (because I'm lazy), both of them are the same.<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre># Just some mathematics.
# The * sign is used to indicate multiplication (number x number),
# the / sign indicates division.
a = 2
b = 4
p a + b # 6
p a - b # -2
p b - a # 2
p a * b # 8
p b / a # 2

# You can join two strings together by using the plus (+) sign
text1 = 'mon'
text2 = 'key'
p text1 + text2 # "monkey"

# We store a 'lol' in v1, we store v1's value in v2, we store "!!!" in v3
# Then we print v1 + ' ' (space) + v2 + v3
v1 = 'lol'
v2 = v1
v3 = '!!!'
p v1 + ' ' + v2 + v3 # "lol lol!!!"

# One of the ways to add some numeric value to a string is embedding it
# using #{}, you just put #{number or variable} inside the string.
# When you do that, you must use double quotes (" ") for the string.
# Double quotes lets the compiler check the string to find any #{}s
# otherwise (single quotes), no checking is done and no conversion either.
num = 1337
p "The number is #{num}" # "The number is 1337"

# Another way is using number.to_s, like this:
num = 1337
p 'The number is ' + num.to_s # "The number is 1337"

# You can also convert strings to numbers.
# You see, 3 and '3' aren't the same thing, you
# can't do '3' + 1 because '3' is a string.
# To change it into an integer use string.to_i
var = '3'
p var.to_i + 1 # 4

# Just a note, you don't need to use variables
# to use .to_s and .to_i
p 'The number is ' + 1337.to_s # "The number is 1337"
p '3'.to_i + 1 # 4</pre></div><br />
<br />
<span class='bbc_underline'><strong class='bbc'>Conclusion</strong></span><br />
<br />
Variables allow us to store values that vary, although all the examples shown didn't really show useful variables. Understanding variables is essential; you won't go far without using them. I tried to make this tutorial very easy to understand but I might've failed in doing that. Don't worry though, you can find tons of variable tutorials on Google or something, and you can always read this boring tutorial again. The next tutorial will be about flow control statements such as loops and the if statement. Later~<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Summary</strong></span><br />
<br />
- There are cases when you'll need to store some values in memory. The values could be either numeric, strings or Booleans. Numeric values can be either integers (no fractions) or floats (fraction). Strings must be enclosed in quotes (single or double). Boolean values can be either true or false.<br />
- Variables are basically identifiers presenting values stored in memory. You use variables just like you use their values. The names (identifiers) of variables must start with a small letter (most of the time) and are case sensitive.<br />
- We use variables to store values that might change. We might not know the value of something at a given time but we still need to use that value, so we use variables..<br />
- We assign values to variables by using the equal sign, which assigns the values at the right side of the sign to the variable(s) at the left side ( var = value ). Some other ways to assign variables is ( var1 = var2 = var3 = value ) and ( var1, var2 = value1, value2 )<br />
- We can do mathematical operations on variables, join strings together, embed numbers in strings and convert variables from a type to another.]]></description>
		<pubDate>Wed, 14 Apr 2010 14:09:04 +0000</pubDate>
		<guid isPermaLink="false">33</guid>
	</item>
	<item>
		<title><![CDATA[[Bart] Tutorial 1 : The Basics]]></title>
		<link>http://www.rmxpunlimited.net/forums/tutorials/article/32-bart-tutorial-1-the-basics/</link>
		<description><![CDATA[<span style='font-size: 21px;'><strong class='bbc'>Tutorial 1 : The Basics</strong></span><br />
<br />
<span class='bbc_underline'><strong class='bbc'>Into the World of Scripting</strong></span><br />
<br />
Greetings, brave dummy! I'm RPG and I'll try my best to teach you Ruby Game Scripting Language (RGSS). This series of tutorials is aimed at people who have no programming experience, but such experience can also help you.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>About RGSS</strong></span><br />
<br />
RGSS (Ruby Game Scripting Language) is -as the name implies- a scripting language based on Ruby. Ruby is an object-oriented programming language created by Yukihiro Matsumoto; you can find more information at Ruby's official site (<a href='http://www.ruby-lang.org' class='bbc_url' title='External link' rel='nofollow external'>http://www.ruby-lang.org</a>). I think RGSS is easy to learn and use, although it could look weird at times. With RGSS, you can have great control over your RMXP game; you can modify almost everything, and you can add almost everything. Basically the limit is your ability and knowledge.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>About Coding</strong></span><br />
<br />
Computers are dumb, they don't really think like you (assuming you do~). The computer follows basic instructions to perform operations, you need to give it some commands and it'd execute them. For example, if you want to know the sum of 1 and 2 you'd ask the computer something like "Please calculate the sum of 1 and 2". But then, you don't need to be polite to the computer and it doesn't make a difference to it wither or not you use 'the' and 'of'. So we end with "calculate sum 1 and 2". Well, why use too many words anyways? We can just do "calculate 1 + 2". Wait, why add calculate? What else can it do with 1 + 2? Make a song about a 1, a plus sign and a 2? So, we end up with "1 + 2", simple, isn't it?<br />
The point of the whole thing is that the instructions we give to the computers are written in some sort of simplified English (talking about high level languages here). Programming languages, like natural ones, have a set of words and rules. However, there aren't as much words or rules in programming languages, only the 'useful' things are there. Learning the important words and rules (or grammar, syntax, whatever) doesn't mean you've learned the language. Let's say that I know all about English grammar and that I've know every word the dictionary, can I got to a person and say "Your tea is good for egg production under the light of the new super monkey nose."? Well, I can. But it doesn't really make much sense, it's not a logical thing to say. Same with computers, you don't just give it stupid instructions just because they are valid. Things should make sense or else you might get some nasty errors.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Blocks</strong></span><br />
<br />
You can give the computer only one command, but you'd most likely give it more. For example (not real code):<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>Ask the user for the password
Wait for the user to type in the password
If the password the user typed is correct, play some victory music
If the password is wrong, punch the user in the face
Duplicate the program and spread copies all over the user computer
Start sending e-mails with copies of the program
Become one of the most famous viruses</pre></div><br />
<br />
Uh, maybe I went a bit too far... but I hope you get the basic idea. The group of instruction we give could form a block of code, and although it doesn't sound that important, it is. Long ago programs were just lines of code with little organization; everything was in one big block that is executed line by line from top to bottom. If for some reason you wanted to go up again, you'd ask the computer to go to that line. The whole thing was very messy and produced 'spaghetti code' (no, not code written in Italian. Just messy unorganized bad code). It looked like this:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>Display a message "Welcome to the super program 007!"
Ask user to input a number
Ask user to input another number
Calculate the sum of the numbers and display it
Display a message "Do you want to exit? (Y)es / (N)o"
If the user types 'Y', exit the program
If the user types 'N', go to line 2 (ask for input for another two numbers)</pre></div><br />
<br />
Basically every time you choose no, the program will be executed again. What's wrong about that? It's not really obvious in that little example. But in big complicated programs, it'd end up like a maze with lots of ‘go to’s and jumps from line to line. When the code is too long, it'd be hard for you to follow and understand it, which makes it hard to improve it or fix bugs.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Functions</strong></span><br />
<br />
Well, worry not! Functions are there to fix this. Sometimes functions could be called Subroutines or Methods (Ruby calls them that, but it's not very accurate). Basically a function is a block of related code that you 'call'. You create a function, have all your code inside it and then call it as much as you want. There is no need to re-write stuff or to jump around like a monkey. Functions organize your programs and makes thing simpler. Well, here's an example:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>Function name: Sum
Function takes two values and calls them num1 and num2
&gt;&gt;Function Starts Here:&lt;&lt;
Calculate the sum of num1 and num2 and display it
&gt;&gt;Function Ends Here&lt;&lt;
Call the function Sum with values 1 and 2
Call the function Sum with values 10 and 5
Call the function Sum with values 29 and 7</pre></div><br />
<br />
Running this program (it's not real btw) would display 3, 15 and 36. Instead of writing the calculate code every time, we just call the function. This can be very useful, let's say you're making a game and made a function to draw things, another to check input and another for calculations, you can then do:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>Call Draw
Call Input Check
Call Calculations
Go to line 1 (Draw)</pre></div><br />
<br />
Whoa! You've got a game! (Not really) This might make little sense, but just know that functions are blocks of related code that could be called. I'll explain them in more details later. Also, keep in mind that Functions are called Methods in RGSS, I used the world 'Function' here because that's the commonly used term in programming. I'll use methods when talking about RGSS though, just remember that they are the same thing.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Variables</strong></span><br />
<br />
Wait, why am I discussing variables after functions? Shouldn't they be discussed first? I don't know, I think that code-&gt;block-&gt;function flows well, but I could be wrong~<br />
Variables are places to store data on your computer. Think of a variable as a locker that you put something in, and then you can refer to the the thing by saying the locker's number. So you could say "Please give me the monkey in locker 5" or just "5". Not a very good example... remember how the sum function in the previous example accepted two values (num1 and num2) and calculated their sum? You see, num1 and num2 could be anything, they could be 1 and 2, 10 or 5, 29 and 7. We just store the two numbers in two variables called num1 and num2 and they'd act as if they were the actual numbers. Still don't get it? You know how students could have ID numbers in school? My ID number is 1921 and when I'm having an exam they ask me to write my ID number on the paper. They don't care about my name because they can just use my ID number to get everything they need to know about me, so the ID and me are the same. A variable is like an ID number (it doesn't need to be a number, could have letters like 'FOA' for my name's initials), it represents a certain value just as an ID number represent a student. Makes no sense? Too bad you're just dumb <img src='http://www.rmxpunlimited.net/forums/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' /><br />
Nah, just kidding, it'll become easier to understand when we have real code examples.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Arrays</strong></span><br />
<br />
Let's say that in some city they have many people with the name John Smith. People often get confused and if you yell "John Smith!!" in the street then tons of people would look at you. Now that's a big problem, for example the city mayor (Mr. John Smith) was arrested because he was a suspect of some crime (Murder of John Smith) but it turned out to be a mistake because the real murderer was another John Smith. So, the mayor was angry and decided to do something. He decided that all John Smithes should have numbers. The mayor would be John Smith [1], another person would be John Smith [2],.... and so on until you have John Smith [99999]. The people in the city lived happily ever after and having too many Johns wasn't a problem anymore. In programming, there are situations where you'd have many variables with similar functions or names. You might need variables to hold all the skills your hero has. But if they had 100 skills, it'd be annoying to create 100 variables and manage them. So, we use arrays, one variable that holds many values. They allow you to easily access values by referring to them by numbers (called index).<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Control Flow</strong></span><br />
<br />
Your program would often need to examine things, take decisions and interact with the user, it might also need to do the same thing many times. Now, you know the Show Choices (or whatever it's called) command in rm2k/3/xp? You provide it with some commands to choose from and things to do based on the chosen command. When the user plays the game, they'd see the choices, pick one and different things would happen. Like:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>Message Box "Hello I sell cats, are you interested?"
Choices:
- Yes
Open the shop menu
- No
Message Box "Don't want to buy anything? Too bad!"</pre></div><br />
<br />
Now without having such a choice, the user would be forced to view the shop menu even if they don't want to buy anything. Another example is the conditional branch (if command) in RPG Maker, you can use it to check if the player has a potion, do something if they do, do something else if they don't. In programming languages you'd often control the flow of code. In one of our examples, we checked if the password is correct or not. In another program we'd loop to display an annoying message 100 times without typing 100 lines of code. More about that in some future tutorial.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Objects</strong></span><br />
<br />
Our world is object-oriented. It is composed of entities that have special properties and can interact with each other. A human is an object that has a name, an age, an occupation. This human can walk, think, eat, get killed, and do other things. An apple is an object; it has properties such as origin, weight, color, percent of water in it and a size. The apple can also be eaten, can fall off a tree, can be thrown in the sky, etc. A human can interact with an apple by eating it, throwing it, holding it, etc. Think of things this way, and you will have no problem with object-oriented concepts.<br />
Computer programs tend to simulate the real world, they draw things like humans do, they calculate things, print things or even simulate things. Games try to simulate the real world all the time, a character in the game has data such as it's sprite file name, it's size on screen, it's position and more. It can also do things like jumping, swimming, killing monsters, etc. The character can interact with the map and with other NPCs and enemies. Do you see the connection? If programs were written in a way that actually simulates the real world we can have more effective programs, and this is where object-oriented languages came from. In programming, an object is an instance of a class, a class is a (user defined) data type. Each object has special properties (variables that describe that object) and methods to operate on these properties (functions).<br />
So basically, an object combines both data (variables) and functions (methods). Objects can inherit other objects (A human is an animal, an apple is a fruit) and can interact with each other. In RGSS, almost everything is an object. You will often create classes and use existing ones, just take a look at the script editor. Notice how each page starts with the word 'class'?<br />
Don't worry if you don't understand this, I'll explain it all in more details later. You might like to read it again then.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>First Program</strong></span><br />
<br />
Well, tired of all that explaining? Want to try something yourself? Open RMXP, add an event and choose some picture for it, double click the command list thing (the big white box), go to the last command page (3?) and choose the last option, 'script'. Now in the text box type the following:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre># I'm a useless comment
print 'Hello World!'</pre></div><br />
<br />
<span class='bbc_underline'><strong class='bbc'>Conclusion</strong></span><br />
<br />
Well, that's all for today. The aim of this tutorial was to briefly introduce you to different programming concepts. You aren't expected to understand everything but just have a basic idea about how things work, I recommend reading the summary. In future tutorials I'll discuss everything we talked about in details and with real code examples, until then you can try playing around with the print function and displaying different things like numbers (you don't add quotes around numbers). The next tutorial will teach you more about variables, see you later~<br />
<br />
<span class='bbc_underline'><strong class='bbc'>Summary</strong></span><br />
<br />
- Computers are dumb, you need to give them detailed instructions. A programming language is basically a set of instructions with rules and keywords.<br />
- Blocks are used to group related instructions.<br />
- A function is a block that you can call.<br />
- Variables store some values for later use.<br />
- An array is a variable that has many values.<br />
- We can control the flow of programs using things like if statements and loops.<br />
- Objects are entities that has some data (variables) and methods to operate on the data (functions).<br />
- We use ( # stuff ) to add comments.<br />
- The print function displays numbers or text (or something else) on the screen. (or a message box)]]></description>
		<pubDate>Wed, 14 Apr 2010 14:03:46 +0000</pubDate>
		<guid isPermaLink="false">32</guid>
	</item>
	<item>
		<title><![CDATA[LegacyX's Ruby/RGSS Tutorial Series - Part 1: Ruby Basics]]></title>
		<link>http://www.rmxpunlimited.net/forums/tutorials/article/30-legacyxs-rubyrgss-tutorial-series-part-1-ruby-basics/</link>
		<description><![CDATA[<span class='bbc_center'><span style='font-size: 17px;'><strong class='bbc'>LegacyX's Ruby/RGSS Tutorials  Part 1: Ruby Basics</strong></span></span><br />
<br />
<strong class='bbc'>Author:</strong> LegacyX<br />
<strong class='bbc'>Date Created:</strong> 10-01-2010<br />
<strong class='bbc'>Date Revisted: </strong>13-01-2010<br />
<br />
<em class='bbc'>If you want to try any Ruby code out whilst you go through my tutorial, i recommend that you'd go to <a href='http://tryruby.org/' class='bbc_url' title='External link' rel='nofollow external'>http://tryruby.org/</a> and work from within your browser. This is also a good way to retain the information you have learnt form this tutorial. Typing it out 1 time isnt good enought, the best way to remeber is to type it out at least 16 times. This is how i learnt and remebered Ruby. just though i would give you a personal piece of advice.<br />
</em><br />
<strong class='bbc'>1.1 Information</strong><br />
<br />
So what is Ruby? Well, Ruby is an interpreted, object-oriented scripting language. And is the backbone of RGSS (Ruby Game Scripting System)that is used in RPG Maker XP.<br />
<br />
Ruby goes to great lengths to be a purely object oriented language. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Every object has a class and every class has one<br />
superclass. At the root of the class hiearchy is the class Object, from which all other classes inherit. Every class has a set of methods which can be called on objects of that class. Methods are always called on an object there are no œclass methods as there are in many other languages (though Ruby does a great job of faking them). Every object has a set of instance variables which hold the state of the object. Instance variables are created and accessed from within methods called on the object. Instance variables are completely private to an object. No other object can see them, not even other objects of the same class, or the class itself. All communication between Ruby objects happens through methods.<br />
<br />
In addition to classes, Ruby has modules. A module has methods, just like a class, but it has no instances. Instead, a module can be included, or mixed in, to a class, which adds the methods of that module to the class. This is very<br />
much like inheritance but far more flexible because a class can include many different modules. By building individual features into separate modules, functionality can be combined in elaborate ways and code easily reused.<br />
Mix-ins help keep Ruby code free of complicated and restrictive class hiearchies.<br />
<br />
Variables in Ruby are dynamically typed, which means that any variable can hold any type of object. When you call a method on an object, Ruby looks up the method by name alone  it doesnt care about the type of the object. This is called duck typing and it lets you make classes that can pretend to be other classes, just by implementing the same methods.<br />
<br />
So this means that having some knowlage of Ruby will help you understand RGSS a lot easier. So, well get right into learning the basics of Ruby.<br />
<br />
<strong class='bbc'>1.2 Basics Of Ruby</strong><br />
<br />
<span class='bbc_underline'>Comments</span><br />
<br />
Comments are an important aspect in Programming, it doesnt matter what language it is, commenting is important because it allows you to revisit your code and understand what it all does (if you commented it well) There are two different types of comments, line and Block. some examples are bellow.<br />
<br />
Like Perl, Bash, and C Shell, Ruby uses the hash symbol (also called Pound Sign, number sign, Square, or octothorpe) for comments. Everything from the hash to the end of the line is ignored when the program is run by Ruby. Here are some sample comments.<br />
<br />
<span class='bbc_underline'>Line Comments</span><br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre># My first Comment
line_of_code</pre></div><br />
<br />
You can append a comment to the end of a line of code, as well. Everything before the hash is treated as normal Ruby code.<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>line_of_code # a line_of_code</pre></div><br />
<br />
<span class='bbc_underline'>Block Comments</span><br />
<br />
You can also comment several lines at a time:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>=begin
my first
block comment
=end

line_of_code</pre></div><br />
<br />
<br />
<br />
Although block comments can start on the same line as =begin, the =end must have its own line. You cannot insert block comments in the middle of a line of code as you can in C, C++, and Java, although you can have non-comment code on the same line as the =end.<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>=begin my first
block comment
=end line_of_code</pre></div><br />
<br />
<span class='bbc_underline'>Reserved Words</span><br />
<br />
Ruby has a set of Reserved rules, just like many other programming languages, these cannot be changed or used for something else like a<br />
variable. Most of these words are listed bellow.<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>alias   and	 BEGIN   begin   break   case	class   def	 defined?
do	  else	elsif   END	 end	 ensure  false   for	 if
in	  module  next	nil	 not	 or	  redo	rescue  retry
return  self	super   then	true	undef   unless  until   when
while   yield</pre></div><br />
<br />
<span class='bbc_underline'>Classes and objects</span><br />
<br />
Classes and objects are obviously central to Ruby, but at first sight they can seem a little confusing. There seem to be a lot of concepts: classes, objects, class objects, instance methods, class methods, and singleton classes. In reality, however, Ruby has just a single underlying class and object structure, which well discuss in this chapter. In fact, the basic model is so simple, we can describe it in a single paragraph.<br />
<br />
A Ruby object has three components these are a set of flags, some instance variables, and an associated class. A Ruby class is an object of Class, which contains all the object things plus a list of methods and a reference to a superclass (which is itself another class).<br />
<br />
All method calls in Ruby nominate a receiver (which is by default self, the current object). Ruby finds the method to invoke by looking at the list of methods in the receivers class. If it doesnt find the method there, it looks in the superclass, and then in the superclasss superclass, and so on. If the method cannot be found in the receivers class or any of its ancestors, Ruby invokes the method method_missing on the original receiver.<br />
<br />
<span class='bbc_underline'>Creating Classes</span><br />
<br />
Classes represent a type of an object, such as a book, a whale, a grape, or chocolate. Everybody likes chocolate, so lets make a chocolate class:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>class Chocolate
  def eat
	puts "That tasted great!"
  end
end</pre></div><br />
<br />
Lets take a look at what weve just done. Classes are created via the class keyword. After that comes the name of the class. All class names must start with a Capital Letter. By convention, we use CamelCase for class name. So we would create classes like PieceOfChocolate, but not like Piece_of_Chocolate.<br />
<br />
The next section defines a class method. A class method is a method that is defined for a particular class. For example, the String class has the length method:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre># outputs 5
puts hello.length</pre></div><br />
<br />
To call the eat method of an instance of the Chocolate class, we would use this code:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>my_chocolate = Chocolate.new
my_chocolate.eat # outputs "That tasted great!"</pre></div><br />
<br />
<span class='bbc_underline'>Defining Methods</span><br />
<br />
Methods are defined using the keyword def followed by the method_name. Method parameters are specified between parentheses following the method name. The method body is enclosed by this definition on the top and the word end on the bottom. By convention method names that consist of multiple words have each word separated by an underscore. Some programmers find the Methods defined in Ruby very similar to those in Python.<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>def method_name(value)
  puts value
end</pre></div><br />
<br />
To define a method that doesnt need to take in any values dont add any parameters after the method_name<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>def method_name
  puts "hello"
end</pre></div><br />
<br />
If multiple variables need to be used in the method, they can be separated with a comma.<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>class SomeClass

  def initialize(msg, person)
	print "Hi, my name is " + person + ". Some information about myself" + msg
  end

end</pre></div><br />
<br />
How to call this method:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>instance = SomeClass.new("im 17","LegACy")</pre></div><br />
<br />
Output:<br />
<br />
im 17 is the msg string and LegacyX is the person string<br />
<br />
hi my name is LegACy. Some information about myself: im 17<br />
<br />
Any object can be passed through using methods<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>def myMethod(myObject)
#Check to see if it defined as an Object that we created
#You will learn how to define Objects in a later section
  if(myObject.is_a?(Integer))
	puts "Your Object is an Integer"
  end
end</pre></div><br />
<br />
The return keyword can be used to specify that you will be returning a value from the method defined<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>def myMethod
  return "Hello"
end</pre></div><br />
<br />
<span class='bbc_underline'>Superclass(Inheritance)</span><br />
<br />
A class can inherit functionality and variables from a superclass, sometimes referred to as a parent class or base class. Ruby does not support multiple inheritance and so a class in Ruby can have only one superclass. The syntax is<br />
as follows:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>class ParentClass
  def a_method
	puts 'b'
  end
end

class SomeClass &lt;  ParentClass # " &lt; " means inherit (or "extends" if you are from Java background)
  def another_method
	puts 'a'
  end
end</pre></div><br />
<br />
How to call this:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>instance = SomeClass.new
instance.another_method
instance.a_method</pre></div><br />
<br />
Output:<br />
<br />
a<br />
b<br />
<br />
All non-private variables and functions are inherited by the child class from the superclass. If your class overrides a method from parent class (superclass), you still can access the parents method by using the super keyword.<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>class ParentClass

  def a_method
	puts 'b'
  end

end

class SomeClass &lt;  ParentClass

  def a_method
	super
	puts 'a'
  end

end</pre></div><br />
how to call this:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>instance = SomeClass.new
instance.a_method</pre></div><br />
<br />
Output:<br />
<br />
b<br />
a<br />
<br />
<span class='bbc_underline'>Operators</span><br />
<br />
<br />
<span class='bbc_underline'>Assignment</span><br />
<br />
Assignment in Ruby is done using the equal operator =. This is both for variables and objects, but since strings, floats, and integers are actually objects in Ruby, youre always assigning objects.<br />
Examples:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>myvar = 'myvar is now this string'
var = 321
dbconn = Mysql::new('localhost','root','password')</pre></div><br />
Self assignment<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>x = 1 #=&gt;;1
x += x #=&gt;; 2
x -= x #=&gt;; 0
x += 4 #=&gt;; x was 0 so x= + 4 # x is positive 4
x *= x #=&gt;; 16
x **= x #=&gt;; 18446744073709551616 # Raise to the power
x /= x #=&gt;;1</pre></div><br />
<br />
A frequent question from C and C++ types is How do you increment a variable? Where are ++ and -- operators? In Ruby, you should use x+=1 and x-=1 to increment or decrement a variable.<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>x = 'a'
x.succ! #=&gt;; "b" : succ! method is defined for String, but not for Integer types</pre></div><br />
<br />
<span class='bbc_underline'>Multiple assignments</span><br />
<br />
Examples:<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>var1, var2, var3 = 10, 20, 30
puts var1 #=&gt;; var1 is now 10
puts var2 #=&gt;; var2 is now 20,var3...etc</pre></div><br />
<br />
<span class='bbc_underline'>Control Structures</span><br />
<br />
Ruby can control the execution of code using Conditional branches. A conditional Branch takes the result of a test expression and executes a block of code depending whether the test expression is true or false. If the test expression evaluates to the constant false or nil, the test is false; otherwise, it is true. Note that the number zero is considered true, whereas many other programming languages consider it false.<br />
<br />
In many popular programming languages, conditional branches are statements. They can affect which code is executed, but they do not result in values themselves. In Ruby, however, conditional branches are expressions. They evaluate to values, just like other expressions do. An if expression, for example, not only determines whether a subordinate block of code will execute, but also results in a value itself.<br />
<br />
if expression:<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>a = 5
if a == 4
a = 7
end
print a # prints 5 since the if-block isn't executed</pre></div><br />
<br />
You can also put the test expression and code block on the same line if you use then:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>if a == 4 then a = 7 end
#or
if a == 4: a = 7 end</pre></div><br />
<br />
if-elsif-else expression<br />
<br />
The elsif (note that its elsif and not elseif) and else blocks give you further control of your scripts by providing the option to accommodate additional tests. The elsif and else blocks are considered only if the if test is false. You can have any number of elsif blocks but only one if and one else block.<br />
<br />
Syntax:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>if   #expression
#...code block...
elsif   #another expression
#...code block...
elsif   #another expression
#...code block...
else
#...code block...
end</pre></div><br />
<br />
<span class='bbc_underline'>Variables and Constants</span><br />
<br />
A variable in Ruby can be distinguished by the characters at the start of its name. Theres no restriction to the length of a variables name (with the exception of the heap size).<br />
<br />
<span class='bbc_underline'>Local Variables</span><br />
<br />
A variable whose name begins with a lowercase letter (a-z) or underscore (_) is a local variable or method invocation. A local variable is only accessible from within the block of its initialization.<br />
<br />
Example:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>foobar</pre></div><br />
<br />
<span class='bbc_underline'>Instance Variables</span><br />
<br />
Instance variables are created for each class instance and are accessible only within that instance or through the methods provided by that instance. They are accessed using the @ operator.<br />
<br />
Example:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>@foobar</pre></div><br />
<br />
A variable whose name begins with @ is an instance variable of self. An instance variable belongs to the object itself. Uninitialized instance variables have a value of nil.<br />
<br />
<span class='bbc_underline'>Class Variables</span><br />
<br />
Class variables are accessed using the @@ operator. These variables are associated with the class rather than any object instance of the class and are the same across all object instances. (These are the same as class static<br />
variables in Java or C++).<br />
<br />
Example:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>@@foobar</pre></div><br />
<br />
<span class='bbc_underline'>Global Variables</span><br />
<br />
A variable whose name begins with $ has a global scope; meaning it can be accessed from anywhere within the program during runtime.<br />
<br />
Example:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>$foobar</pre></div><br />
<br />
<span class='bbc_underline'>Constants</span><br />
<br />
A variable whose name begins with an uppercase letter (A-Z) is a constant. A constant can be reassigned a value after its initialization, but doing so will generate a warning. Every class is a constant. Trying to substitute the value of a constant or trying to access an uninitialized constant raises the NameError exception.<br />
<br />
Usage:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>FOOBAR</pre></div><br />
<br />
<span class='bbc_underline'>Pseudo Variables</span><br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>self</pre></div><br />
<br />
Execution context of the current method.<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>nil</pre></div><br />
<br />
The sole-instance of the NilClass class. Expresses nothing.<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>true</pre></div><br />
<br />
The sole-instance of the TrueClass class. Expresses true.<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>false</pre></div><br />
<br />
The sole-instance of the FalseClass class. Expresses false. (nil also is considered to be false, and every other<br />
value is considered to be true in Ruby.)<br />
The value of a pseudo variable cannot be changed. Substitution to a pseudo variable causes an exception to be raised.<br />
<br />
<strong class='bbc'>1.3 Intermidate Ruby</strong><br />
<br />
<span class='bbc_underline'>Arrays & Hashes</span><br />
<br />
An array is a collection of objects indexed by a non-negative integer. You can create an array object by writing Array.new, by writing an optional comma-separated list of values inside square brackets.<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>array_one = Array.new
array_two = &#91;&#93; # shorthand for Array.new
array_three = &#91;"a", "b", "c"&#93; # array_three contains "a" , "b" and "c"

array_three&#91;0&#93; # =&gt;; "a"
array_three&#91;2&#93; # =&gt;; "c"</pre></div><br />
<br />
Negative indices are counted back from the end<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>array_four&#91;-2&#93; # =&gt;; "b"</pre></div><br />
<br />
[start, count] indexing returns an array of count objects beginning at index start<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>array_four&#91;1,2&#93; # =&gt;; &#91;"b", "c"&#93;</pre></div><br />
<br />
Using ranges. The end position is included with two periods but not with three, well learn more about ranges later.<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>array_four&#91;0..1&#93; # =&gt;; &#91;"a", "b"&#93;

array_four&#91;0...1&#93; # =&gt;; &#91;"a"&#93;</pre></div><br />
<br />
Hashes are basically the same as arrays, except that a hash not only contains values, but also keys pointing to those values. Each key can occur only once in a hash. A hash object is created by writing Hash.new or by writing an optional list of comma-separated key =&gt; value pairs inside curly braces.<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>hash_one = Hash.new
hash_two = {} # shorthand for Hash.new
hash_three = {"a" =&gt;; 1, "b" =&gt;; 2, "c" =&gt;; 3} #=&gt;; {"a"=&gt;; 1,"b"=&gt;; 2, "c"=&gt;; 3}</pre></div><br />
<br />
<span class='bbc_underline'>Ranges</span><br />
<br />
A range represents a subset of all possible values of a type, to be more precise, all possible values between a start value and an end value.<br />
<br />
This may be:<br />
<br />
 All integers between 0 and 5.<br />
0..5<br />
 All numbers (including non-integers) between 0 and 1, excluding 1.<br />
0.01.0<br />
 All characters between t and y.<br />
t..y<br />
<br />
Therefore, ranges consist of a start value, an end value, and whether the end value is included or not (in this short syntax, using two .. for including, and three ... for excluding). A range represents a set of values, not a sequence. Therefore,<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>5..0</pre></div><br />
<br />
though syntactically correct, produces a range of length zero.<br />
<br />
Ranges can only be formed from instances of the same class or subclasses of a common parent, which must be Comparable (implementing &lt;=&gt;). Ranges are instances of the Range class, and have certain methods, for example, to determine whether a value is<br />
<br />
inside a range:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>r = 0..5
puts r === 4 # =&gt;; true
puts r === 7 # =&gt;; false</pre></div><br />
<br />
<span class='bbc_underline'>Method Calls</span><br />
<br />
Methods are called using the following syntax:<br />
<br />
method_name(parameter1, parameter2,<br />
<br />
If the method has no parameters the parentheses can usually be omitted as in the following:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>method_name</pre></div><br />
<br />
If you dont have code that needs to use method result immediately, Ruby allows to specify parameters omitting<br />
parentheses:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>results = method_name parameter1, parameter2 # calling method, not using parentheses</pre></div><br />
<br />
You need to use parentheses if you want to work with the result immediately. e.g., if a method returns an array and we want to reverse element<br />
<br />
order:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>results = method_name(parameter1, parameter2).reverse</pre></div><br />
<br />
<span class='bbc_underline'>Return Values</span><br />
<br />
Methods return the value of the last statement executed. The following code returns the value x+y.<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>def calculate_value(x,y)
x + y
end</pre></div><br />
<br />
An explicit return statement can also be used to return from function with a value, prior to the end of the function declaration. This is useful when you want to terminate a loop or return from a function as the result of a conditional expression.<br />
<br />
Note, if you use return within a block, you actually will jump out from the function, probably not what you want.<br />
<br />
To terminate block, use break. You can pass a value to break which will be returned as the result of the block:<br />
	<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>six = (1..10).each {|i| break i if i&gt;; 5}</pre></div><br />
<br />
In this case, six will have the value 6.<br />
<br />
<span class='bbc_underline'>Class Definition</span><br />
<br />
Classes are the basic template from which object instances are created. A class is made up of a collection of variables representing internal state and methods providing behaviours that operate on that state.<br />
<br />
Classes are defined in Ruby using the class keyword followed by a name. The name must begin with a capital letter and by convention names that contain more than one word are run together with each word capitalized and no<br />
separating characters (CamelCase). The class definition may contain method, class variable, and instance variable declarations as well as calls to methods that execute in the class context, such as attr_accessor. The class declaration<br />
is terminated by the end keyword.<br />
<br />
Example:<br />
<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>class MyClass
  def some_method
	 #code goes here
  end
end
</pre></div><br />
<br />
<em class='bbc'><span style='color: #FF0000'>If you have any questions please feel free to ask, and i will answer them to the best of my ability.</span></em>]]></description>
		<pubDate>Tue, 16 Mar 2010 10:26:13 +0000</pubDate>
		<guid isPermaLink="false">30</guid>
	</item>
	<item>
		<title>Regular Expressions in RGSS (Regexp)</title>
		<link>http://www.rmxpunlimited.net/forums/tutorials/article/11-regular-expressions-in-rgss-regexp/</link>
		<description><![CDATA[<span class='bbc_center'><span style='font-size: px;'><strong class='bbc'>Regular Expressions in RGSS (Regexp)</strong></span></span><br />
<span style='font-size: 26px;'><strong class='bbc'>Preface</strong></span><br />
<br />
This article is intended to give basic insight in the use of Regular Expressions in RGSS and to be used for future reference.<br />
I assume you, the reader, have scripting knowledge. If you have problems with scripting issues when you read/test the tutorial that is not directly related to regular expression it would probably be a good idea to seek basic scripting tutorials before continue reading or you will most likely not get as much out of reading this tutorial.<br />
This is not an in-depth tutorial on regular expressions. It is more of an appetizer. A help to get you started. (Along with the reference part naturally)<br />
I hope will be able to figure out how to use Regular expressions to your advantage with what I have provided as well as being able to figure out what I have not run through.<br />
<br />
I am sure I will have made at least one error. Please do tell me if you find it.<br />
If you have any problems understanding anything of the material here, ask. Worst case scenario is me not answering. Best case is you getting an answer that will help you understand the stuff here <img src='http://www.rmxpunlimited.net/forums/public/style_emoticons/default/happy.gif' class='bbc_emoticon' alt='^_^' /><br />
Worth the risk? I would say so.<br />
<br />
Enjoy reading<br />
 - <strong class='bbc'>Zeriab</strong><br />
<br />
<span style='font-size: 26px;'><strong class='bbc'>Contents</strong></span><ul class='bbc'><li>Preface<br /></li><li>Contents<br /></li><li>Reference<br /></li><li>What are regular expressions/languages?<br /></li><li>How to create regular expressions<br /></li><li>How to use regular expressions<br /></li><li>Non-regular languages accepted<br /></li><li>Examples<br /></li><li>Exercises<br /></li><li>Credits and thanks<br /></li><li>Sources and useful links</li></ul> <br />
<span style='font-size: 26px;'><strong class='bbc'>Reference</strong></span><br />
<br />
Reference from <a href='http://www.zenspider.com/Languages/Ruby/QuickRef.html#11' class='bbc_url' title='External link' rel='nofollow external'>ZenSpider</a>:<br />
<br />
<p class='citation'>Reference said:</p><div class="blockquote"><div class='quote'>Regexen<br />
<br />
/normal regex/iomx[neus]<br />
%r|alternate form|<br />
<br />
options:<br />
<br />
/i         case insensitive<br />
/o         only interpolate #{} blocks once<br />
/m         multiline mode - '.' will match newline<br />
/x         extended mode - whitespace is ignored<br />
/[neus]    encoding: none, EUC, UTF-8, SJIS, respectively<br />
<br />
regex characters:<br />
<br />
.          any character except newline<br />
[ ]        any single character of set<br />
[^ ]       any single character NOT of set<br />
*          0 or more previous regular expression<br />
*?         0 or more previous regular expression(non greedy)<br />
+          1 or more previous regular expression<br />
+?         1 or more previous regular expression(non greedy)<br />
?          0 or 1 previous regular expression<br />
|          alternation<br />
( )        grouping regular expressions<br />
^          beginning of a line or string<br />
$          end of a line or string<br />
{m,n}      at least m but most n previous regular expression<br />
{m,n}?     at least m but most n previous regular expression(non greedy)<br />
&#092;A         beginning of a string<br />
&#092;b         backspace(0x08)(inside[]only)<br />
&#092;B         non-word boundary<br />
&#092;b         word boundary(outside[]only)<br />
&#092;d         digit, same as[0-9]<br />
&#092;D         non-digit<br />
&#092;S         non-whitespace character<br />
&#092;s         whitespace character[ &#092;t&#092;n&#092;r&#092;f]<br />
&#092;W         non-word character<br />
&#092;w         word character[0-9A-Za-z_]<br />
&#092;z         end of a string<br />
&#092;Z         end of a string, or before newline at the end<br />
(?# )      comment<br />
(?: )      grouping without backreferences<br />
(?= )      zero-width positive look-ahead assertion<br />
(?! )      zero-width negative look-ahead assertion<br />
(?ix-ix)   turns on/off i/x options, localized in group if any.<br />
(?ix-ix: ) turns on/off i/x options, localized in non-capturing group.</div></div><br />
<br />
<span style='font-size: 26px;'><strong class='bbc'>What are regular expressions/languages?</strong></span><br />
<em class='bbc'>You can skip this section if you want since it is a bit of theory without too much practical application.</em><br />
<br />
A regular language is a language that can be expressed with a regular expression.<br />
What do I mean by language?<br />
I mean that words either can be in the language or not in the language.<br />
Let us for the moment for simplification consider an <em class='bbc'>alphabet</em> with just <strong class='bbc'>a</strong> and <strong class='bbc'>b</strong>. This means that you only have the symbol <strong class='bbc'>a</strong> and the symbol <strong class='bbc'>b</strong> to make words of when using this alphabet.<br />
A regular language with that alphabet will define which combinations of <strong class='bbc'>a</strong> and <strong class='bbc'>b</strong> are <em class='bbc'>words</em> in the language. When I say a regular language accepts a words I mean that it is an actual <em class='bbc'>word</em> in the language.<br />
We could define a regular language to be an <strong class='bbc'>a</strong> followed by any amount of <strong class='bbc'>b</strong>s and ended by 1 <strong class='bbc'>a</strong>. 0 <strong class='bbc'>b</strong>s is a possibility.<br />
Etc. <strong class='bbc'>aa</strong>, <strong class='bbc'>aba</strong> and <strong class='bbc'>abbba</strong> would be in the language.<br />
<strong class='bbc'>b</strong>, <strong class='bbc'>abbbbab</strong> and <strong class='bbc'>bba</strong> would on the other hand not be in the language.<br />
We can quickly see that there are an infinite amount of words belonging to the language <img src='http://www.rmxpunlimited.net/forums/public/style_emoticons/default/happy.gif' class='bbc_emoticon' alt='^_^' /><br />
<br />
A regular expression is the definition of a regular language.<br />
Let us start with a simple regular expression:<br />
<strong class='bbc'>aba</strong><br />
This means that accepted word must consist of an <strong class='bbc'>a</strong> followed by a <strong class='bbc'>b</strong> followed by an <strong class='bbc'>a</strong>.<br />
This particular regular expression defines a regular language that only accepts one word, <em class='bbc'>aba</em>.<br />
<br />
The previous regular language can be expresses as:<br />
<strong class='bbc'>a(b)*a</strong><br />
<br />
Notice the new notation. The star *.<br />
It literally means any amount of the symbol it encompasses. By any amount it is 0, 1, 2, ...<br />
As long as just one of the amounts fits it will be accepted.<br />
The regular expression defines a regular language that accepts any words that consists of an <strong class='bbc'>a</strong> followed by any amount of <strong class='bbc'>b</strong>s followed by an <strong class='bbc'>a</strong> and nothing more.<br />
Note that <strong class='bbc'>a(b)*(b)*a</strong> expresses the same regular language. This can easily be seen as one of the <strong class='bbc'>(b)*</strong> can be 0 all the time and you have the same regular expression.<br />
We can conclude that there can exist an infinite amount ways to express a regular language<br />
<br />
If we wanted the words just to start with <strong class='bbc'>a(b)*a</strong> and what come after is irrelevant we can use this regular expression: <strong class='bbc'>a(b)*a[ab]*</strong><br />
<br />
Note: The <strong class='bbc'>()</strong> are not really needed when there is only 1 letter, I just put them on for clarity. It is perfectly fine to write <strong class='bbc'>ab*a[ab]*</strong><br />
<br />
Let us define a new regular expression:<br />
<strong class='bbc'>abba|baba</strong><br />
<br />
We have new notation again. The | simple means <em class='bbc'>or</em> like in normal RGSS.<br />
So this regular expression defines a language that accepts <strong class='bbc'>abba</strong> and <strong class='bbc'>baba</strong>. It is pretty straightforward.<br />
<br />
The? means either 0 or 1 of the symbol. <strong class='bbc'>ab?a</strong> accepts <strong class='bbc'>aa</strong> and <strong class='bbc'>aba</strong>.<br />
<br />
One final often used notation is the + operator - <strong class='bbc'>a(b)+a</strong><br />
It is basically the same as the star * operator with the difference of at least one b.<br />
<strong class='bbc'>(x)+</strong> is the same as <strong class='bbc'>x(x)*</strong>, where x means that it could be anything. Any regular notation.<br />
<br />
Note <strong class='bbc'>(a)*</strong> also accepts the empty word. I.e. "" in Ruby syntax.<br />
<br />
I will end this section with an example of a non-regular language:<br />
Any words in this language has a number of <strong class='bbc'>a</strong>s in the start followed by the same number of <strong class='bbc'>b</strong>s.<br />
I.e. <strong class='bbc'>ab</strong>, <strong class='bbc'>aabb</strong>, <strong class='bbc'>aaabbb</strong> and so on.<br />
<br />
I will not trouble you with the proof because I think you will find it as boring as I do.<br />
If you really want it I am sure you can manage to search for it yourself. <img src='http://www.rmxpunlimited.net/forums/public/style_emoticons/default/wink.gif' class='bbc_emoticon' alt=';)' /><br />
<br />
<br />
<span style='font-size: 26px;'><strong class='bbc'>How to create regular expressions</strong></span><br />
<br />
You can create a regular expression with one of the following syntaxes: (I will use the first one in my examples)<br />
<br />
/.&#46;&#46;/<em class='bbc'>ol</em><br />
%r|...|<em class='bbc'>ol</em><br />
Regexp.new('...', <em class='bbc'>options</em>, <em class='bbc'>language</em>)<br />
<br />
The dots (...) symbolize the actual regular expression. You can see the syntax up in the reference section.<br />
The <em class='bbc'>o</em> symbolizes the place for options, which are optional. You do not have to write anything here.<br />
<em class='bbc'>o</em> be any of the following <em class='bbc'>i,o,m,x</em> You can have several of them. You can choose them all if you want. From the reference section:<br />
<p class='citation'>Quote</p><div class="blockquote"><div class='quote'>/i         case insensitive<br />
/o         only interpolate #{} blocks once<br />
/m         multiline mode - '.' will match newline<br />
/x         extended mode - whitespace is ignored<br />
/[neus]encoding: none, EUC, UTF-8, SJIS, respectively</div></div><br />
The /[neus] is for the <em class='bbc'>l</em>. You can choose either <em class='bbc'>n, e, u</em> or <em class='bbc'>s</em>. Only one encoding is possible at a time.<br />
<br />
The <em class='bbc'>options</em> block in Regexp.new is optional. This is a little different from the options part in the previous syntaxes.<br />
Here you can put:<br />
<strong class='bbc'>Regexp::EXTENDED</strong> - Newlines and spaces are ignored.<br />
<strong class='bbc'>Regexp::IGNORECASE</strong> - Case insensitive.<br />
<strong class='bbc'>Regexp::MULTILINE</strong> - Newlines are treated as any other character.<br />
<br />
If you want more than one option, let us say ignore case and multiline, you or them together like this: <strong class='bbc'>Regexp::IGNORECASE | Regexp::MULTILINE</strong><br />
<br />
<br />
We move on to what you actually write instead of the dots (...)<br />
Notice that <strong class='bbc'>.</strong> means any character.<br />
If you want to find just a dot use <strong class='bbc'>&#092;.</strong><br />
<br />
Let us take the example where you want to accept words that start with either <strong class='bbc'>a, b</strong> or <strong class='bbc'>c</strong>. What comes after does not matter<br />
<strong class='bbc'>/(a|b|c).*/</strong> is a possibility, so is <strong class='bbc'>[abc].*</strong> and <strong class='bbc'>[a-c].*</strong><br />
This illustrates the use of the <strong class='bbc'>[]</strong>. If you want all letters use <strong class='bbc'>[a-zA-Z]</strong> or just <strong class='bbc'>[a-z]</strong> if you have ignore case on.<br />
If you have weird letters, i.e. not a-z then you probably have to enter them manually.<br />
Example, any word:<br />
<strong class='bbc'>/[a-z]*/i</strong> gives the same as <strong class='bbc'>/[a-zA-Z]*/</strong><br />
The first case will not allow case sensitive stuff later though. I.e. <strong class='bbc'>/[a-z]*g/i</strong> is not the same as <strong class='bbc'>/[a-zA-Z]*g/</strong>.<br />
In the first case words that end with big G are accepted while they are not in the latter case.<br />
Numbers are <strong class='bbc'>[0-9]</strong><br />
Just use <strong class='bbc'>&#092;w</strong> to get numbers, letters and <strong class='bbc'>_</strong><br />
<br />
<br />
Let us a bit more difficult example.<br />
We have used Dir to get the files in a directory. We want to remove the file extension from the strings. How exactly we will do it is shown in the next section.<br />
Here we will write the regular expression that accepts the file extension with dot and only the file extension.<br />
If there are more dots as in FileName.txt.dat we will only consider the end extension. I.e. only <strong class='bbc'>.dat</strong>.<br />
If you have self-discipline enough it would be a good time to try and figure out how to do it on your own. Just consider every extension.<br />
<br />
My answer is <strong class='bbc'>/&#092;.[^&#092;.]*&#092;Z/</strong><br />
I will go through this step by step.<br />
First we have <strong class='bbc'>&#092;.</strong> which means a dot like I told earlier. It is the dot in the file name.<br />
Next we have the <strong class='bbc'>[^&#092;.]*</strong> bit. The <strong class='bbc'>[]</strong> means one of the character in the brackets. <strong class='bbc'>[^]</strong> means any character that is not in the brackets. Since you have the dot <strong class='bbc'>&#092;.</strong> in the brackets it means any character but the dot.<br />
The star simple means any amount, so any amounts of non-dot characters are accepted.<br />
Finally we have <strong class='bbc'>&#092;Z</strong> which means at the end of the string. It will be explained in the next section.<br />
<br />
<br />
<span style='font-size: 26px;'><strong class='bbc'>How to use regular expressions</strong></span><br />
<br />
You may have wondered why there are both a <strong class='bbc'>*</strong> and <strong class='bbc'>*?</strong> operator that basically does the same.<br />
I have also avoided other use specific operators.<br />
These are related to how they should be applied to strings.<br />
<br />
You now know how to create regular expressions and I will in this section tell you how to actually use.<br />
<br />
I will continue the example from the previous section.<br />
We have the string:<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>str = "Read.me.txt"</pre></div><br />
We want to remove the <strong class='bbc'>.txt</strong> which can be done this way:<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>str. gsub!(/&#092;.&#91;^&#092;.&#93;*&#092;Z/) {|s| ""}</pre></div><br />
We use the gsub! which modifies the string. The return is "Read.me"<br />
The <strong class='bbc'>&#092;Z</strong> means that it has to be at the end of the line and/or string. '&#092;n' is considered to be a new line. It does not take <em class='bbc'>.me</em> because there is a dot after it and it is therefore not at the end of the line. (Remember that <strong class='bbc'>[^&#092;.]</strong> do not accept dots)<br />
Here is a list of the methods on strings where you can apply the regular expression.<br />
Look here for how to use them: <a href='http://www.rubycentral.com/ref/ref_c_string.html' class='bbc_url' title='External link' rel='nofollow external'>http://www.rubycentr...f_c_string.html</a><ul class='bbc'><li>=~<br /></li><li>[ ]<br /></li><li>[ ]=<br /></li><li>gsub<br /></li><li>gsub!<br /></li><li>index<br /></li><li>rindex<br /></li><li>scan<br /></li><li>slice<br /></li><li>slice!<br /></li><li>split<br /></li><li>sub<br /></li><li>sub!</li></ul>Basically whenever you see <em class='bbc'>aRegexp</em> or <em class='bbc'>pattern</em> as an argument you can apply your regular expression.<br />
<br />
The effects vary from method to method, but I am sure you can figure it out as the principle when considering regular expressions are the same.<br />
<br />
Another fishy thing you might have notices is the <em class='bbc'>non-greedy</em> variants of <strong class='bbc'>*</strong> and <strong class='bbc'>+</strong>.<br />
To illustrate the different effect try this code:<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>"boobs".gsub(/bo*/) {|s| p s}	 # 1
 "boobs".gsub(/bo*?/) {|s| p s}	# 2
 "boobs".gsub(/bo+/) {|s| p s}	 # 3
 "boobs".gsub(/bo+?/) {|s| p s}	# 4</pre></div><br />
The first one (greedy) will print out "boo" and "b". It takes all the <strong class='bbc'>o</strong>s it can.<br />
The next one (non greedy) will print out "b" and "b". It takes as few <strong class='bbc'>o</strong>s as possible.<br />
That is basically the difference. It will take <strong class='bbc'>o</strong>s if necessary. In the following code "boob" is printed out in both examples.<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>"boobs".gsub(/bo*b/) {|s| p s} 
 "boobs".gsub(/bo*?b/) {|s| p s}</pre></div><br />
<br />
The + operator is similar except that there have to be at least 1 <strong class='bbc'>o</strong>.<br />
In 3rd case you will get "boo" and 4th case you will get "bo".<br />
<br />
All in all. The longest possible string is taken unless you have some non greedy operators. The non greedy operators will try to get the shortest possible string.<br />
<em class='bbc'>"boobs".gsub(/o*?/) {|s| p s}</em> will give pure ""s.<br />
As a finale I will talk about escaping characters. You may have wondered about how to search for the characters that have special meaning like <strong class='bbc'>*</strong>, <strong class='bbc'>|</strong>, <strong class='bbc'>/</strong>.<br />
The trick is to <em class='bbc'>escape</em> them. That is what it is called. You just basically have to put a <strong class='bbc'>&#092;</strong> in front of them.<br />
<strong class='bbc'>&#092;*</strong>, <strong class='bbc'>&#092;|</strong> and <strong class='bbc'>&#092;/</strong>. To get <strong class='bbc'>&#092;</strong> just use <strong class='bbc'>&#092;&#092;</strong>.<br />
I have already showed an example where I escape the dot. (<strong class='bbc'>&#092;.</strong>)<br />
<br />
There are still loads of operators I have not showed. Some are a bit advanced some are not. They will not be included in this tutorial except for the back reference shown in the next section<br />
Until I make another tutorial or extend this tutorial you can have fun with discovering how they work on your own <img src='http://www.rmxpunlimited.net/forums/public/style_emoticons/default/happy.gif' class='bbc_emoticon' alt='^_^' /><br />
<br />
<span style='font-size: 26px;'><strong class='bbc'>Non-regular languages accepted</strong></span><br />
<br />
It is a bit ironic that the regular expression implementation in Ruby also accepts some non-regular languages.<br />
It is the back-references I am talking about.<br />
Look at this example: <strong class='bbc'>/(wii|psp)&#092;1/</strong><br />
<strong class='bbc'>wiiwii</strong> and <strong class='bbc'>psppsp</strong>, but neither <strong class='bbc'>wiipsp</strong> nor <strong class='bbc'>pspwii</strong>.<br />
You can use back references to make non-regular languages.<br />
I am not going to supply neither proof nor example. You can google it yourself if you are doubting <img src='http://www.rmxpunlimited.net/forums/public/style_emoticons/default/happy.gif' class='bbc_emoticon' alt='^_^' /><br />
One problem with back references is speed. It goes from polynomial time to exponential time. If the regular expressions have been implemented just a little sensible the speed down will only effect regular expressions with the extra functionality.<br />
It should not be too much of a problem with short regular expressions, but it is still something to consider.<br />
<br />
<span style='font-size: 26px;'><strong class='bbc'>Examples</strong></span><br />
<br />
A couple of examples for reference and guidance <img src='http://www.rmxpunlimited.net/forums/public/style_emoticons/default/happy.gif' class='bbc_emoticon' alt='^_^' /><br />
<br />
<span style='font-size: 15px;'><strong class='bbc'><em class='bbc'><span class='bbc_underline'>Example 1</span></em></strong></span><br />
I will start by giving some code:<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>files = Dir&#91;"Data/*"&#93;
files.each {|s| s.gsub!(/&#092;.&#91;^&#092;.&#93;*$|&#91;^&#092;/&#93;*&#092;//) {|str| ""}}</pre></div><br />
The filenames of all the files in the Data directory are stored in the <em class='bbc'>files</em> variable as strings in an Array. (subdirectories and their contents not included)<br />
That is what the <em class='bbc'>Dir["Data/*"]</em> command returns.<br />
The next line calls <em class='bbc'>gsub!(</em><strong class='bbc'>/&#092;.[^&#092;.]*$|[^&#092;/]*&#092;//</strong><em class='bbc'>) {|str| ""}</em> on each filename. (Remember that it is a string)<br />
Now we finally come to the big regular expression:]<strong class='bbc'>/&#092;.[^&#092;.]*$|[^&#092;/]*&#092;//</strong><br />
Notice the <strong class='bbc'>|</strong>. This means that we accept strings that fulfills either what comes before or what comes after. If  the string are accepted in both cases it will still be accepted<br />
Let us look at <strong class='bbc'>/&#092;.[^&#092;.]*$</strong>. This looks like something we have seen before. Since <strong class='bbc'>$</strong> means end of string/line it basically does the same thing as <strong class='bbc'>&#092;Z</strong>. We have already run through this example, it removes the extension.<br />
Next we will look <strong class='bbc'>[^&#092;/]*&#092;//</strong>. Remember the bit about escaping?<br />
<strong class='bbc'>[^&#092;/]</strong> means any character but /. The star means any amount of them.<br />
It is followed by <strong class='bbc'>&#092;/</strong> which means the character /. The last character MUST be /<br />
Since the greedy version of the star is used it will try to find the longest possible string which ends with /.<br />
So this basically finds the directory bit of the path.<br />
This means that it either has to be the extension or the path before the filename. We remove these parts by substituting the found strings with "".<br />
<br />
This can be used if you for some reason want to draw the files in the location without the path and extension. (You might have them elsewhere.)<br />
<br />
<span style='font-size: 26px;'><strong class='bbc'>Exercises</strong></span><br />
<br />
I have made up a couple of exercise you can try to deal with. I have not provided the answer and I do not plan to provide them.<br />
I consider them more of a stimulant; A way to help you at learning regular expressions.<br />
If you really want to check your answers then PM me. Do not post your answers here.<br />
<br />
<span style='font-size: 15px;'><strong class='bbc'><em class='bbc'><span class='bbc_underline'>Exercise 1</span></em></strong></span><br />
Let <em class='bbc'>str</em> be an actual string. What does this code do?<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>str.gsub!(/.*&#092;..*/) {|s| ""}</pre></div><br />
<br />
<span style='font-size: 15px;'><strong class='bbc'><em class='bbc'><span class='bbc_underline'>Exercise 2</span></em></strong></span><br />
You have one long string that contains a certain amounts of words. Whitespace characters separate the words.<br />
These words have a structure. They all start with either "donkey_" or "monkey_"<br />
What comes after the "_" differs from word to word.<br />
What you want is to separate the monkeys from the donkeys.<br />
You want to put the donkeys in a donkey array and the monkeys in a monkey array.<br />
Make the 2 arrays before and use just a <em class='bbc'>gsub</em> call to separate the monkeys from the donkeys.<br />
<br />
<span style='font-size: 26px;'><strong class='bbc'>Credits and thanks</strong></span><br />
This article have been made by <strong class='bbc'>Zeriab</strong>, please give credits<br />
Credits to <strong class='bbc'>ZenSpider.com</strong> for the reference list.<br />
<br />
Thanks to:<br />
<strong class='bbc'>Ragnarok Rob</strong> for the example word "boobs". <em class='bbc'>(1st and 4th letter equal. 2nd and 3rd letter equal and different from 1st and 4th. 5th letter different from the others)</em><br />
<strong class='bbc'>SephirothSpawn</strong> for getting me to do this tutorial.<br />
<strong class='bbc'>Nitt</strong> (<strong class='bbc'>jimme reashu</strong>) for reporting a bug<br />
<br />
<br />
<span style='font-size: 26px;'><strong class='bbc'>Sources and useful links</strong></span><br />
<br />
<a href='http://www.zenspider.com/Languages/Ruby/QuickRef.html#11' class='bbc_url' title='External link' rel='nofollow external'>ZenSpider</a> - <a href='http://www.zenspider.com/Languages/Ruby/QuickRef.html#11' class='bbc_url' title='External link' rel='nofollow external'>http://www.zenspider...uickRef.html#11</a><br />
<a href='http://www.rubycentral.com/ref/' class='bbc_url' title='External link' rel='nofollow external'>Ruby Central</a> - <a href='http://www.rubycentral.com/ref/ref_c_regexp.html' class='bbc_url' title='External link' rel='nofollow external'>http://www.rubycentr...f_c_regexp.html</a><br />
<a href='http://www.regular-expressions.info/' class='bbc_url' title='External link' rel='nofollow external'>Regular-Expressions.info</a> - <a href='http://www.regular-expressions.info/' class='bbc_url' title='External link' rel='nofollow external'>http://www.regular-expressions.info/</a>]]></description>
		<pubDate>Tue, 08 Dec 2009 21:46:16 +0000</pubDate>
		<guid isPermaLink="false">11</guid>
	</item>
	<item>
		<title><![CDATA[xLeD's Lesson 1]]></title>
		<link>http://www.rmxpunlimited.net/forums/tutorials/article/10-xleds-lesson-1/</link>
		<description><![CDATA[This is a lesson I wrote for someone called xLeD at a different forum, I'm now sharing it with guys <img src='http://www.rmxpunlimited.net/forums/public/style_emoticons/default/happy.gif' class='bbc_emoticon' alt='^_^' /> <br />
<br />
<span class='bbc_center'><span style='font-size: px;'><span class='bbc_underline'>Lesson 1</span></span></span><br />
<span style='font-size: px;'>Today's topic: <strong class='bbc'>Simple Sorting</strong></span><br />
<br />
Hey <strong class='bbc'>xLeD</strong><br />
<br />
First of I will start with a little something I have written about Arrays. Just skip what you know.<br />
Then I will teach you the search algorithm Insertion-Sort.<br />
<br />
<p class='citation'>Quote</p><div class="blockquote"><div class='quote'><span class='bbc_underline'><span style='font-size: px;'><strong class='bbc'>Array</strong></span></span><br />
Just skip the parts on theory you don't understand. I will not use pictures.<br />
<br />
<span style='font-size: 15px;'><strong class='bbc'>Theory</strong></span><br />
An array is a list of elements. A vector of elements is also correct. Just a different wording.<br />
Let us assume that the elements are integers (whole numbers).<br />
Try to think of a table with 1 column and a number of rows, let's say 10 rows.<br />
In each cell is an integer. This integer is what is meant as an element. This is how the data is stored<br />
There are 10 integers (elements) in all because there are 10 rows. This is an array with 10 elements. <br />
<br />
Let's go back to the rows again and say we want 1 of the integers out from a certain cell. <br />
We must have a way of finding the right cell. We have. It is called the index.<br />
Think about us looking on the top row. Think that if you look at the bottom cell it will be farther away than the top cell. You can say that there is a distance between a certain cell and the top cell.<br />
We can use this distance to get the cell we want. We could say that we wanted the cell with distance 5.<br />
The top cell would of course have distance = 0 and the bottom cell would have the amount of elements - 1. Continuing the example the bottom cell would have distance = 9<br />
Wow? amount of elements - 1... What does that mean?<br />
Remember when we said that there were 10 rows? This is the amount of elements.  So we have 10 - 1 = 9.<br />
If we now call distance for <em class='bbc'>index</em> you we have solved the question about what <em class='bbc'>index</em> means.<br />
<br />
I hope it was understandable<br />
<br />
<span style='font-size: 15px;'><strong class='bbc'>Ruby</strong></span><br />
All the above might be very well, but it does not explain how to you it in ruby.<br />
In Ruby everything is build of objects, which are created from classes. So naturally there is an Array-class.<br />
<br />
Before going further I must point you to <a href='http://www.rubycentral.com/ref/ref_c_array.html' class='bbc_url' title='External link' rel='nofollow external'>Ruby references on the Array-class</a><br />
The above is just basically the syntax with comments.  Therefore you should read there instead of here.<br />
Just a quick example though: (Same elements are allowed)<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>&#91;6, 2, 4, 9, 2&#93;   #&lt;--- is an array
array = &#91;6, 2, 4, 9, 2&#93;   #&lt;---- for before

# Getting the elements out
p array&#91;0&#93;  #---&gt; 6
p array&#91;4&#93;  #---&gt; 2
p array&#91;5&#93;  #---&gt; nil

# A little trick
p array&#91;-1&#93; #---&gt; 2
p array&#91;-2&#93; #---&gt; 9

# -1 returns the last element in the array
# -2 returns the element before the last element and so on</pre></div><br />
<br />
I don't know what else there is to say as most of it is in the references.<br />
Just ask if there is something you can't understand in the references.<br />
<br />
<span style='font-size: 15px;'><strong class='bbc'>References</strong></span><br />
<a href='http://www.rubycentral.com/ref/ref_c_array.html' class='bbc_url' title='External link' rel='nofollow external'>Ruby references</a><br />
<a href='http://en.wikipedia.org/wiki/Array' class='bbc_url' title='External link' rel='nofollow external'>Wikipedia.org</a></div></div><br />
<br />
<span style='font-size: 17px;'><strong class='bbc'>Insertion-Sort:</strong></span><br />
Let <em class='bbc'>A</em> be an array. The pseudo code for the algorithm is:<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>Insertion-Sort(A)
1  for j = 2 to length&#91;A&#93;
2	  do key = A&#91;j&#93;
3		  i = j - 1
4		  while i &gt; 0 and A&#91;i&#93; &gt; key
5			  do A&#91;i + 1&#93; = A&#91;i&#93; 
6					i = i - 1
7		  A&#91;i + 1&#93; = key</pre></div><br />
<br />
Is it difficult to understand? <br />
You should note that pseudo code isn't just pseudo code. This is my version of pseudo code.<br />
Note that how much they are indented tells in which branch they are in.<br />
For example is line 7 not in the while loop, but in the for-loop.<br />
Line 6 is however in the for-loop.<br />
And so on?<br />
<br />
I know I haven't explained it well, and for that I apologize.<br />
I have saved it for the tasks. You'll see ^_~<br />
<br />
<span style='font-size: 36px;'>The tasks:</span><br />
Reading is good, but alas reading alone is not as giving as tasks to follow up the read text.<br />
<strong class='bbc'>Task 1:</strong><br />
<em class='bbc'>A</em> = [7, 12, 30, 12, 6, 29]<br />
Put this array into the algorithm.<br />
Calculate manually what <em class='bbc'>A</em> each time it is at the start of the for-loop.<br />
Also calculate the output. (The sorted array).<br />
<br />
<strong class='bbc'>Task 2:</strong><br />
Implement the algorithm into RMXP. Yup write it in Ruby.<br />
Use the example from above to test.<br />
<br />
<strong class='bbc'>Task 3:</strong><br />
Rewrite the algorithm so it sorts in decreasing order instead of increasing order.<br />
In Ruby I mean.<br />
<br />
<strong class='bbc'>Task 4:</strong> (optional)<br />
Make the insertion sort as an extension to the Array class.<br />
That is make a method <em class='bbc'>insertion_sort</em> that can be called like this:<br />
<div class='codetop'>CODE</div><div class='prettyprint'><pre>&#91;7, 12, 30, 12, 6, 29&#93;.insertion_sort</pre></div><br />
Good luck with the tasks.<br />
 - <strong class='bbc'>Zeriab</strong><br />
<br />
<span style='font-size: 36px;'>Sources:</span><br />
Recursion @ Wikipedia - <a href='http://en.wikipedia.org/wiki/Insertion_sort' class='bbc_url' title='External link' rel='nofollow external'>http://en.wikipedia..../Insertion_sort</a><br />
Introduction to Algorithms - <a href='http://mitpress.mit.edu/algorithms/' class='bbc_url' title='External link' rel='nofollow external'>http://mitpress.mit.edu/algorithms/</a>]]></description>
		<pubDate>Tue, 08 Dec 2009 21:43:38 +0000</pubDate>
		<guid isPermaLink="false">10</guid>
	</item>
</channel>
</rss>