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.

Really (Really) Simple Display Problem [SOLVED]

So, let me just begin by saying I'm probably the biggest newbie when it comes to scripting, so this problem can probably be easily solved by anyone.

I have a script that displays text. The problem is, I want the text to disappear after 20 frames, but I don't know how to do this.

Code:
class My_Window3 < Window_Base

  # * Object Initialization

  def initialize
    super(0, 0, 256, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    
    show_text
    #clear
  end
  
  # * Refresh

  def show_text
    self.contents.clear
    
    self.contents.draw_text(0, 0, 256, 32, $game_variables[24].to_s)
  end
  
  #def clear
    #self.contents.clear
  #end
end

That clear method is what I want to call after 20 frames.

Can anyone please help?
 
This would be done in the update method of the scene. So inside your scene. First add this line below 'def main':
Code:
@delay = 20 * 2
Find the 'def update' method. Inside it add something of the likes:
Code:
if @delay > 0
  @delay -= 1
else
  @your_window.clear
end
Change '@your_window' into whatever you call your window. Oh, and note that the variable delay function is used to allow other things to execute at the same time, and to prevent script hanging if more than 8 seconds pass. Oh, and make sure you uncomment the clear method.

Hope this helps.
 
First of all, thank you so much for taking some of your time to help me.

Next, did you mean something like this?:

Code:
class My_Window3 < Window_Base
  
  # * Object Initialization
  
  def initialize
    @delay = 20 * 2
    super(0, 0, 256, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    
    show_text
  end
  
  # * Refresh
  
  def show_text
    self.contents.clear
    
    self.contents.draw_text(0, 0, 256, 32, $game_variables[24].to_s)
    if @delay > 0
      @delay -= 1
    else
      clear
    end
    end
    
  def clear
    self.contents.clear
  end
end

That kind of works; it shows the text for about 4 seconds. Also, I decreased the value of @delay and it didn't change the delay time. If I'm doing something wrong please tell me.
 
No. Wherever you initialize the window (which would usually be Scene_) something, you have to add this code.
This is the only place where your window will appear in the first place.
 
I didn't really initialize it from another script, if that's what you mean.  I called it from an event. If I'm completely missing what you're trying to say, I apologize (like I said, I'm REALLY new to scripting, so a lot of this still doesn't make sense to me).
 
If you called it from an event, it would be wise to use this method instead:
Code:
window = My_Window3.new
sleep(1)
window.clear
Note that 20 frames is 1 second as a usual rate. You can change the sleep to whatever you want up to 8 seconds.
If it's above 8 seconds, the script will hang and crash the game.
 
By default you should not be having this in a call script, as it appears to be pretty useless to make local variables inside a method in the Interpreter. You might wanna try implementing this into the Scene_Map instead. Take a look at the Window_Message already initialized there and follow the standards. Then use the code provided at the very first step.

Cheers.
 

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