Help - Search - Members - Calendar
Full Version: Displaying time in menu
RPG RPG Revolution Forums > Scripting > Script Development and Support > RGSS2
Hoodlum
I've made a mistake and posted this in a wrong section! Please, move this topic to RGSS2 Script Support.

Hello.
I am currently working on a game with a feature of displaying current game time in player's menu. It should be shown in a window, right above gold. I have wrote this script and called it Window_Time:
CODE
#==============================================================================
# ** Window_Time
#------------------------------------------------------------------------------
#  This window displays playtime on the menu screen.
#==============================================================================

class Window_Time < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(x, y)
   super(x, y, 160, WLH * 3)
   refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    @time = Graphics.frame_count / Graphics.frame_rate
    hour = @time / 60 / 60
    min = @time / 60 % 60
    sec = @time % 60
    text = sprintf("Game time: %dh:%dmin", hour, min, sec)
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, 120, self.height / 2, text, 1)
  end
end

Next, I've added this line in Scene_Menu:
CODE
@time_window = Window_Time.new(0, 248)

Now when I press ESC in game, the window with text 'Game time: 0h:0min" is shown for a second and then it just disappears... How to make it work? Thanks in advance for any answers!
The Law G14
Hey, I'll move this topic for you smile.gif

Also, in the terminate method of Scene_Menu, make sure you add:

CODE
@time_window.dispose


and in the update method, also add:

CODE
@time_window.update


I'm not sure if this will fix your problem, but we can start from there smile.gif
Hoodlum
Thanks for your very fast reaction!
I've tried it and reult is the same - the window disappears very fast. Also, after closing the menu, game crashes with following error:
CODE
Script 'Window_Base' line 37: RGSSError occurred.
disposed window

Line 37 is here:
CODE
  def dispose
    self.contents.dispose # Line 37
    super
  end

Hmm, any other ideas?
The Law G14
Hm, this is very weird, I tried putting the script in my game and I don't get any such errors, do you have any other custom scripts in your game?
The Law G14
Hm, this is very weird, I tried putting the script in my game and I don't get any such errors, do you have any other custom scripts in your game?
Hoodlum
Yes, it seems that Jet's Time System is ruining everything... It's a shame, 'cause I really like this script and can't find anything in advantage. Well, anyway, thanks for your help, there is no problem anymore, although if someone knows how to make it work with Jet's Time System it would be really great. tongue.gif
The Law G14
I can try to get them to work together if you'd like smile.gif Just send me Jet's Time System, do you have any other custom scripts?
Hoodlum
I wasn't expecting such helpfulness, it makes me nicely surprised (in Poland, where I live, it would be hard to find someone like you tongue.gif)! Again thank you very much, but this time I need to refuse - I don't want to bother you with it, since it surely would take some amount of time. Also I would wish to learn RGSS by fixing most of the problems myself. I am advanced scripter in Pawn language (used in GTA: San Andreas Multiplayer) and I know how to think like programmer if you know what I mean. ;d I don't read any tutorials, just look at code, analyze it and try to change it for my needs. So I've removed Jet's Time System and replaced it with my own, based on events and few commands in Game_Interpreter class. The window now works and I've even managed to draw an hourglass icon next to the time amount! biggrin.gif
The Law G14
Great, I'm glad it's all working for you! And thanks for the compliment lol, if you need any later help in scripting, throw me a PM and I'll be more than happy to help you out (Though it seems you're already progressing very well biggrin.gif )
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.