Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Sign in to follow this  
totalsticks

Help With My Script?

Question

So, after scouring the web for any way to make what I needed possible,

I started looking at all the scripting tutorials that are on this site.

Great stuff, but now it seems like I have hit a snag, well a couple of them.

 

1. I tried to make this clock appear in the upper right corner of the screen

and can be viewed at all times without having to call the scene specifically.

Like a HUD sort of. But it wont display like a hud, instead more a menu.

 

2. I am trying to get in-game variables to be called within the clock script

that allows it to display/update them on the clock as they change. However,

I cant seem to manage to get them to display.

 

I must be doing something wrong, so if anyone could point out to me what it

is, I would be grateful. I will attach my first attempt at a script from

scratch, and hopefully someone can figure it out.

 

 

 

class DateWindow < Window_Base
 def initialize
   super(525,0,115,96)
   @window = DateWindow.new
   @timer_min = $game_variables[7]
   @timer_hour = $game_variables[8]
   @timer_day = $game_variables[9]
   @timer_month = $game_variables[10]
   @timer_year = $game_variables[11]    
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end

 def refresh
   self.contents.clear
   self.contents.font.color = normal_color
   self.contents.font.size = 16
   self.contents.draw_text(0,0,100,32,"timer_hour:timer_min")
   self.contents.draw_text(0,32,100,32,"timer_month/timer_day/timer_year AZ")
 end
end

class Scene_ShowWindow
 def main
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   Graphics.freeze
   @window.dispose
 end
 def update
   @window.update
 end
end

 

 

 

Lines 5-9 are my attempts at turning the game variables into local variables.

Meanwhile, Lines 18 and 19 are where I am trying to display them within the window.

 

Again, thanks. I know I'm a pain. :B):

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

First of all, good work on the script you compiled. It doesn't work, but its very close.

 

The line "@window = Datewindow.new" should be in the scene, not the window. Apart from that, everything is pretty much good.

 

Alright, I got a little annoyed because this is a relatively simple request and no one replied, so I decided to give it a go even though I don't know very much. Try this out:

 

Replace Scene_Map with:

 

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================

