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.

This is Freezing My Game!

Okay, I was attempting to display a custom window in my game through an event using the $scene = <Window name> script command. This worked fine with simple windows, but for some reason it wasn't working with the window I had. (Does outputting variables make a difference?) Anyway, I was given this HUD script. It's not returning any errors, but my game is completely frozen the moment I start it, and my last help topic pretty much got ignored. I'm trying to get this finished for someone and I hate that I'm taking so freakin' long.

Code:
 

class Scene_Map

  attr_accessor :hud

  alias smap_main main

  alias smap_update update

  def main

    @hud = Window_Energy.new

    smap_main

    @hud.dispose

  end

  def update

    @hud.update

    if $game_player.y < 3

      @hud.opacity = 160

    else

      @hud.opacity = 235

    end

    smap_update

  end

end

 

That's the code I was given that's freezing my game. Does anyone know what's wrong with it?
 
Wait, you are putting a window in your $scene variable?

That is most likely your problem.

Second, when EXACTALLY does it freeze? Right after selecting new game, or before the title menu?

Third, I see nothing in that code that could cause a problem.
 
It would probably help if you had what I programmed:

Code:
 

class Window_Energy < Window_Base

  def initialize

    super(0, 0, 200, 96)

    self.contents = Bitmap.new(width - 32, height - 32)

    refresh

  end

  

  def refresh

    self.contents.clear

    @sp = $game_variables[1].to_s

    @maxsp = $game_variables[2].to_s

    self.contents.draw_text(0, 0, 200, 32, "Energy", 1)

    self.contents.draw_text(0, 32, 90, 32, @sp, 2)

    self.contents.draw_text(90, 32, 20, 32, "/", 1)

    self.contents.draw_text(110, 32, 90, 32, @maxsp)

  end

  

  def update

    super

    if $game_variables[1] != @sp || $game_variables[2] != @maxsp

      refresh

    end

  end

end

 

It freezes as soon as the map loads up after New Game is selected. I have an event at the beginning that is set to call $scene.hud.visible = false, and then to flip a switch that turns the event to the second page, which has nothing on it and just sits idle doing nothing (basically turns off, for all intents and purposes).

But yeah, it loads the map and my character, but then freezes so I can't move, call the menu, or anything accept bring up the debugger.
 
It doesn't make a difference. It's still frozen. I still have to run it as an autorun event, it's just erasing itself instead flipping a switch.

EDIT: Okay, apparently not even putting the event in there seems to make it work... so far. Maybe setting it to false was causing some kind of problem, but that's a problem in itself considering I can't show and hide the window when I need to.
 
Oh, sorry about that here, use this instead:

[rgss] 
$hudswitch = 1 # change this to the switch that you want to
# have (on = visible/off = invisible)
class Scene_Map
  attr_accessor :hud
  alias smap_main main
  alias smap_update update
  def main
    @hud = Window_Energy.new
    smap_main
    @hud.dispose
  end
  def update
    @hud.update
    if $game_player.y < 3
      @hud.opacity = 160
    else
      @hud.opacity = 235
    end
    @hud.visible = $game_switches[$hudswitch]
    smap_update
  end
end
 
[/rgss]

Just pick a switch, and turn it on to make the hud show,
and turn it of to make the hud not show (you have to
edit the script where it says "$hudswitch = 1" and replace
the 1 with number of the switch).
 
Ah, okay, that actually works really well considering I had to flip a switch anyway when the window is called. Thanks! Hopefully it'll work from here on out so I don't have to bother you with it again. ^_^ Thanks again!
 

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