While I don't know everything about rgss, I'm getting better, and the biggest problem for me, was getting started. Every scripting tutorial I've ever seen started by explaining variables and things that, at first, don't seem important at all. I plan to make one that will get you started in the right direction so you're not stuck like I was. Everything I know about rgss will be in here, eventually, and I plan to update as I learn, to share my knowledge in a way that doesn't scare people.

OMG THIS IS SO CONFUSING WHERE DO I START!

Well first, calm down. It's actually pretty simple once you get the hang of it. If you already have experience in coding, awesome, you're already ahead of where I was when I started.

 

The first thing to remember, is that it's difficult to learn something if you have no use for it. First decide what you want to make for your game so you're not staring at a wall of text wondering what the heck it says for hours as you slowly go insane and eventually throw your computer out the window because you got frustrated.

 

The best way to start, is not to do that weird print variable stuff in most tutorials. You will have no need for it 99% of the time, and will only ever use it for debugging, if at all.

 

Polraudio and I both started with editing "Scene_End" and moved on to the rest of the menus.
Scene_End is that screen with the window that says "To Title", "Shutdown", and "Cancel" This is literally the most basic form of menu in the default scripts, and is what I will be talking about in step 2...


How do I Scene_End? [Def Main]

When making an edit to a script, make a copy, and place it below "Scene_Debug" and above Main (Yes, I know you've heard that before when using other people's scripts) The reason for this, is that the program reads the scripts in the order they are in the script editor, and anything after main is completely ignored.

 

Since your version of "Scene_End" is at the bottom, it will be overwriting the original. Why? Because it is the same class, (like having two files with the same name, but keeping both) unless you know what you're doing, "Class NAME_OF_CLASS" should be first on all scripts, except for comments, which can be anywhere.
by the way, comments are made with a "#" they are good for separating your scripts into sections.

 

the first part after the class is named, is "def main"
this basically means "define main" and is how many scripts start. others start with "def initialize", but follow with "def main"
It's difficult to explain, but it is basically defining a variable...well...more of a command.
Here's what the def main stuff means in this script:


How do I Scene_End Part 2: def update

def update is pretty simple.
it defines the command "update" which was used earlier in the loop that was in def main.

what I call "defs" are needed to tell the game what to do with things that aren't built into the program.
DO NOT CALL THEM "DEFS"

 

not getting it? don't worry, the actual edits are coming soon.


How do I Scene_End Part 3: The actual options


by the way, it's possible to use =begin, and =end to make long comments instead of starting every line with a "#"
for example:

=begin
super long description of script.
=end


Example of a basic text window

Now for actually making windows. You know how to add them right?
just use

@my_window = my_window_class_name.new

 

well the code for making the window itself is pretty simple, as long as you don't want to add something crazy to it.
here's a basic text window:

#==============================================================================
# ** Window_Gold
#------------------------------------------------------------------------------
#  This window displays amount of gold.
#==============================================================================

class Window_Text < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 160, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.font.size = 22
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, 160, 32, "Look at me! I'm text!")
  end
