Sunday 8 June 2014

Revisiting the past

I mentioned in the last post that I really started reading code (Ruby, anyway) through RPG Maker XP, or RMXP for short. The programs that followed, developed also by Enterbrain was RMVX and RMVXA (RPG Maker VX and VX Ace). Today, I decided to spend a short while in the afternoon to revisit that.

Lo and behold, a script among many others from the software default library:


#==============================================================================
# ** Scene_Save
#------------------------------------------------------------------------------
#  This class performs save screen processing. 
#==============================================================================

class Scene_Save < Scene_File
  #--------------------------------------------------------------------------
  # * Get Help Window Text
  #--------------------------------------------------------------------------
  def help_window_text
    Vocab::SaveMessage
  end
  #--------------------------------------------------------------------------
  # * Get File Index to Select First
  #--------------------------------------------------------------------------
  def first_savefile_index
    DataManager.last_savefile_index
  end
  #--------------------------------------------------------------------------
  # * Confirm Save File
  #--------------------------------------------------------------------------
  def on_savefile_ok
    super
    if DataManager.save_game(@index)
      on_save_success
    else
      Sound.play_buzzer
    end
  end
  #--------------------------------------------------------------------------
  # * Processing When Save Is Successful
  #--------------------------------------------------------------------------
  def on_save_success
    Sound.play_save
    return_scene
  end
end


Just earlier in the year, these words made very little sense to me. I used to just try and piece things together where I can and if I need to modify something, more often than not it's on a custom-made script by other programmers (who upload a free-use script for use in RPG Maker or sometimes commercial license required scripts) and they use Constants (Now I know the right term!) that users of the scripts are allowed to adjust according to the users' needs. But now, I can read the meat of the scripts very well!

Essentially, Scenes in RGSS (the name of RPG Maker's library for ruby) refer to windows that players will be seeing in the game - which are classes. In this case, Scene_Save refers to the save game screen when players want to save their game. And now, I can break this down bit by bit.

Scene_Save is a class, and it inherits Scene_File class (Makes sense, because Scene_File, a much bigger script handles the write/load procedure of saving and loading games, which its subclasses (Scene_Load, Scene_Save) will use.As a class, Scene_Save will have many methods inside it - and now I see that there are many methods("help_window_text", "on_savefile_ok") and constants being called within those methods itself. And knowing the software as long as I have, I know what those constants refer to! This particular script now makes tons of sense.

In the past week, I've been wondering why when we learned reading/writing files we used one script that had the class handling the read/write method and another script that actually called the methods - but seeing them in action in RMVXA really made it that much clearer why they'd do that. It's cleaner, easier to see - far better than putting everything on one script. It's also because in this instance we have 3 different windows that the user will interact with in the game, which is the File Scene/Window, which asks them if they want to Save/Load so they can make a choice if they want to open either of those scenes. Then, Scene_File handles most of the read/write processes while Scene_Save/Scene_Load just creates the windows for user interaction. It's important because if we want to override any of these with a custom script, it's so much easier to just override the class Scene_Save and Scene_Load (Which custom Save/Load mods DO target if they just want to change the general layout) or Scene_File (where they change -how- games are saved and loaded, such as directory, information actually recorded, etc.).

I look forward to actually using the built-in scripts as well as custom scripts to further learn as a case study for Ruby scripts in the future.

2 comments:

  1. RMXP brings back a lot of memories with Ruby. I know exactly how it feels trying to just understand what the code is actually doing, but at least you're getting the hang of it!

    Keep it up, and can't wait till you release an RMXP game!

    ReplyDelete
    Replies
    1. Yeah, no kidding. Being able to read this means I can actually write something if I have to, now. :p

      Delete