• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Crazyninjaguy's Lesson 1 in RGSS

Status
Not open for further replies.
  • 664
    Posts
    16
    Years
    Heya, so this is my first lesson in Scripting RGSS for RPG Maker XP.
    RGSS Stands for Ruby Game Scripting System, just thought you should know that before we started. Although many of the commands in Pokemon Essentials are different because poccil completely re-wrote everything, this is a great starting point for you.

    Anyway, so in this lesson, we'll learn how to print and all about variables and how to set values and stuff.
    So on with the lesson.

    As a start, we'll learn how to print. Printing is probably one of the easiest things you can do in RGSS, it simply shows a pop-up box when ran with your text or variables inside.
    To print we type in the script editor:

    Code:
    p 'Badger'

    This will come up with a pop-up box above the game window, just saying Badger with a small 'OK' box.
    To put this in your game as a sort of reminder, open up your script editor in RMXP (RPG Maker XP) and right click the script right at the bottom called main, and click insert.
    Name this script section Lesson 1. We'll keep all the script sections organised as we go along to avoid confusion.

    Ok, so let's explain the command i just wrote.

    Code:
    p 'Badger'

    p = the print command, you can also use print but i use p as it's shorter.
    'Badger' = When you want to print text, be it in a pop-up box or in a window, you have to enclose it in quotes so that the game knows that it is text, and not a variable. The text inside the quotes can be whatever you want.

    To better understand what you are doing, and if you look back at your scripts later, it is always useful to use comments.
    Comments are ignored by the game but still remain in the script, they're sort of like notes. Anyway, here's an example of a comment line.

    Code:
    # I'm a useless comment line

    Ok let's explain this,

    # = The syntax to show the game that this is a comment line.
    I'm a useless comment line = Exactly what it says on the tin, but this text will not be shown anywhere apart from the script editor, as it has the # in front of it.

    So to put these two script sections together we would get

    Code:
    # I'm a useless comment line
    p 'Badger

    Now try running that by choosing test play in the main RMXP window. As soon as you start your game, you should get a little pop-up window saying Badger.
    Congratulations! You've just written your first script! It's not very impressive but it's a start.

    Now not only can you print text, but you can also print variables. A variable is something which you can store something else in, like a container. There are a few types of variables, but i'll explain about them later on. Now to declare a variable, we have to give it a name, you can call this whatever you want, but don't make it too complicated, you need to know the name isn't something random like BadgerWhaleChicken.

    Code:
    @badger = 'I like badgers!'

    That is how you store a value in a variable. Variables can not only store text, but they can store numbers, and even whole classes.
    Let's explain the code above.

    @badger = The variable's name, this can be called anything you like, but you need to remember it.
    = = The = shows that we want to store a value in a variable.
    'I like badgers!' = The value we have chosen to store in the variable, can be anything, just like printing.

    Now it's useless just storing a value in a variable and doing nothing with it, so we can print it for now.
    Put this is your Lesson 1 script section under the little bit we did before.

    Code:
    @badger = 'I like badgers!'
    p @badger

    Ok so there's your code, save that and do a test play. You should get a pop-up box as before that says "I like badgers!" or whatever you chose to put in your quotes.
    This is probably the simplest of the commands, and though the print command isn't used very often, if at all, storing data in a variable is something you will do almost all the time.

    You can also store other variables in variables, i know, crazy right? It's pretty simple though, all you do is this.

    Code:
    @bad = 'Bad'
    @ger = 'ger'
    @badger = @bad   @ger
    p @badger

    basically, we stored half the word badger in the variable @bad, and the other half in the variable @ger, then we stored both variables and in the variable @badger and printed it. To print two variables at once, we use the symbol. This shows the game that we want to print or store two things at once. If you put that in your Lesson 1 script, you'll see that because we stored both halves of the word, it printed both halves.

    So on to the different types of variables. There are 5 different types that you can use in a script, but you have to be able the correct one for what you are trying to do.

    Code:
    - local_variable
    -- A variable useable only inside a method, more on methods in the next lesson.
    
    - @instance_variable
    -- Useable throughout an entire class
    
    - @@class_variable
    -- Same as above
    
    - $global_variable
    -- Useable anywhere
    
    - Constant_Variable
    -- Exclusive to a class/module that never changes.

    So the variable that we stored data in earlier was an instance variable because we only wanted to use it in that class (More on classes later).

    So i hope that that was helpful, now you are on your way to becoming a great scripter! One thing i will add, is if you have an old schoolbook, preferably A4, rip out all the pages that have writing on them, and write down all the key things i am talking about in these lessons and you will be able to look back at your notes while scripting.

    Until the next lesson!
    - Crazyninjaguy ^^
     

    nmorr

    Takin a brake. -_-
  • 214
    Posts
    15
    Years
    Awesome tutorial! Thanks, I'll check the next one. (never knew you could make popup messages in RMXP).
     

    carmaniac

    Where the pickle surprise at?
  • 671
    Posts
    15
    Years
    You broke the rules... again...

    Edit:
    Me posting this is kinda breaking the rules to so sorry for mini modding.
     
    Status
    Not open for further replies.
    Back
    Top