Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> [Scripting][Series]The Scripter’s Journey Series, 7. The World of Modules!
The Law G14
post Aug 16 2012, 04:23 PM
Post #1


Scripter FTW
Group Icon

Group: Local Mod
Posts: 1,348
Type: Scripter
RM Skill: Skilled
Rev Points: 5




The Scripter’s Journey Series

7. The World of Modules!


Table of Contents
I. What are Modules?
II. Namespaces!!
III. Mixins!!
IV. Conclusion!


What are Modules?
Alright, what are modules? Modules are like an organized interface or common area where you can store methods and constants to use later in your program. What do I mean by this? Think of modules like toolboxes, where they have extra “tools” (constants and methods) you can use to build your house (program). They serve two key roles: creating a unique namespace and allowing mixins with classes.


Namespaces!!
So…what’s a namespace? First of all, let’s first understand that Modules house two things: constants and methods (remember we learned what constants were last tutorial). Now, you’re probably wondering why there are only constants and not other types of “variables” like in classes…this is because modules do not create a new “type” like classes or can be inherited. You cannot make “instances” of a certain module like you can for classes. I want this to be ingrained in your head, modules are like “toolboxes” and can be used to easily add on to your program while classes are organized data types that can allow instances of this new type. So, with that out of the way, let’s go over namespaces.

Basically, namespaces allow you to create names of methods and constants without worrying that you may have naming conflicts. For example, let’s say you have two constants that both have the same name, but deal with two different things…like “ALLIANCE”, one constant refers to the Enemy Alliance (Evil), and the other refers to the Actor Alliance (Good). If you just go ahead and create two constants with the same name, this will cause problems. So, you can create two modules, one being a “toolbox” that contains basic actor information, and the other being a “toolbox” for basic enemy information:

CODE
module Actor
ALLIANCE = “Good”
def Actor.equip
#blah
end
module Enemy
ALLIANCE = “Evil”
def Enemy.gear
# Stuff
end
end


See? Now, notice something else I did in this module, I demonstrated how you would make your own methods. It’s the same way as making class methods in a class. Moreover, like I said, modules are like “toolboxes” and add on to the program…thus, modules and their contents can be used anywhere. Here’s how you would access a module’s contents:

CODE
# inside some random script
print Enemy::ALLIANCE
print Enemy.gear


And there you have it on namespaces! Next, mixins!


Mixins!!
Mixins means the idea of embedding a module into a class, or basically adding all the methods and constants of a module…and pouring it into a class for it to use freely. To do this, you must use the “include” keyword. Check out the following example:

CODE
module Actor
ALLIANCE = “Good”
end
class Game_Actor
include Actor
def initialize
print ALLIANCE
end
end


Notice that by using the “include” keyword, we no longer need to do something like this “Actor::ALLIANCE” but simply “ALLIANCE” because it’s essentially part of the class now. Get it? You can “include” as many modules as you like, thus “mixing it in!” Also, if you’d like to see some example in RMXP, for example, go to the help file and search up “String”, you’ll see under “Included Modules”, Comparable and Enumerable! You can check out those modules for yourself, but that’s just to show you some real examples!


Conclusion
Lol well that really short! But Modules are really important and plus I thought it would be good to have a breath of fresh air with this smaller tutorial verus last tutorial which was a moutfull. Anyway, like always, if you have any questions, concerns, or just feel like commenting, post! Thanks again and be back next! (Not sure what topic to go over next…but yea!)

The order of how these tutorials will progress: http://www.rpgrevolution.com/forums/index....showtopic=54953

~Law


__________________________

To put in sig, copy this link:
CODE
[url="http://www.rpgrevolution.com/forums/index.php?showtopic=51540"][img]http://img40.imageshack.us/img40/6504/conceptthelawbanner.png[/img][/url]


Sig Stuff


"When you first come, no one knows you. When help them out, they all know you. When you leave, they all love you. When you come back, they've already forgotten you." -- copy into your sig if you think this quote speaks true!

If you are one of the very few teenagers that know what real rap is and don't blindly listen to the hate statements (rap is crap), then put this in your sig. I say this in the name of Common, Mos Def, Lupe Fiasco, 2Pac, Nas, Talib Kweli, Eminem, and many others. -Exiled One

