Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Time Hub help please <Resolved>

Hi just a moment of your time. I need help with a script i'm trying to piece together with no scripting knowledge.

Code:
class Window_HUD < Window_Base
  def initialize
    super(640,480,176,112)
    self.contents = Bitmap.new(140,80)
    self.contents.font.size = 20
    self.back_opacity = 160
    refresh
  end
  def refresh
    self.contents.clear
    @actor = $game_party.actors[0]
    self.contents.draw_text(4,0,132,20,$ats.date.to_s,1)
    self.contents.draw_text(4,10,132,20,$ats.clock.to_s,1)
    draw_actor_hp(@actor,4,16)
    draw_actor_sp(@actor,4,36)
    self.contents.draw_text(4,60,132,20,$game_party.gold.to_s,2)
    self.contents.draw_text(4,60,132,20,$data_system.words.gold + ":")
  end
end
class Scene_Map
  alias hud_main main
  alias hud_update update
  def main
    @hud = Window_HUD.new
    hud_main
    @hud.dispose
  end
  def update
    @hud.refresh
    if $game_switches[1] and @hud.x > 468
      @hud.x -= 11
      @hud.y -= 7
    end
    if $game_switches[1] == false and @hud.x < 640
      @hud.x += 11
      @hud.y += 7
    end
    hud_update
  end
end

I'm trying to get this hub from the ==Really=== Simple HUD Request topic to work with Near Fantastica Advanced Time System so it'll show the day of the week and the time, only hour and minute in am/pm format. But the hub script wants to update every from and not when the time changes every 60 frames. So it's lagging the game a bit. Can you help me fix that and make it so the hub doesn't slide in and out when i turn in on and off, it just appears and disappears. Thanks in advanced.
 

khmp

Sponsor

Inside Scene_Map and inside its update. Change this line:
Code:
@hud.refresh
to:
Code:
if Graphics.frame_count % Graphics.frame_rate == 0
  @hud.refresh
end

Good luck with it l0rdph0enix! :thumb:
 
Like this?

Code:
class Window_HUD < Window_Base
  def initialize
    super(640,480,176,112)
    self.contents = Bitmap.new(140,80)
    self.contents.font.size = 20
    self.back_opacity = 160
    refresh
  end
  def refresh
    self.contents.clear
    @actor = $game_party.actors[0]
    self.contents.draw_text(4,0,132,20,$ats.date.to_s,1)
    self.contents.draw_text(4,10,132,20,$ats.clock.to_s,1)
    draw_actor_hp(@actor,4,16)
    draw_actor_sp(@actor,4,36)
    self.contents.draw_text(4,60,132,20,$game_party.gold.to_s,2)
    self.contents.draw_text(4,60,132,20,$data_system.words.gold + ":")
  end
end
class Scene_Map
  alias hud_main main
  alias hud_update update
  def main
    @hud = Window_HUD.new
    hud_main
    @hud.dispose
  end
#=========================================
#   Update
#=========================================
  def update
    @hud.update
    if $game_switches[2] and @hud.x > 468
      @hud.x -= 11
      @hud.y -= 7
    end
        if $game_switches[2] == false and @hud.x < 640
      @hud.x += 11
      @hud.y += 7
      end
    hud_update
   def refresh
     if Graphics.frame_count % Graphics.frame_rate == 0
  @hud.refresh
end
  end
end
end

?

cuz that's how i changed it in my game and the time doesn't update :( I'm trying to work that hub into a *.png pic interface (would rather the interface be scripted but that's beside the point)
 

khmp

Sponsor

You can just edit your previous post mate. No need to create a new post to add to the last one. Ok let's see... you messed the code up real good. :wink: Always tab the code. Keep things neat for the sake of another reader. Its hard to read the following code:
Code:
   def refresh
     if Graphics.frame_count % Graphics.frame_rate == 0
  @hud.refresh
end
  end
end
end

Anyway let's fix "Scene_Map". The "main" method is fine. "update" seems to be where you went awry. We're going to start from scratch. I missed from your original post that you wanted it to disappear and reappear based on a switch so I will cover that as well. Like I said scratch so your Scene_Map class should look like this now:
Code:
class Scene_Map
  alias hud_main main
  alias hud_update update

  def main
    @hud = Window_HUD.new
    hud_main
    @hud.dispose
  end
  #=========================================
  # * Frame Update
  #=========================================
  def update
    hud_update
  end
end

The update is only calling Scene_Map's original update. When we alias a method we are saving the old code so we don't just override the old code. If you've looked into the default scripts we wouldn't want to just override all that stuff. Just in case you were curious as to why. That aside let's add some stuff before the alias method update call. First as you've mentioned in your first post you want to toggle the hud on and off without any sliding. Within the "Window" class is a method called "visible". This toggles the visibility of the window coincidentally:
Code:
class Scene_Map
  #=========================================
  # * Constant Variables
  #=========================================
  HUD_SWITCH = 2

  alias hud_main main
  alias hud_update update

  def main
    @hud = Window_HUD.new
    hud_main
    @hud.dispose
  end
  #=========================================
  # * Frame Update
  #=========================================
  def update
    @hud.visible = $game_switches[HUD_SWITCH]
    hud_update
  end
end

I threw in a constant called HUD_SWITCH and set it equal to 2. This is the index of which switch toggles the HUD. You can change it to whatever you like. Now we are going to re institute the code I gave you for updating at timed intervals. Including the check for HUD visibility no sense in redrawing something that can't be seen. I don't know if windows don't already have that check but for the sake of peace of mind I include it.

Code:
class Scene_Map
  #=========================================
  # * Constant Variables
  #=========================================
  HUD_SWITCH = 2

  alias hud_main main
  alias hud_update update

  def main
    @hud = Window_HUD.new
    hud_main
    @hud.dispose
  end
  #=========================================
  # * Frame Update
  #=========================================
  def update
    @hud.visible = $game_switches[HUD_SWITCH]
    if Graphics.frame_count % Graphics.frame_rate == 0 && @hud.visible
      @hud.refresh
    end
    hud_update
  end
end

That's all there is to it. Almost now that the window no longer slides to where it should be we need to create the Window where it will be permanently. There's a line and I want you to use CTRL-H (Search + Replace) to do this, s'alright?

Search:
Code:
super(640,480,176,112)
Replace:
Code:
super(0,0,176,112)

That will place the window all the way in the upper left corner of the screen.

Now you want to change it to a picture. That drastically changes things because we should no longer be dealing with a "Window" object but you would be using a "Sprite" instead. You would need to do quite a bit more work with the drawing code as it wouldn't be as simple. If that is your wish you should create a Script Request topic here.

Good luck with it l0rdph0enix! :thumb:
 
Woo hoo it works properly now, I just have to edit where it appears but other then that it works like a charm. No longer lagging my game from updating every frame. Yeah i want it to be a "window" script, it's the interface pic i want to be done as a window script too instead of a pic. So, thanks for providing the Script Request link for that, that's awsome. Soon as I move the hub, to where i need it i'll take a screen shot of it in work in my game to show yeah how it looks. thanks again for your help with this, the lagging of it is what's been stopping me from releasing a demo of my game. You shall be credited for your help too. ;)

EDIT: ScreenShot
http://i26.tinypic.com/jhtqhd.png]http://i26.tinypic.com/jhtqhd.png[/img]
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top