class Scene_Map
 #--------------------------------------------------------------------------
 # * Main Processing
 #--------------------------------------------------------------------------
 def main
   @date_window = Window_PlayTimeHud.new
   # Make sprite set
   @spriteset = Spriteset_Map.new
   # Make message window
   @message_window = Window_Message.new
   # Transition run
   Graphics.transition
   # Main loop
   loop do
     # Update game screen
     Graphics.update
     # Update input information
     Input.update
     # Frame update
     update
     # Abort loop if screen is changed
     if $scene != self
       break
     end
   end

   # Prepare for transition
   Graphics.freeze
   # Dispose of sprite set
   @spriteset.dispose
   #dispose of the clock
   @date_window.dispose
   # Dispose of message window
   @message_window.dispose
   # If switching to title screen
   if $scene.is_a?(Scene_Title)
     # Fade out screen
     Graphics.transition
     Graphics.freeze
   end
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   # Loop
   loop do
     # Update map, interpreter, and player order
     # (this update order is important for when conditions are fulfilled 
     # to run any event, and the player isn't provided the opportunity to
     # move in an instant)
     @date_window.update
     $game_map.update
     $game_system.map_interpreter.update
     $game_player.update
     # Update system (timer), screen
     $game_system.update
     $game_screen.update
     # Abort loop if player isn't place moving
     unless $game_temp.player_transferring
       break
     end
     # Run place move
     transfer_player
     # Abort loop if transition processing
     if $game_temp.transition_processing
       break
     end
   end
   # Update sprite set
   @spriteset.update
   # Update message window
   @message_window.update
   # If game over
   if $game_temp.gameover
     # Switch to game over screen
     $scene = Scene_Gameover.new
     return
   end
   # If returning to title screen
   if $game_temp.to_title
     # Change to title screen
     $scene = Scene_Title.new
     return
   end
   # If transition processing
   if $game_temp.transition_processing
     # Clear transition processing flag
     $game_temp.transition_processing = false
     # Execute transition
     if $game_temp.transition_name == ""
       Graphics.transition(20)
     else
       Graphics.transition(40, "Graphics/Transitions/" +
         $game_temp.transition_name)
     end
   end
   # If showing message window
   if $game_temp.message_window_showing
     return
   end
   # If encounter list isn't empty, and encounter count is 0
   if $game_player.encounter_count == 0 and $game_map.encounter_list != []
     # If event is running or encounter is not forbidden
     unless $game_system.map_interpreter.running? or
            $game_system.encounter_disabled
       # Confirm troop
       n = rand($game_map.encounter_list.size)
       troop_id = $game_map.encounter_list[n]
       # If troop is valid
       if $data_troops[troop_id] != nil
         # Set battle calling flag
         $game_temp.battle_calling = true
         $game_temp.battle_troop_id = troop_id
         $game_temp.battle_can_escape = true
         $game_temp.battle_can_lose = false
         $game_temp.battle_proc = nil
       end
     end
   end
   # If B button was pressed
   if Input.trigger?(Input::B)
     # If event is running, or menu is not forbidden
     unless $game_system.map_interpreter.running? or
            $game_system.menu_disabled
       # Set menu calling flag or beep flag
       $game_temp.menu_calling = true
       $game_temp.menu_beep = true
     end
   end
   # If debug mode is ON and F9 key was pressed
   if $DEBUG and Input.press?(Input::F9)
     # Set debug calling flag
     $game_temp.debug_calling = true
   end
   # If player is not moving
   unless $game_player.moving?
     # Run calling of each screen
     if $game_temp.battle_calling
       call_battle
     elsif $game_temp.shop_calling
       call_shop
     elsif $game_temp.name_calling
       call_name
     elsif $game_temp.menu_calling
       call_menu
     elsif $game_temp.save_calling
       call_save
     elsif $game_temp.debug_calling
       call_debug
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Battle Call
 #--------------------------------------------------------------------------
 def call_battle
   # Clear battle calling flag
   $game_temp.battle_calling = false
   # Clear menu calling flag
   $game_temp.menu_calling = false
   $game_temp.menu_beep = false
   # Make encounter count
   $game_player.make_encounter_count
   # Memorize map BGM and stop BGM
   $game_temp.map_bgm = $game_system.playing_bgm
   $game_system.bgm_stop
   # Play battle start SE
   $game_system.se_play($data_system.battle_start_se)
   # Play battle BGM
   $game_system.bgm_play($game_system.battle_bgm)
   # Straighten player position
   $game_player.straighten
   # Switch to battle screen
   $scene = Scene_Battle.new
 end
 #--------------------------------------------------------------------------
 # * Shop Call
 #--------------------------------------------------------------------------
 def call_shop
   # Clear shop call flag
   $game_temp.shop_calling = false
   # Straighten player position
   $game_player.straighten
   # Switch to shop screen
   $scene = Scene_Shop.new
 end
 #--------------------------------------------------------------------------
 # * Name Input Call
 #--------------------------------------------------------------------------
 def call_name
   # Clear name input call flag
   $game_temp.name_calling = false
   # Straighten player position
   $game_player.straighten
   # Switch to name input screen
   $scene = Scene_Name.new
 end
 #--------------------------------------------------------------------------
 # * Menu Call
 #--------------------------------------------------------------------------
 def call_menu
   # Clear menu call flag
   $game_temp.menu_calling = false
   # If menu beep flag is set
   if $game_temp.menu_beep
     # Play decision SE
     $game_system.se_play($data_system.decision_se)
     # Clear menu beep flag
     $game_temp.menu_beep = false
   end
   # Straighten player position
   $game_player.straighten
   # Switch to menu screen
   $scene = Scene_Menu.new
 end
 #--------------------------------------------------------------------------
 # * Save Call
 #--------------------------------------------------------------------------
 def call_save
   # Straighten player position
   $game_player.straighten
   # Switch to save screen
   $scene = Scene_Save.new
 end
 #--------------------------------------------------------------------------
 # * Debug Call
 #--------------------------------------------------------------------------
 def call_debug
   # Clear debug call flag
   $game_temp.debug_calling = false
   # Play decision SE
   $game_system.se_play($data_system.decision_se)
   # Straighten player position
   $game_player.straighten
   # Switch to debug screen
   $scene = Scene_Debug.new
 end
 #--------------------------------------------------------------------------
 # * Player Place Move
 #--------------------------------------------------------------------------
 def transfer_player
   # Clear player place move call flag
   $game_temp.player_transferring = false
   # If move destination is different than current map
   if $game_map.map_id != $game_temp.player_new_map_id
     # Set up a new map
     $game_map.setup($game_temp.player_new_map_id)
   end
   # Set up player position
   $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
   # Set player direction
   case $game_temp.player_new_direction
   when 2  # down
     $game_player.turn_down
   when 4  # left
     $game_player.turn_left
   when 6  # right
     $game_player.turn_right
   when 8  # up
     $game_player.turn_up
   end
   # Straighten player position
   $game_player.straighten
   # Update map (run parallel process event)
   $game_map.update
   # Remake sprite set
   @spriteset.dispose
   @spriteset = Spriteset_Map.new
   # If processing transition
   if $game_temp.transition_processing
     # Clear transition processing flag
     $game_temp.transition_processing = false
     # Execute transition
     Graphics.transition(20)
   end
   # Run automatic change for BGM and BGS set on the map
   $game_map.autoplay
   # Frame reset
   Graphics.frame_reset
   # Update input information
   Input.update
 end
