Maph 0 Report post Posted January 8, 2008 All right! Apparently not everyone can fully understand Leon's tutorials about scripting in RGSS, and remain lost on the subject, probably abandoning scripting all together. This tutorial is for people to understand the basics of scripting and programming in general. I hope that this will allow the users of the board to properly use the resources that Leon has so kindly provided. First I must warn you that I'm no good at this kind of thing, but here it goes. Now I'm going to try and ignore the stuff you don't need, the difference between a high level/low level programming language etc, and get straight into what you'd need for actually writing something useful. I'll start with the most basic tool of any program, the algorithm. Now, I'm sure a lot of people out there don't really know what it means, but don't let this scare you away.Allow me to explain as best as I can. An algorithm is a set of exact instructions to be carried out that must end in a finite amount of time. Something that loops on forever is not an algorithm. The same goes for something that has vague instructions. Most recipes would be considered algorithms because they usually have exact measurements of quantity and time, and don't go on forever. Algorithms are basically the heart and soul of a program/script. A computer needs exact instructions because it can not think on it's own. Next I'll talk about pseudo-code. Now pseudo-code isn't really important unless you're trying to quickly convey what you're trying to do with a program, or you're trying to communicate your code to people who may not have much programming/scripting experience (my target audience). Pseudo-code isn't a real language, it's just a quick sloppy way of making something that looks like a language, but without worrying about all of the specifics and notation. The examples I give will be in pseudo-code so that it will be easier to convey my points. I've decided to also put up an actual code version of the code. They will be encased in a pair of []'s. If you don't understand exactly what's going on with the real code, try and have a look at Leon's stuff, if you're still stuck PM me. Let's start with something simple. We want something that will make the words "Good morning" pop up on screen. The algorithm for that would simply be print "Good morning" [class Printtest def initialize print "Good morning" end end] "print" is a common command among languages which just tells the computer to put whatever's after it on screen. I am not entirely familiar with the semantics (the meaning of commands and symbols) of RGSS, so I highly recommend that you don't try using any of the commands that I'll be showing you in RGSS, as they may not exist in the language, or may do something else entirely. As you can see there isn't anything ambiguous about the above algorithm. It's just one simple instruction. Basically, a program or script is just a ton of simple instructions, all working together (or if you're a bad code writer against each other). Now I'll explain a powerful tool, the variable. When you think variable try to remember back to math, and algebra. You have X's and Y's, and Z's etc etc. In class you'd have to toy around with the equation to find out what the variable's value is. In scripting languages you can assign variables and use them as you like with a simple "=" sign. For exampe. Tofu=6 Now whenever you use your newly defined variable "Tofu" it will substitute in the value 6. So if we were to put in print Tofu it would print out a 6. The whole code would be Tofu=6 print Tofu [class Tofu def initialize @tofu=6 print @tofu end end] Also I'd like to point out that in the first example there were " " around Good morning. This is because "Good morning" wasn't defined as a variable. If you left out the " " the computer would look for what Good morning was supposed to mean, then give you an error. For my second example to work both lines would have to be in the same program/script in order to work, otherwise it wouldn't find Tofu. To learn about the specifics of variables in RGSS I suggest you look at Leon's tutorials. http://www.rmxpunlimited.net/forums/index.php?showforum=96 You should notice that the way his stuff is written out is different than mine. He's giving examples in actual RGSS. So if you're confused about which to actually use, use his. I'm just here to try and explain the basic concepts so that you can better understand his stuff. I'll just re-iterate what Leon said on commenting In RGSS you use the "#" symbol to indicate that whatever follows it on that line is a comment. Comments are there to help you, and others, organize and understand your code. If you want large chuncks of comment you can use "=begin" to start the comment section, and "=end" to end the comment section. Anything found in between those two will not have any effect on the code. I cannot stress enough the importance of commenting and good format. Without them it's very easy to get lost in your own code. On to the basic format. If you're unfamiliar with scripting and you look at one, it may seem like they have indiscriminant symbols, and indentation flung around. This isn't the case. As I explained earlier a programming language has to be very exact, so there are many little rules that help the computer figure out what you're trying to tell it to do. Let's go back to our little tofu code. class Tofu def initialize @tofu=6 print tofu #You can use "p" in place of "print" to save time. end end If you notice I added a little comment there. Anyway, first we have our "class" (see Leon's tut) Next is a common piece in programming languages the "def" function "def" basically just says "The thing that comes after me on the same line is the name of our new function, and everything below (up until the "end" tag) is what the function actually does." The next part "initialize" I must say I'm not sure why you need it, but apparently the first function (referred to as a "mod" in RGSS) in a script needs to be called "initialize" in order to get the whole thing to start. I don't think this is the case if the method, or class is called from another method. Which brings me to my next topic Calling a function/class/method In a class, or one of your defined methods you can actually execute another mod (I'm not sure about other classes, ask Leon). This is done simply by typing out the method's name. Let's rename "initialize" class Tofu def tofu2 @tofu=6 p @tofu end end So now we have a method named tofu2, but there's nothing telling it how, or when to start. To fix this we'll write another method in the same class. We'll put it above tofu2 class Tofu def initialize tofu2 end def tofu2 @tofu=6 p @tofu end end So basically this does the same thing as our first one, but now we've called "tofu2" using another method instead of having to call it initialize. In the event manager you can call a class by typing "Class name".new when you select the "Script" option on page 3. Anyway that's all for now. Don't worry there's more where that came from, and I'll be updating this sucker, probably daily. Leave feedback, let me know if this is helping a little, and if you'd like me to continue. Credits to Deryk Barker. Share this post Link to post Share on other sites
Marked 197 Report post Posted January 8, 2008 Moved to RGSS Tutorials. This is a good tutorial, you may want to use the code tags for the parts that are actually code to make it a little easier to read. Share this post Link to post Share on other sites
Maph 0 Report post Posted January 8, 2008 If you think so. I was avoiding it so as not to tread on Leon's territory, but if you think it will help over all then I can certainly do that. I think I'll write a pseudo-code and a RGSS version for each of the codes. All right, first major edit is up. Sorry guys I accidentally referred to methods as mods. I'm pretty sure I caught all of the mistakes. Share this post Link to post Share on other sites
Marked 197 Report post Posted January 9, 2008 If you think so. I was avoiding it so as not to tread on Leon's territory, but if you think it will help over all then I can certainly do that. I hope you are not talking about Code tags... everyone on every forum uses them. Share this post Link to post Share on other sites
Maph 0 Report post Posted January 9, 2008 Well then that's my fault for not knowing my audience very well. It's been my experience that most people shy away from scripting entirely. Well I'll just throw what I know up there, and hopefully it'll allow people to better understand Leon's tuts. Share this post Link to post Share on other sites
Leon 55 Report post Posted January 9, 2008 Well, treading on my turf won't be a problem. My land is open to all those who tread. In other words, I don't mind more scripting tutorials. If it better teachs, let it. Share this post Link to post Share on other sites
Maph 0 Report post Posted January 10, 2008 All right then. I'll try and make it a little more complete then. Share this post Link to post Share on other sites
Trickster 1 Report post Posted January 11, 2008 I found a little mistake class Tofu def initialize @tofu=6 print tofu #You can use "p" in place of "print" to save time. end end tofu needs to be @tofu Share this post Link to post Share on other sites
Maph 0 Report post Posted January 12, 2008 Yes indeedy. It's all fixed now thanks for that. Hopefully I can find time to update this a bit more by Monday. Share this post Link to post Share on other sites
Swift 0 Report post Posted September 21, 2008 Sweet, thanks for the Tut! Share this post Link to post Share on other sites