end
Once you add that that above your edited Scene_End, and add this below "@command_window.y = 240 - @command_window.height / 2" in Scene_End
@text_window = Window_Text.new
@text_window.x = 0
@text_window.y = 0
which tells the game to put the window in the upper left corner when Scene_End is called
(which is when another scene says "$scene = Scene_End.new" if you didn't catch that)

 

the window should look like this:


How do I window?

Windowing is pretty easy and, as you can probably tell, the text window above is based off of the gold window, and I forgot to change the comment at the top. I do that a lot, since I already know what the script does, and took that one from my project and edited it.

 

you if you didn't catch my mistake: But wait! When I exit the end menu, the text window you made is still there!
Do you know what this means? It means I forgot something. Remember the ".dispose", and ".update" things in Scene_End? Well, where you see those, just add "@text_window.dispose" and "@text_window.update" respectively.

 

Here's an explainy version. of the little text window I made. This one is twice as wide by the way.

so what's self.contents?
well first of all, "self" ...do something with the current object?
".contents" do something with the contents of the current object

 

now what about displaying text as a variable?
well, replace the text with something like "$game_party.gold.to_s"
now it will display how much money the play has.
by the way, you can use variables and commands alongside numbers to make things bigger or smaller
depending on their contents. Try making a window that is always a perfect square, no matter what the
width is.
Oh, and .to_s converts a variable to a string. It's not always necessary, but it prevents complications with some scripts, and should fix the "cannot convert nil to string" errors you might get.

 

And making a location window is easy. Just add:

  def data
    data = load_data("Data/MapInfos.rxdata")
  end
above def initialize, and replace the text with:
data[$game_map.map_id].name


What do all these scripts do? And where can I find other commands and variables?

Game_Temp:
Where instance variables and things that aren't saved in a save file are made
@ means defines an instance variable. I'm not completely sure how it's used, though.

 

Game_System:
This class is used to define things like bgm_play, window_skin name, etc.
to use one of the commands in here, use $game_system.NAME_OF_COMMAND
for example:
$game_system.se_play($data_system.cancel_se) will play the cancel sound effect.

 

Game_Switches handles switches, of course. To use a switch in scripting, use $game_switches[i] = true/false
i = the switch number. This is useful when you need to turn on or off a switch using a script, instead of the event editor.

 

the same goes for Game_Variables, except variables can be anything from 0 to 908212098650476839570.

 

both game_switches and game_variables should be avoided when possible while scripting. It's best to use $variable_name = variable_value
they work better
these can have just about any value. true, false, nil, another variable, numbers, or text if you know what you're doing.

 

so guess what game_selfswitches does. Self Switches in events. I have never used these in scripting before though.

 

Game_Screen and Game_Picture should be easy to figure out now if you just look at the comments at the top

 

Game_Battler handles how battles work. the damage formulas are in Game_Battler 3 if you were wondering.

 

The rest should be pretty easy to figure out.
If you want to edit a window or scene, and dont know what to edit, pick one you think it might be, and change a number that will move something. and see what has changed.

 

Window_Base is where all your favorite window commands are defined.
you should define a command here if you want to use it in multiple windows

 

I like shortening things by do things like:

 

def DrawHPSP(actor, x, y)
draw_actor_hp(actor, x, y)
draw_actor_sp(actor, x, y + 64)
end

 

and the using "DrawHPSP(actor, 32, 32)"
to draw both the HP and SP at the same time.

 

and I like using @spriteset = Spriteset_Map.new
to show the map behind windows. treat it like a window too. put it in the same place as you would a
window, and add a @spriteset.dispose and @spriteset.update where necessary.
and use .opacity after .x or .y to make a window transparent
for example:

@gold_window = Window_Gold.new
@gold_window.x = 480
@gold_window.y = 224
@gold_window.opacity = opacity
this was taken directly from my game, and uses the variable I created called "opacity" so that I can change the opacity of all windows in the menu at once. above this is
"opacity = 190"
you can also just use "@gold_window.opacity = 190" but that's not as cool.


"Fun" with battle systems (And more about functions or whatever)

Don't know how the game calculates damage?
Found out how, but think it's stupid?
Or do you want to add a new stat to the battle system?
If you answered yes to any of those, then this step is for you!

 

Ok, by "fun" I meant math, but whatever.
to find where damage is calculated, go to Game_Battler 3
and scroll down to line 42
the commented lines above that are

#--------------------------------------------------------------------------
# * Applying Normal Attack Effects
#     attacker : battler
#--------------------------------------------------------------------------

 

This is where my tutorial gets complicated...
If you want to edit it, I suggest taking out lines 38-97, putting them in a separate script above main, and adding
"class Game_Battler"
to the top of the script.
This, as you may have guessed, will tell the program that anything written here will overwrite everything under "def attack_effect(attacker)" in the Game_Battler class
I'm not sure, but I have reason to believe "defs" are called functions...so let's call them that.
Anywho, the script overwrites only that function, because that's the only one you separated.

 

the default script says:
(with comments added by me)

 

It should be pretty straight forward from there if you know variables and can do equations and stuff.
It helps to use google and take a look at damage formulas for commercial game like Final Fantasy, Pokemon (It's really complicated...), and Disgaea (My skill damage formula is based on it)

 

The very next function in the same script is the skill damage formula.
The only *knew new information you should need is:
- skill.scope is the scope of the skill. (e.g. one enemy, all enemies, one ally, etc)
- skill.atk_f is how much the damage depends on the attacker's ATK stat. 0 is not at all. I usually set it to 0 or 100 (it's in the database by the way)
- attacker.atk is replaced with user.atk for some reason, and trying to use attacker causes problems.
- skill.power is the skill's power

 

*the difference between knew and new is not confusing, but my hands can't seem to figure it out...


The Correct Way to Mess with the Accuracy Formula

So...this part

hit_result = (rand(100) < attacker.hit)
and
# Second Hit Detection
eva = 8 * self.agi / attacker.dex + self.eva
hit = self.damage < 0 ? 100 : 100 - eva
hit = self.cant_evade? ? 100 : hit
hit_result = (rand(100) < hit)
Work differently than I thought. The good news is, though, you probably won't have to mess with it since the formula isn't that bad.

 

First of all:
hit_result = (rand(100) < attacker.hit)
This means, like I said, take a random number between 0 and 100. If it's less than the attacker's hit stat, then hit_result = true. To make it easier to understand, you can replace it with this:

if rand(100) < attacker.hit
 hit result = true
end
And it will do the same thing, but take up like 300% more lines.

 

The second part comes after the damage is calculated because it checks how much damage was done before it finishes deciding how much damage was done.
It will usually override what the first part decided

 

eva = 8 * self.agi / attacker.dex + self.eva
the variable "eva" is equal to 8 times the target's agi stat divided by the attacker's dex stat plus the target's eva stat. pretty simple.
so now we have a new variable that hasn't been called yet, just defined

 

next:

hit = self.damage < 0 ? 100 : 100 - eva
This is another shortened if statement. It means this:
if self.damage < 0
  hit = 100
else
  hit = 100 - eva
end
So now we know that the variable "hit" means the chance of the attack hitting, and eva means the chance of the attack missing. So this basically is telling the game that, if the eva is 60, the hit must be 40. If the eva is 90, the hit must be 10, etc.

 

It's also saying, in the same if statement, that attacks will always hit if they do no damage. So the player will see "0" instead of "Miss" If the attack did nothing, so they won't try whatever the did a second time.

 

And den:

hit = self.cant_evade? ? 100 : hit
This means this:
if the attack can't miss, then hit must be 100 (make sense to me)
if not, then hit = hit (so it doesn't change and is decided by what ever happened on the previous line.)

 

and this:

hit_result = (rand(100) < hit)
is where the game turns "hit" into a percentage.
if the random number between 0 and 100 is less than hit, than hit_result = true

 

Finally something makes sense here!


Go see part 2

http://www.gdunlimited.net/tutorials/t/rpg-maker-xp/beginner-039-s-guide-to-rgss-part-2

Share


About the Author

Comments

1,923 Posts
2,504 Points

Bob423  said 22nd September 2013

Added some things about the battle formula. Hope it helps.

1,923 Posts
2,504 Points

Bob423  said 9th October 2013

Added some information about the accuracy formula cuz I learned how it works *grin*

144 Posts
511 Points

Metaclaw  said 9th October 2013

you're right, 'def' means a function is beginning. 'end' means it ends.
it's short for 'define', as you're defining a new function.
so :
def collapse
end

 

means: define a new function called collapse

Guest_selebmemble said 22nd October 2015

oh M jay!
this is super helpful (I guess, haven't read everything). Anyway, getting back here as soon as possible. Thanks for being exist, and making this tutorial

Quick Reply

Guest

Enter a username

Security check: What is 8 plus 2?