end

 

Add above the following above main

 

#==============================================================================
# ** Window_PlayTime
#------------------------------------------------------------------------------
#  This window displays play time on the menu screen.
#==============================================================================

class Window_PlayTimeHud < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(640-160, 0, 160, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   self.contents.clear
   self.contents.font.color = system_color
   @total_sec = Graphics.frame_count / Graphics.frame_rate
   hour = @total_sec / 60 / 60
   min = @total_sec / 60 % 60
   sec = @total_sec % 60
   text = sprintf("%02d:%02d:%02d", hour, min, sec)
   self.contents.font.color = normal_color
   self.contents.draw_text(4, 0, 120, 32, text, 2)
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   super
   if Graphics.frame_count / Graphics.frame_rate != @total_sec
     refresh
   end
 end
end

 

 

The last one is a simple edit of Window_PlayTime, but we can use it to display the time any way we want.

Share this post


Link to post
Share on other sites
  • 0

First off, thanks for the help. I didnt realize that most of my problem was I was trying

to call it in a window as if it was a custom menu system. I'm starting to understand just

a little here. So, I have the HUD, to the specific size I want, in the right positioning,

but I cant seem to call the variables I want to input for the time and date. I'll attach what I

edited from what you sent me. You'll see three lines of comments explaining what I'm trying

to do. Again, thanks for the help.

 

 

 

#==============================================================================
# ** Window_PlayTime
#------------------------------------------------------------------------------
#  This window displays play time on the menu screen.
#==============================================================================

class Window_DateHud < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(520, 0, 115, 96)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   self.contents.clear
   self.contents.font.color = system_color
   self.contents.font.color = normal_color
   # Note that the below timer_hour, etc are all variables I want to
   # call from a common event I have set up. \v[7] doesnt seem to
   # work. Thats what I'm trying to accomplish.
   self.contents.draw_text(0,0,100,32,"timer_hour:timer_min")
   self.contents.draw_text(0,32,100,32,"timer_month/timer_day/timer_year AZ")
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   super
   if Graphics.frame_count / Graphics.frame_rate != @total_sec
     refresh
   end
 end
end

 

 

Share this post


Link to post
Share on other sites
  • 0

I have modified your latest script to use the variables that you set up in your event.

 

 

#==============================================================================
# ** Window_PlayTime
#------------------------------------------------------------------------------
#  This window displays play time on the menu screen.
#==============================================================================

class Window_DateHud < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(520, 0, 115, 96)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   self.contents.clear
   self.contents.font.color = system_color
   self.contents.font.color = normal_color
   # Note that the below timer_hour, etc are all variables I want to
   # call from a common event I have set up. \v[7] doesnt seem to
   # work. Thats what I'm trying to accomplish.
   text = sprintf("%02d:%02d", $game_variables[8], $game_variables[7])
   self.contents.draw_text(0,0,100,32,text,2)
   text = sprintf("%02d/%02d/%04d", $game_variables[10], $game_variables[9], $game_variables[11])
   self.contents.draw_text(0,32,100,32, text,2)
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   super
   if Graphics.frame_count / Graphics.frame_rate != @total_sec
     refresh
   end
 end
end

 

Share this post


Link to post
Share on other sites
  • 0

Thanks, that got it working. Now I just need to find a way to make it refresh

on its own without having to go into the menu and back. And also a way to turn

it off while during events, etc..

Share this post


Link to post
Share on other sites
  • 0

Ran into a slight problem. Fixed it by copying the Scene_Map

script into my own project. Now it functions perfectly.

Great job guys! Thanks for all the help. I gave you both + Rep

for the help. Now all that's left to do is figure out how to make

a calendar. :alright:

 

Topic Closed.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...