- 312
- Posts
- 17
- Years
- Seen Jul 16, 2023
Hi there! My name is Lorem Ipsum, and I am going to give you a few tutorials about the world of RGSS scripting, and its origin, Ruby. There is no need to have any prior scripting knowledge at all, all you need is a mind ready to learn.
Ruby
RGSS stands for Ruby Game Scripting System, so, obviously originates from the coding language Ruby. Ruby is easy to learn, and is useful in lots of other places, such as CGI web coding. But for now, we are going to concentrate on the much compressed language of RGSS, which RPG Maker XP decided to use in their system. First, however, you will need a bit of background on how everything works.
Your first RGSS Script
Now, in RGSS, there are a few basic commands that can be utilised to make powerful game engines. We will start with the most basic of them all, the code that will simply print something on your screen. That script is called print. With print, all you have to do is put in a space after the words, and put exactly what you want to be placed on the screen in between single or double quote marks. Here is an example:
You could put that in a script event box on the map. But for larger scale scripts, this is impractical, so we call on the Script Editor, which can be accessed by pressing F11. So, with that in mind, scroll down to the script called "Main", and right click on it. In the menu that you see, click on "Insert". You now have a blank script page. But before we are ready to code, we still need to know two more things about RGSS. These are the class and the def commands. The class command is used to start a script, and is what we rely on when we need to call it in an event. The def command is used within the class, and is used to define different sections of code. That's what def means; define. To make class work, you must give it a unique name, and to make def work, you give it the attribute "initialize" if it is the script that will be the main one, or name it what you like if it is not. We will just be using "initialize" in most cases today.
Now we are ready to script. Name your script in the bottom left hand corner, and then turn your attention to the massive box on the right of the screen. This is what we type the script in. Now, we start off with a class, as that is what starts a script in most cases. We are going to call it "Hello", as this is what we are going to make the script do, say hello. So, in the code, you should have this:
If not, rectify your mistake, and take note of it.
Next, we need to add the initialize attribute, so we press return twice, and type in def intialize (note that the return key-ing isn't compulsory, just makes your script neat and easy to read.). After that, we're going to use "print" to type in the message that is used throughout by coders testing a new language. So, press return once more, so you are on a new line, and then type in print "Hello World!".
That is your main method. It is in def initialize, so that is what will be intialized and outputted. Finish the class and def by pressing return and typing end for the def, and then pressing return and typing end for the class. This should be your script:
Eventing the Script
Brilliant! Now, all you need to do is call it in an event. So, press OK at the bottom of the script editor, and then exit, and create a new event on your map. All you need to do to call a simple script like this is take the name of the class (in our case "Hello"), and put .new after it. For you, it will be "Hello.new". Press OK, and playtest your game. Go over to the place or character where your script is, press the action key, and voila! A popup on your screen should say "Hello World!" click OK, and relish in your scripting supremacy. You have just coded your very first RGSS script. Give yourself a pat on the back.
Troubleshooting
If any problems arise, just post a note in this thread, and I will try to see what is going on. Be sure to copy and paste the code in your script editor between
tags so I can see if you have made any errors.
In conclusion
So, have a good think about this, and return soon to my RGSS tutorial, where next time, we will be learning about attr_accessors and their power to change games. Thank you for reading and participating, goodnight.
(Mods and admins, if this isn't in the right place, or you don't want it here, just give me the say so/and or remove it. Thanks, Lorem Ipsum)
Ruby
RGSS stands for Ruby Game Scripting System, so, obviously originates from the coding language Ruby. Ruby is easy to learn, and is useful in lots of other places, such as CGI web coding. But for now, we are going to concentrate on the much compressed language of RGSS, which RPG Maker XP decided to use in their system. First, however, you will need a bit of background on how everything works.
Your first RGSS Script
Now, in RGSS, there are a few basic commands that can be utilised to make powerful game engines. We will start with the most basic of them all, the code that will simply print something on your screen. That script is called print. With print, all you have to do is put in a space after the words, and put exactly what you want to be placed on the screen in between single or double quote marks. Here is an example:
Code:
print "Hello World!"
You could put that in a script event box on the map. But for larger scale scripts, this is impractical, so we call on the Script Editor, which can be accessed by pressing F11. So, with that in mind, scroll down to the script called "Main", and right click on it. In the menu that you see, click on "Insert". You now have a blank script page. But before we are ready to code, we still need to know two more things about RGSS. These are the class and the def commands. The class command is used to start a script, and is what we rely on when we need to call it in an event. The def command is used within the class, and is used to define different sections of code. That's what def means; define. To make class work, you must give it a unique name, and to make def work, you give it the attribute "initialize" if it is the script that will be the main one, or name it what you like if it is not. We will just be using "initialize" in most cases today.
Now we are ready to script. Name your script in the bottom left hand corner, and then turn your attention to the massive box on the right of the screen. This is what we type the script in. Now, we start off with a class, as that is what starts a script in most cases. We are going to call it "Hello", as this is what we are going to make the script do, say hello. So, in the code, you should have this:
Code:
class Hello
Next, we need to add the initialize attribute, so we press return twice, and type in def intialize (note that the return key-ing isn't compulsory, just makes your script neat and easy to read.). After that, we're going to use "print" to type in the message that is used throughout by coders testing a new language. So, press return once more, so you are on a new line, and then type in print "Hello World!".
That is your main method. It is in def initialize, so that is what will be intialized and outputted. Finish the class and def by pressing return and typing end for the def, and then pressing return and typing end for the class. This should be your script:
Code:
class Hello
def initialize
print "Hello World!"
end
end
Eventing the Script
Brilliant! Now, all you need to do is call it in an event. So, press OK at the bottom of the script editor, and then exit, and create a new event on your map. All you need to do to call a simple script like this is take the name of the class (in our case "Hello"), and put .new after it. For you, it will be "Hello.new". Press OK, and playtest your game. Go over to the place or character where your script is, press the action key, and voila! A popup on your screen should say "Hello World!" click OK, and relish in your scripting supremacy. You have just coded your very first RGSS script. Give yourself a pat on the back.
Troubleshooting
If any problems arise, just post a note in this thread, and I will try to see what is going on. Be sure to copy and paste the code in your script editor between
Code:
In conclusion
So, have a good think about this, and return soon to my RGSS tutorial, where next time, we will be learning about attr_accessors and their power to change games. Thank you for reading and participating, goodnight.
(Mods and admins, if this isn't in the right place, or you don't want it here, just give me the say so/and or remove it. Thanks, Lorem Ipsum)