• 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 2 in RGSS

Status
Not open for further replies.
664
Posts
16
Years
  • Ok, so we've learnt about printing and declaring variables, and you may have learnt about the different types of variables. Just make sure you've read Lesson 1 first! So now onto the next lesson.
    The structure of a class.

    Let's jump straight in shall we? But first remember to make your Lesson 2 script section won't you.

    Code:
    class Class_Badger # Line 1
      def method_one # Line 2
      end # Line 3
      
      def method_two # Line 4
      end # Line 5
    end # Line 6

    Alright lets go with the explanation.

    Line 1

    The word "class" tells the game that we are writing a new class, and the class name here is Class_Badger. We must have a name for the class, otherwise we wouldn't have anything to call in the game would we? (More on calling later).

    Line 2

    The word "def" shows that we are writing a method, and the method name in this case is method_one. You must have a name for a method otherwise there is nothing for it to run, and it will probably cause errors.

    Line 3

    The word "end" tells the game that we have finished writing that method and we can move onto the next one.

    Line 4

    The next method

    Line 5

    Ends the second method

    Line 6

    This "end" is special because it ends the class and tells the game that there is nothing else in this class and to stop the process of running it.

    So that's the basic structure of a class. But it is basic. So let's add some padding.

    Code:
    class Class_Badger # Name of the class
      def initialize # The initialize method. If that isnt there, nothing works
        @badger = 'Badgers Rule!' # Stores a value in the variable @badger
        badger2 # Calls the next method
      end # Ends the method
      
      def badger2 # The method we just called
        p @badger # Print the variable we declared earlier
      end # Ends this method
    end # Ends Class_Badger

    I've added some comment lines to explain it all as this is pretty easy and we've done it before. (The variables and printing.) Always remember to indent (RMXP does it for you) because it will be easier to understand in big scripts.

    Ok, so if you put that script section into the Lesson 2, everything should be fine right? Wrong. To see the effects of this script you have just written, you need to create a new event on a map, and set the starting party position to that map. Ok, in the event you have just created, give it a graphic or sprite so you can see where it is. Double click on the character you have just made on the map, and double click the @> in the big white space to the left. Navigate yourself to the third page of the popup and choose Script... at the bottom. In the popup that...well...pops up, type in Class_Badger.new This shows the game that we want to call a script section. So for any other class that you write, to call it, it will be Class_Name.new Then run your game and go up to the character and press the spacebar. Look! The popup said badger!

    Congratulations! Your first working class!

    But that's not all for this lesson. Just to check if it's all sunk in, i want you to write me a class, below are the things you have to do.

    Homework!

    Create a class called Class_Yourname (Yourname being your name obviously).

    The class needs to have two methods, the first one being the 'def initialize' one.

    In the initialize method, declare 2 variables and store them in another.

    In the second method, print the 3rd variable (The one with the two variables stored inside).

    End the class and hand me in your homework here to this thread.

    Until the next lesson!
    - Crazyninjaguy ^^
     

    PokemonPlatnum

    nomnomnom.
    257
    Posts
    16
    Years
  • Code:
    class Class_PokemonPlatnum
      def initialize 
        @pokemon = 'so '
        @platnum = 'cool :)'
        pokemonplatnum2
      end
      
      def pokemonplatnum2 
        p @pokemon+@platnum
      end 
    end
    My Homework :L
     
    664
    Posts
    16
    Years
  • RGSS stands for Ruby Game Scripting System which is what RMXP uses.
    RGSS is an API for Ruby, so learning RGSS is sort of learning the basics of RUBY too.

    @PokemonPlatnum, nice work ;)
     

    KingCharizard

    C++ Developer Extraordinaire
    1,229
    Posts
    14
    Years
  • RGSS stands for Ruby Game Scripting System which is what RMXP uses.
    RGSS is an API for Ruby, so learning RGSS is sort of learning the basics of RUBY too.

    @PokemonPlatnum, nice work ;)

    I understand that but when it really comes down to it your writng scripts in RUBY. However Learning RUBY is more of a smarter way to go because its a programming language and can be used for web programming... Anyways Great tutorial way to help out everyone lately keep up the great work... I like reading your topics.
     
    664
    Posts
    16
    Years
  • I understand that but when it really comes down to it your writng scripts in RUBY. However Learning RUBY is more of a smarter way to go because its a programming language and can be used for web programming... Anyways Great tutorial way to help out everyone lately keep up the great work... I like reading your topics.

    True true.
    When i started scripting, i had no idea it was based on ruby lol, last year around september i decided to learn a bit of ruby to help myself write cleaner scripts, and it paid off :)

    Thanks :D
    Good to know that people appreciate it :D
     

    Time Shift Dialga

    Son of a Pachizel!
    44
    Posts
    15
    Years
    • Seen Oct 1, 2011
    I'm going to look like a complete idiot for this, and I bet the solution will be obvious xD

    Here I go:

    Apparently I have a syntax error on line 23 - I checked it, replace p with print, reverted it...nothing worked, here's the code (Oh gawd, I'll open a shop Homework Extensions 'R' Me =P)

    Code:
    #############################################################################
    #This is my simple demo script involving CLASSES and VARIABLES              #
    #############################################################################
    
    class Basic_Script
      def initialize
        @me = 'I am'
        variable2
      end
      
      def variable2
        @metwo = 'starting to understand.'
        merging_variables
        
        def merging_variables
          @full_script = @me + @metwo
          final_result
        end
       
        def final_result
          p @full_script
        end
        end

    Okay, that set aside, I've tried several guides, not understanding much other than print (I knew a little bit of BASIC, not much, but enough to aid knowledge of languages such as this ^-^ Also, I am aware that that's programming and this is scripting BUUUUT...).
    However I come and read this and understand it right down to the full stop.
    Excluding my seemingly random error I think I've done fine.

    Thanks for this, it really does help!

    EDIT:

    This is line 23 (No need to count xD)
    Code:
     p @full_script
     
    Last edited:
    664
    Posts
    16
    Years
  • Yup, the solution is really obvious :D

    You forgot to end the variable_2 method :P
    Once you've ended it it should be fine :)

    Remember, if there's a syntax error on the last line, you haven't ended something properly.
     

    Time Shift Dialga

    Son of a Pachizel!
    44
    Posts
    15
    Years
    • Seen Oct 1, 2011
    Oh...right, thanks!

    I thought it might have been something to do with how I put the other two variables into that one...*places dunce's hat on head* :P
     

    Missingno.7-4468

    The Kazuka Party is for curry!
    513
    Posts
    15
    Years
  • I am a sucker for tuts.

    Code:
    class Bibarels_Are_Awesome
      def initialize
        @Bibarels = 'Bibarels are awesome'
        talkin
      end
      def talkin
        @K = ' Okay?'
        bout
      end
      def bout
        @Awesomeness = @Bibarels + @K
        bibarel
      end
      def bibarel
        p @Awesomeness
      end 
    end

    Anyway, I really wanna learn this, and presently, it doesn't seem as hard as it did when I first hear about this(Oh so long ago)
     

    nmorr

    Takin a brake. -_-
    214
    Posts
    15
    Years
  • My Homework

    Nvm, here's my homework.

    class Class_Testing # Name of the class
    def initialize # The initialize method. If that isnt there, nothing works
    @Testing = 'Testing...123...Hope this works.' # Stores a value in the variable @badger
    testing2 # Calls the next method
    end # Ends the method

    def testing2 # The method we just called
    p @Testing # Print the variable we declared earlier
    end # Ends this method
    end # Ends Class_Badger

    I fixed my prob. from before if anyone read the message.
     
    Last edited:
    Status
    Not open for further replies.
    Back
    Top