19 May 2009

Time/Date Formats

In yesterday's entry, System Time/Date Script, I showed how to use the built-in Time function to display the current (system) time and date.

To change format, the strftime method has a number of options available.

Its basic format is

strftime(format)

where format is the format string to be used, which may be specified with the following:
  • %A - Full day of the week (Sunday, Monday, etc.)
  • %a - Abbreviated day of the week (Sun, Mon, etc.)
  • %B - Full month (January, February, etc.)
  • %b - Abbreviated month (Jan, Feb, etc.)
  • %c - Current Date and Time (system clock format)
  • %d - Day of the month (01-31)
  • %H - Time of day in 24-hour format (00-23)
  • %I - Time of day in 12-hour format (01-12)
  • %j - Day of the year (001-366)
  • %M - Minutes (00-59)
  • %m Numerical month of the year (01-12)
  • %p - Displays AM or PM after the time
  • %S - The number of seconds (00-60, 60 being a "leap second")
  • %U - Week of the year, the first week starting with the first Sunday (00-53)
  • %W - Week of the year, the first week starting with the first Monday (00-53)
  • %w - Day of the week (0-6, 0 denoting Sunday)
  • %X - Displays the Time
  • %x - Displays the Date
  • %Y - Displays the Year as a 4-digit number (2009)
  • %y - Displays the Year as a 2-digit number (00-99)
  • %Z - Displays the default (system) Time Zone
  • %% - Displays a % character
Note that this is case sensitive.

So, as an example, to display the full date, including day, month and year, strftime would be set to:

strftime = ("%A, %d %B, %Y")


The result would be

Tuesday, 20 May, 2009

And that's it!

System Time/Date Script

RMXP and RMVX has a built-in Time function that allows the display of the current date and time (based on the system clock). I found this by accident while sifting through the Help file - actually while searching for Bitmap and Sprite management - and after some experimentation discovered how to place it in windows.

To use it, there are two functions to be aware of:

Time.now

This reads the current time and date from the system clock.

strftime("%I:%M:%S %p")

This converts the time into a string, using the time of day (in 12-hour format), minutes and seconds, as well as showing AM/PM.

So to add the time and date, we can add the following:

t = Time.now
time = t.strftime("%I:%M:%S %p")
date = t.strftime("%a, %d %b, %Y")

What this will do is store the time/date stamp format into variables and convert them to strings so that they can then be "drawn" in a window.

In RMXP, the following script can be used to replace the default. In RMVX, create a new script called Window_PlayTime:
#=================================================================
# ** Window_PlayTime
#-----------------------------------------------------------------
#  This window displays play time on the menu screen.
#=================================================================
class Window_PlayTime < 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.clear
    self.contents.font.size = 16
    t = Time.now
    time = t.strftime("%I:%M:%S %p")
    date = t.strftime("%a, %d %b, %Y")
    self.contents.font.color = normal_color
    self.contents.draw_text(0, -2, 140, WLH, date, 1)
    self.contents.draw_text(0, 14, 140, WLH, time, 1)
  end
  #---------------------------------------------------------------
  # * Frame Update
  #---------------------------------------------------------------
  def update
    super
    if Graphics.frame_count / Graphics.frame_rate != @total_sec
      refresh
    end
  end
end
RMXP will display the replacement time/date in the default "Play Time" window on the menu status.

To make this work in RMVX, add the following to Scene_Menu:

In the start definition routine, add

@window_playtime = Window_PlayTime.new
@window_playtime.x = X
@window_playtime.y = Y

where X and Y are the x- and y-coordinates for the window placement.

Add the following to the terminate definition routine:

@window_playtime.dispose

This is to ensure that the window doesn't stay onscreen when the status menu has been exited.

And finally, add the following to the update definition routine:

@window_playtime.update

This is to ensure that the time refreshes every second while on the status menu.

The resultant "Play Time" window should now contain the current time and date, thus:

Tue, 19 May, 2009
12:33:22 PM

And that's it, but the strftime element does have a number of different format options, which I'll detail in the next entry.

Miscellaneous Utilities

A number of useful utilities to aid in game-making with RM2K3 have been produced, aside from the Character Creators.

The following utilities are designed for "hacking" resources:

  • ResHack (RM2K/3) - Short for Resource Hack, this great utility allows the hacking of games or RM2K. With it, game icons, text, etc. can be modified to suit individual needs.
  • RM Reck (RM2K/3) - Similar to ResHack (above), it allows game icon, glyphs, and even logo screens to be changed. This is compatible with both RM2K and RM2K3.
  • Animget - This useful utility enables ripping of sprites and other animations, mostly from emulators. Once it's been activated, it runs in the background and saves snapshots every 0.1 seconds for appropriate resource modification later.

Other useful programs that can be used are:

  • RMTool (RM2K/3) - It scans RPG Maker games for missing files and gives instructions on how to fix it. For example, if a MIDI or particular graphics file is missing from the game's Project folder, this tool will tell you which one is missing. Note that it was specifically made for RM2K, but works as well with RM2K3, except for 2K3-specific folders (i.e. System2, BattleChars, CharSets, etc.); they just won't be scanned.
  • Zorn's RM2K Tool (Direct Download) - A solid utility that allows random creation of Game Titles, Hero Names, Item Names, Equipment Names and Skill Names (using an editable external text file). It also has a few tutorials built in. These have been designed for RM2K, but should also work with RM2K3.

Window & Scene Wizard

If you're like me and *hate* making windows and their accompanying scenes - at least when it comes to positioning onscreen - there is a useful utility called the Window & Scene Wizard (WSW). Actually it's compiled using RGSS and runs standalone or from with RMXP itself.

You can find a demo, along with instructions and downloads, at Creation Asylum. Note: The first download site no longer hosts the files, so be sure to use the second download site instead.

The WSW works very well, using the mouse and keyboard fluently to create windows. You can create ordinary windows as well as menus, add text, icons and pictures, as well as parameters and other details.

When your finished product is saved, the Window and Scene scripts will be saved in .TXT format. From there you can copy and paste into RMXP and use them for your newly created windows.

The only problem I have with the WSW, however, is that if you create a blank window (or a set of blank positioned windows), it also contains extra, generic crap you don't really need. It's not difficult to delete it, but if you don't know too much about RGSS, it can mess up and you'll receive a few errors.

Work on the WSW stopped after v1.0, since the final entry in the forum was back in 2006, and nothing else has become of it. It's still a good program/utility nevertheless, for learning more about RGSS if for nothing else.
Related Posts with Thumbnails
Template Design "Perfect World" by SkinCorner