Chaos Project

RPG Maker => RPG Maker Scripts => Topic started by: TheSquish on January 22, 2012, 02:10:54 am

Title: Need help: OMG modules!
Post by: TheSquish on January 22, 2012, 02:10:54 am
So I'm rather noob to RGSS and scripting in general.
I got the basics of windows and scenes but I'm really struggling with modules and how to manipulate/access the information in them.

For instance , this portion of a module included in RPG maker VX

module RPG
  class Actor
    def initialize
      @id = 0
    end
  end
attr_accessor :id
end


1. How do I overwrite/add to information in a module when I can't directly edit the module?
   Ex: Add the attribute weight to actors and items.

2. How do I know what can see a particular module and it's contents?
   Ex: I needed to alias a method in a module to use in Game_Battlers or sumthin...
        or
        I call a script in a debug menu that displays all the attributes of an actor defined in class Actors.


I've been trying to learn though trial and error but...yeah, thanks ahead of time.
Title: Re: Need help: OMG modules!
Post by: ForeverZer0 on January 22, 2012, 02:19:11 am
You can edit modules, you just need to access the classes they contain in the proper scope.

Here's an example:

module ExampleModule
 
  class ExampleClass
   
    def initialize
      @test = "This is a string
    end
  end
end


The following will cause an error:
myclass = ExampleClass.new


This will not:
myclass = ExampleModule::ExampleClass.new


Any class within a module is the same as any other constant. You need only access it using the "::" operator.

From here we can even alias it:
class ExampleModule::ExampleClass
  alias la_de_da initialize
  def initialize
    la_de_da
    p @test
  end
end


Now when you initialize the class it will print the string.
Title: Re: Need help: OMG modules!
Post by: TheSquish on January 22, 2012, 02:53:37 am
Oh thank you so much.
I'm go make some more noob attempts at scripting now.