My Project Thread: Gai's Hunters


Go to the top of the page
 
+Quote Post
   
Legacy
post Aug 17 2012, 07:56 AM
Post #2


B★RS Coding Ninja
Group Icon

Group: Global Mod
Posts: 1,414
Type: Scripter
RM Skill: Advanced
Rev Points: 15




This is a great series Law, loved reading it and I know it's going to help a lot of people starting out. happy.gif


__________________________
Freelance Programmer (C#, C++, Ruby)
#onegameamonth

Go to the top of the page
 
+Quote Post
   
The Law G14
post Aug 17 2012, 01:49 PM
Post #3


Scripter FTW
Group Icon

Group: Local Mod
Posts: 1,348
Type: Scripter
RM Skill: Skilled
Rev Points: 5




Hey, thanks a bunch man! I really appreciate it smile.gif Any suggestions for future tutorials?


__________________________

To put in sig, copy this link:
CODE
[url="http://www.rpgrevolution.com/forums/index.php?showtopic=51540"][img]http://img40.imageshack.us/img40/6504/conceptthelawbanner.png[/img][/url]


Sig Stuff


"When you first come, no one knows you. When help them out, they all know you. When you leave, they all love you. When you come back, they've already forgotten you." -- copy into your sig if you think this quote speaks true!

If you are one of the very few teenagers that know what real rap is and don't blindly listen to the hate statements (rap is crap), then put this in your sig. I say this in the name of Common, Mos Def, Lupe Fiasco, 2Pac, Nas, Talib Kweli, Eminem, and many others. -Exiled One

My Project Thread: Gai's Hunters


Go to the top of the page
 
+Quote Post
   
MagitekElite
post Aug 18 2012, 06:20 PM
Post #4


Level 42
Group Icon

Group: Revolutionary
Posts: 1,138
Type: None
RM Skill: Skilled




Yes, it certainly will help. biggrin.gif

I have seen the updates, but I never had time to comment on them--mostly because I didn't make it to that lesson yet. I was busy this week so I couldn't sit down to try it (and am still looking for an editor that will work), but after I get home on Monday I'm gonna sit down for it. smile.gif

Go to the top of the page
 
+Quote Post
   
Shaddow
post Sep 2 2012, 11:15 AM
Post #5


The Eventer Inventor
Group Icon

Group: Local Mod
Posts: 1,250
Type: Event Designer
RM Skill: Masterful
Rev Points: 90




Thanks, Professor Law, this really helped me get started on learning how to script. While it was a long read and a lot of information, you made it fun to read and informative.

One thing I'd like to see is maybe some 'homework assignments' maybe some simple script types for people to practice what you've taught them. For a hands on learner like myself, nothing could be more useful.


__________________________




I support these projects! -------------





Go to the top of the page
 
+Quote Post
   
The Law G14
post Sep 3 2012, 05:02 PM
Post #6


Scripter FTW
Group Icon

Group: Local Mod
Posts: 1,348
Type: Scripter
RM Skill: Skilled
Rev Points: 5




Thanks man smile.gif I'll get right into those homework assignments. The reason I didn't do any for these tutorials are because they are more fundamental type tutorials. This was the last tutorial of the "Beginner Syntax" block. However, my next post will be a homework assignment that synthesizes all the information learned from this "Beginner Syntax" block. From here on out though, there should be a homework assignment with each topic since were now entering "Advanced Syntax". I'm a hands on learner as well so I know how you feel, I'll get down to these assignments, you can count on me biggrin.gif


__________________________

To put in sig, copy this link:
CODE
[url="http://www.rpgrevolution.com/forums/index.php?showtopic=51540"][img]http://img40.imageshack.us/img40/6504/conceptthelawbanner.png[/img][/url]


Sig Stuff


"When you first come, no one knows you. When help them out, they all know you. When you leave, they all love you. When you come back, they've already forgotten you." -- copy into your sig if you think this quote speaks true!

If you are one of the very few teenagers that know what real rap is and don't blindly listen to the hate statements (rap is crap), then put this in your sig. I say this in the name of Common, Mos Def, Lupe Fiasco, 2Pac, Nas, Talib Kweli, Eminem, and many others. -Exiled One

My Project Thread: Gai's Hunters


Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th June 2013 - 06:21 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker