-
Content Count
188 -
Joined
-
Last visited
-
Days Won
5
Content Type
Profiles
Forums
Blogs
Downloads
Calendar
Gallery
Everything posted by Zeriab
-
This is quite some tutorial you got there. It's a good read ^_^
-
I'll post a system I've made:
-
It's a nice tutorial you go there. Quite understandable in my opinion. Great job ^_^ I'm sure loads will find this helpful
-
Regular Expressions in RGSS (Regexp) Preface This article is intended to give basic insight in the use of Regular Expressions in RGSS and to be used for future reference. 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. 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) 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. I am sure I will have made at least one error. Please do tell me if you find it. 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 ^_^ Worth the risk? I would say so. Enjoy reading - Zeriab Contents Preface Contents Reference What are regular expressions/languages? How to create regular expressions How to use regular expressions Non-regular languages accepted Examples Exercises Credits and thanks Sources and useful links Reference Reference from ZenSpider: What are regular expressions/languages? You can skip this section if you want since it is a bit of theory without too much practical application. A regular language is a language that can be expressed with a regular expression. What do I mean by language? I mean that words either can be in the language or not in the language. Let us for the moment for simplification consider an alphabet with just a and b. This means that you only have the symbol a and the symbol b to make words of when using this alphabet. A regular language with that alphabet will define which combinations of a and b are words in the language. When I say a regular language accepts a words I mean that it is an actual word in the language. We could define a regular language to be an a followed by any amount of bs and ended by 1 a. 0 bs is a possibility. Etc. aa, aba and abbba would be in the language. b, abbbbab and bba would on the other hand not be in the language. We can quickly see that there are an infinite amount of words belonging to the language ^_^ A regular expression is the definition of a regular language. Let us start with a simple regular expression: aba This means that accepted word must consist of an a followed by a b followed by an a. This particular regular expression defines a regular language that only accepts one word, aba. The previous regular language can be expresses as: a(b)*a Notice the new notation. The star *. It literally means any amount of the symbol it encompasses. By any amount it is 0, 1, 2, ... As long as just one of the amounts fits it will be accepted. The regular expression defines a regular language that accepts any words that consists of an a followed by any amount of bs followed by an a and nothing more. Note that a(b)*(b)*a expresses the same regular language. This can easily be seen as one of the (b)* can be 0 all the time and you have the same regular expression. We can conclude that there can exist an infinite amount ways to express a regular language If we wanted the words just to start with a(b)*a and what come after is irrelevant we can use this regular expression: a(b)*a[ab]* Note: The () are not really needed when there is only 1 letter, I just put them on for clarity. It is perfectly fine to write ab*a[ab]* Let us define a new regular expression: abba|baba We have new notation again. The | simple means or like in normal RGSS. So this regular expression defines a language that accepts abba and baba. It is pretty straightforward. The? means either 0 or 1 of the symbol. ab?a accepts aa and aba. One final often used notation is the + operator - a(b)+a It is basically the same as the star * operator with the difference of at least one b. (x)+ is the same as x(x)*, where x means that it could be anything. Any regular notation. Note (a)* also accepts the empty word. I.e. "" in Ruby syntax. I will end this section with an example of a non-regular language: Any words in this language has a number of as in the start followed by the same number of bs. I.e. ab, aabb, aaabbb and so on. I will not trouble you with the proof because I think you will find it as boring as I do. If you really want it I am sure you can manage to search for it yourself. ;) How to create regular expressions You can create a regular expression with one of the following syntaxes: (I will use the first one in my examples) /.../ol %r|...|ol Regexp.new('...', options, language) The dots (...) symbolize the actual regular expression. You can see the syntax up in the reference section. The o symbolizes the place for options, which are optional. You do not have to write anything here. o be any of the following i,o,m,x You can have several of them. You can choose them all if you want. From the reference section: The /[neus] is for the l. You can choose either n, e, u or s. Only one encoding is possible at a time. The options block in Regexp.new is optional. This is a little different from the options part in the previous syntaxes. Here you can put: Regexp::EXTENDED - Newlines and spaces are ignored. Regexp::IGNORECASE - Case insensitive. Regexp::MULTILINE - Newlines are treated as any other character. If you want more than one option, let us say ignore case and multiline, you or them together like this: Regexp::IGNORECASE | Regexp::MULTILINE We move on to what you actually write instead of the dots (...) Notice that . means any character. If you want to find just a dot use \. Let us take the example where you want to accept words that start with either a, b or c. What comes after does not matter /(a|b|c).*/ is a possibility, so is [abc].* and [a-c].* This illustrates the use of the []. If you want all letters use [a-zA-Z] or just [a-z] if you have ignore case on. If you have weird letters, i.e. not a-z then you probably have to enter them manually. Example, any word: /[a-z]*/i gives the same as /[a-zA-Z]*/ The first case will not allow case sensitive stuff later though. I.e. /[a-z]*g/i is not the same as /[a-zA-Z]*g/. In the first case words that end with big G are accepted while they are not in the latter case. Numbers are [0-9] Just use \w to get numbers, letters and _ Let us a bit more difficult example. 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. Here we will write the regular expression that accepts the file extension with dot and only the file extension. If there are more dots as in FileName.txt.dat we will only consider the end extension. I.e. only .dat. 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. My answer is /\.[^\.]*\Z/ I will go through this step by step. First we have \. which means a dot like I told earlier. It is the dot in the file name. Next we have the [^\.]* bit. The [] means one of the character in the brackets. [^] means any character that is not in the brackets. Since you have the dot \. in the brackets it means any character but the dot. The star simple means any amount, so any amounts of non-dot characters are accepted. Finally we have \Z which means at the end of the string. It will be explained in the next section. How to use regular expressions You may have wondered why there are both a * and *? operator that basically does the same. I have also avoided other use specific operators. These are related to how they should be applied to strings. You now know how to create regular expressions and I will in this section tell you how to actually use. I will continue the example from the previous section. We have the string: str = "Read.me.txt" We want to remove the .txt which can be done this way: str. gsub!(/\.[^\.]*\Z/) {|s| ""} We use the gsub! which modifies the string. The return is "Read.me" The \Z means that it has to be at the end of the line and/or string. '\n' is considered to be a new line. It does not take .me because there is a dot after it and it is therefore not at the end of the line. (Remember that [^\.] do not accept dots) Here is a list of the methods on strings where you can apply the regular expression. Look here for how to use them: http://www.rubycentral.com/ref/ref_c_string.html =~ [ ] [ ]= gsub gsub! index rindex scan slice slice! split sub sub! Basically whenever you see aRegexp or pattern as an argument you can apply your regular expression. 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. Another fishy thing you might have notices is the non-greedy variants of * and +. To illustrate the different effect try this code: "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 The first one (greedy) will print out "boo" and "b". It takes all the os it can. The next one (non greedy) will print out "b" and "b". It takes as few os as possible. That is basically the difference. It will take os if necessary. In the following code "boob" is printed out in both examples. "boobs".gsub(/bo*b/) {|s| p s} "boobs".gsub(/bo*?b/) {|s| p s} The + operator is similar except that there have to be at least 1 o. In 3rd case you will get "boo" and 4th case you will get "bo". 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. "boobs".gsub(/o*?/) {|s| p s} will give pure ""s. 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 *, |, /. The trick is to escape them. That is what it is called. You just basically have to put a \ in front of them. \*, \| and \/. To get \ just use \\. I have already showed an example where I escape the dot. (\.) 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 Until I make another tutorial or extend this tutorial you can have fun with discovering how they work on your own ^_^ Non-regular languages accepted It is a bit ironic that the regular expression implementation in Ruby also accepts some non-regular languages. It is the back-references I am talking about. Look at this example: /(wii|psp)\1/ wiiwii and psppsp, but neither wiipsp nor pspwii. You can use back references to make non-regular languages. I am not going to supply neither proof nor example. You can google it yourself if you are doubting ^_^ 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. It should not be too much of a problem with short regular expressions, but it is still something to consider. Examples A couple of examples for reference and guidance ^_^ Example 1 I will start by giving some code: files = Dir["Data/*"] files.each {|s| s.gsub!(/\.[^\.]*$|[^\/]*\//) {|str| ""}} The filenames of all the files in the Data directory are stored in the files variable as strings in an Array. (subdirectories and their contents not included) That is what the Dir["Data/*"] command returns. The next line calls gsub!(/\.[^\.]*$|[^\/]*\//) {|str| ""} on each filename. (Remember that it is a string) Now we finally come to the big regular expression:]/\.[^\.]*$|[^\/]*\// Notice the |. 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 Let us look at /\.[^\.]*$. This looks like something we have seen before. Since $ means end of string/line it basically does the same thing as \Z. We have already run through this example, it removes the extension. Next we will look [^\/]*\//. Remember the bit about escaping? [^\/] means any character but /. The star means any amount of them. It is followed by \/ which means the character /. The last character MUST be / Since the greedy version of the star is used it will try to find the longest possible string which ends with /. So this basically finds the directory bit of the path. 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 "". 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.) Exercises 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. I consider them more of a stimulant; A way to help you at learning regular expressions. If you really want to check your answers then PM me. Do not post your answers here. Exercise 1 Let str be an actual string. What does this code do? str.gsub!(/.*\..*/) {|s| ""} Exercise 2 You have one long string that contains a certain amounts of words. Whitespace characters separate the words. These words have a structure. They all start with either "donkey_" or "monkey_" What comes after the "_" differs from word to word. What you want is to separate the monkeys from the donkeys. You want to put the donkeys in a donkey array and the monkeys in a monkey array. Make the 2 arrays before and use just a gsub call to separate the monkeys from the donkeys. Credits and thanks This article have been made by Zeriab, please give credits Credits to ZenSpider.com for the reference list. Thanks to: Ragnarok Rob for the example word "boobs". (1st and 4th letter equal. 2nd and 3rd letter equal and different from 1st and 4th. 5th letter different from the others) SephirothSpawn for getting me to do this tutorial. Nitt (jimme reashu) for reporting a bug Sources and useful links ZenSpider - http://www.zenspider.com/Languages/Ruby/QuickRef.html#11 Ruby Central - http://www.rubycentral.com/ref/ref_c_regexp.html Regular-Expressions.info - http://www.regular-expressions.info/
-
SephirothSpawn has pretty much made what you want: 1. Triple Triad (The card game): http://www.creationasylum.net/index.php?showtopic=2440 2. Sphere Grid: http://www.creationasylum.net/index.php?showtopic=6174 Here is btw. another Final Fantasy related script: Materia System: http://www.creationasylum.net/index.php?showtopic=6288
-
Leon's Encounter-List changer
Zeriab replied to Leon's topic in Archived RPG Maker XP Scripts (RGSS1)
Nice and simple :P -
This is the 2nd lesson I wrote for someone called xLeD at a different forum, I'm now sharing it with guys :P I have made Lesson 2. You can download it at one of the following links: http://www.savefile.com/files/189882 http://www.uploadtemple.com/view.php/1161644637.pdf I hope you like it. - Zeriab
-
Hilarious Windows Errors
Zeriab replied to EmilyAnnCoons's topic in Computers, Internet and Tech Talk
These gave me a good laugh :D I once got an error while trying to copy a file in Windows ME: ERROR Cannot copy file File exists ------------ OK -
@Wyzrd: I intend to stick around :D @Grandor: Thanks @ryanrulz_11: I'm taking a break from the CA at the moment, so I can't at the moment. You could try to somehow get in contact with SephirothSpawn and ask him.
-
I wrote tutorial/explination on recursion to Satiel. I thought I might as well share it. It is dedicated to Satiel. Hey Satiel! Today's topic: Recursion What is recursion? I remember this definition roaming around: Recursion: see "Recursion" It is clearly meant as joke, but still gives a good idea of what Recursion means. Recursion means something like going back. Returning... Stuff like that. Examples are good: Here is a Ruby example of a simple recursive method. #============================================================================== # ** Recursion #------------------------------------------------------------------------------ # Simple example of recursion #============================================================================== class Recursion #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize recurse(1) end #-------------------------------------------------------------------------- # * Recurse-method # # This will print n and then run itself with n being 1 # greater than before. #-------------------------------------------------------------------------- def recurse(n) p n recurse(n+1) end end You see in the method recurse the method recurse being called. This is called a recursive call because the method is calling itself. This is classified as Direct Recursion, because the method calls itself. If the method had called another method which in turn had called recurse it would be classified as Indirect Recursion. You will quickly notice that something is special, especially if you have tried the code. It never stops! This is because there is nothing in the code preventing the recursive loop to stop. Well, it will eventually stop because of security measures. (You would get an 'Stack level too deep' error) If it weren't for them it still would eventually stop due to practical reasons, but it would theoretically never stop. Now we come to the next part. How to prevent it from looping indefinitely: For doing this we must have a base. By a base I mean something that will check if certain conditions are fulfilled. If they are the recursive loop will be breached. Difficult to understand? Fear not because here is another example: #============================================================================== # ** Recursion 2 #------------------------------------------------------------------------------ # Example of recursion, this time actually usuable. #============================================================================== class Recursion #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize p recurse(100) end #-------------------------------------------------------------------------- # * Recurse-method # # Will count the sum of the numbers 1..n recursively #-------------------------------------------------------------------------- def recurse(n) # This is the base part if n <= 0 return 0 else # This is the recursive part return recurse(n-1) + n end end end If you run Recursion.new you should get the number '5050'. What is this number? 5050 = 1 + 2 + 3 + ... + 99 + 100 How does method work? I will show you step by step the execution. I will however use 10 instead of 100 as start number: (55 = 1 + ? + 10) It will start with 'p recurse(10)' from the object initialization. This means that the first time the method recurse is called with n = 10 recurse(10): As 10 is not less or equal 0 this command will be executed 'return recurse(10-1) + 10' The problem is just. What is 'recurse(9)'? recurse(9): As 9 is not less or equal 0 this command will be executed 'return recurse(9-1) + 9' You see where this is head? Yes 'recurse(8)' recurse(8): ? recurse(1): Same as before except that the command executed will be 'return recurse(1-1) + 1' recurse(0): This is different. This time you fulfill the requirements as 0 is less or equal 0. This makes the method 'return 0'. So is this it? Is it finished? recurse(0) is finished. So we go back to recurse(1) which returning 'recurse(0) + 1' As recurse(0) = 0 we have recurse(1) returning '0 + 1' = '1' recurse(2) therefore returns '1 + 2' = '3', which then again is used in recurse(3) and so on. This continues, so recurse(9) returns '36 + 9' = '45' And finally will recurse(10) return '45 + 10' = '55' But? won't it just continue? The answer is no. Remember that we ran the command 'p recurse(10)'? So when recurse(10) returns its value that is basically it. The value will be printed on the screen like when you normally use the 'p' and we're finished. I think this explains pretty well the idea behind recursion. The idea about solving a problem backwards. This problem can be solved in an iterative way. Here is a Ruby example of an iterative solution: #============================================================================== # ** Recursion 3 #------------------------------------------------------------------------------ # Same example some before. This time it is iterative. #============================================================================== class Recursion #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize p recurse(100) end #-------------------------------------------------------------------------- # * Recurse-method # # Will count the sum of the numbers 1..n iteratively #-------------------------------------------------------------------------- def recurse(n) result = 0 for i in 1..n result += i end return result end end You see that the method recurse do under any circumstances call itself. Instead the for-loop iterates 'n' times. For-loop? That is just the 'for i in 1..n' until end. Each cycle is an iteration. The first iteration is with i = 1, the next with i = 2 and so on. Iterations are very common. I am only mentioning iteration as opposed to recursion. It now happens that there is an even better way of calculation the sum of 1..n It can be done by this formula: ((n*n) + n) / 2 So all the classes I have here are basically good-for-nothing except for the purpose I have made them. They help you understand! The task: Reading is good, but alas reading alone is not as giving as task to follow up the read text. Here is the task for recursion: You must make a class with a method that gives the nth Fibonacci number. The method takes n as input. You can use the same style as I have used in the examples, but it is not necessary. What is necessary is that it is done recursive. You can also make an iterative solution. (Optional) What is Fibonacci numbers? The first Fibonacci number is 0 The second is 1 If n > 2 then the nth Fibonacci number is the (n-1)th Fibonacci number + the (n-2)th Fibonacci number. For example is the 3th Fibonacci number = 0 + 1 = 1 The 4th = 1 + 1 = 2 The 5th = 1 + 2 = 3 The 6th = 2 + ? And so on. Good luck with the task. - Zeriab Sources: Recursion @ Wikipedia - http://en.wikipedia.org/wiki/Recursion Introduction to Algorithms - http://mitpress.mit.edu/algorithms/ My head - Sorry, no link to my head
-
This is a lesson I wrote for someone called xLeD at a different forum, I'm now sharing it with guys :D Lesson 1 Today's topic: Simple Sorting Hey xLeD First of I will start with a little something I have written about Arrays. Just skip what you know. Then I will teach you the search algorithm Insertion-Sort. Insertion-Sort: Let A be an array. The pseudo code for the algorithm is: Insertion-Sort(A) 1 for j = 2 to length[A] 2 do key = A[j] 3 i = j - 1 4 while i > 0 and A[i] > key 5 do A[i + 1] = A[i] 6 i = i - 1 7 A[i + 1] = key Is it difficult to understand? You should note that pseudo code isn't just pseudo code. This is my version of pseudo code. Note that how much they are indented tells in which branch they are in. For example is line 7 not in the while loop, but in the for-loop. Line 6 is however in the for-loop. And so on? I know I haven't explained it well, and for that I apologize. I have saved it for the tasks. You'll see ^_~ The tasks: Reading is good, but alas reading alone is not as giving as tasks to follow up the read text. Task 1: A = [7, 12, 30, 12, 6, 29] Put this array into the algorithm. Calculate manually what A each time it is at the start of the for-loop. Also calculate the output. (The sorted array). Task 2: Implement the algorithm into RMXP. Yup write it in Ruby. Use the example from above to test. Task 3: Rewrite the algorithm so it sorts in decreasing order instead of increasing order. In Ruby I mean. Task 4: (optional) Make the insertion sort as an extension to the Array class. That is make a method insertion_sort that can be called like this: [7, 12, 30, 12, 6, 29].insertion_sort Good luck with the tasks. - Zeriab Sources: Recursion @ Wikipedia - http://en.wikipedia.org/wiki/Insertion_sort Introduction to Algorithms - http://mitpress.mit.edu/algorithms/
-
I have an idea, but we all must band together for it!
Zeriab replied to Leon's topic in General Game Development
This is a good idea. I have unfortunately not enough time to join, but I do wish you luck. @Leon: I can give you support on my own scripts if you decide to use any of them. -
Thanks all. @Leon: I will check them out @Wyrzd: Let's hope we will get to know each other now that I am back.
-
Hey all! I missed you all and I'm back again How have ya all been and what's happened while I was away? Dunno what else to say... - Zeriab
-
Don't worry SCMike. This has nothing to do with you. I don't care about you being bisexual. Anyway thanks for the nice goodbyes :) Don't have much else to say except I'll be back - Zeriab
-
It pains me to hear that Marked as resigned, but I am sure he has his reason. I hope he will stay around. On another note I congratulation you on becoming an administrator and wish you luck administrating RMXP Unlimited. I will let you know if I ever have comments and/or question :) - Zeriab
-
Just letting you know that I am leaving for a couple of weeks. I might be online for a short while tomorrow, but no promises. If not: See you all in a while! - Zeriab
-
Some spam are to be expected <_< For some weird reason I don't think I will win. Wonder why... XD
-
Welcome Cornetto ^_^ I'm Zeriab. Pleased to meet you.
-
Heh, nice idea. I'll start by posting the probably least messy desktop. Yes, this IS actually how it looks like. Just to make sure there's at least one participant :rolleyes:
-
Everything you need to know about: The Event Editor
Zeriab replied to Marked's topic in Forum Archive
Good and visual description. I think beginners will find this helpful Great job! -
[XP] How to make an RMXP Expansion Pack
Zeriab replied to EmilyAnnCoons's topic in Archived RPG Maker XP Tutorials
Good tut. I found it easy to understand. Great job writing it :rolleyes: -
I guess you talk about the script by mewsterus I'm not sure what you mean by the complete version though. Anyway you can find the script here: http://www.rpg-palace.com/scripts/mode07.php
-
Congrats! Let's hope the next 1000 posts will be as informative as ever, or better
-
The majority part of it, yeah. I got help with making from various people submitting questions and answers. I edited the submitted materials until I thought it fitted. I have not written it all at once though. The first version came about a month ago.