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.

[Resolved] Simple Letter-by-Letter Message System Help

Hi, I'm having a problem making a message system in RGSS that displays a message letter by letter rather than all at once. Here's my code:

Code:
# This class will make a the window text appear letter by letter...

# ...rather than all at once

class Window_Speech3 < Window_Base

  

  def initialize(id, awidth, line1, line2, line3, line4)

    if (($game_map.events[id].x - $game_map.display_x/128) * 32 - (awidth/2.4) < 0)

      x = 0

    else  

      x = ($game_map.events[id].x - $game_map.display_x/128) * 32 - (awidth/2.4)

    end  

    if (($game_map.events[id].y - $game_map.display_y/128) * 32 - 160 < 0)

      y = 0

    else

      y = ($game_map.events[id].y - $game_map.display_y/128) * 32 - 160

    end

    if (line4.length != 0)

      aheight = 128

    elsif (line3.length != 0)

      aheight = 104

      y = y + 24

    elsif (line2.length != 0)  

      aheight =  80

      y = y + 48

    else

      aheight = 56

      y = y + 72

    end

    super (x, y, awidth, aheight)

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

    speak(line1, line2, line3, line4)

    end

    

  def speak(line1, line2, line3, line4)

    $game_switches[2] = true

    for i in 0...line1.length

      if line1[i, 1] == "^"

        line1.slice!(i, 1)

        for j in 0...10

          Graphics.update

        end

        redo

        end

      self.contents.clear

      self.contents.draw_text(0, 0, 448, 24, line1[0, i+1])

      Graphics.update

    end

    for i in 0...line2.length

      if line2[i, 1] == "^"

        line2.slice!(i, 1)

        for j in 0...10

          Graphics.update

        end

        redo

      end

      self.contents.clear

      self.contents.draw_text(0, 0, 448, 24, line1)

      self.contents.draw_text(0, 24, 448, 24, line2[0, i+1])

      Graphics.update

    end

    for i in 0...line3.length

      if line3[i, 1] == "^"

        line3.slice!(i, 1)

        for j in 0...10

          Graphics.update

        end

        redo

        end

      self.contents.clear

      self.contents.draw_text(0, 0, 448, 24, line1)

      self.contents.draw_text(0, 24, 448, 24, line2)

      self.contents.draw_text(0, 48, 448, 24, line3[0, i+1])

      Graphics.update

    end

    for i in 0...line4.length

      if line4[i, 1] == "^"

        line4.slice!(i, 1)

        for j in 0...10

          Graphics.update

        end

        redo

      end

      self.contents.clear

      self.contents.draw_text(0, 0, 448, 24, line1)

      self.contents.draw_text(0, 24, 448, 24, line2)

      self.contents.draw_text(0, 48, 448, 24, line3)

      self.contents.draw_text(0, 72, 448, 24, line4[0, i+1])

      Graphics.update

    end

  end

end

(Note: This is a very simple message system that I just made to try to teach myself Ruby/RGSS as I'm new at it. I wrote all the code myself, so if something confuses you while reading it, I can definitely make it clearer.)

The script takes input text and displays it character-by-character, unless that character is '^', in which case it deletes that character and pauses for 10 frames before continuing to display more text. It actually works pretty well. The only problem I'm having is that using Graphics.update pauses not only the text display but everything else, as well. For instance, one scene in which I tried to use it also has the "rain" weather effect occurring. Whenever the game pauses to display text, the rain and other sprite animations also pause. The conclusion I came across was that I'm not supposed to be using Graphics.update, but my attempts at deciphering other, more advanced message systems for the solution have been fruitless. So, I'm asking for help. How can I make the game display text letter-by-letter without using Graphics.update (or taking someone else's message system).
 
All right. What you are doing is actually creating a loop, where the only thing that happens is updating the graphics. This is not a good thing, as that means that nothing else will happen until the loop is done. Instead, I would recommend creating an update method and a timer. You would have the update methods in Scene_Map and Scene_Battle call this update method for the new window. To set up the timer, you would have a variable, which you set to however long you want it to pause before placing the next letter. (I recommend you base it on the scripting FPS, which is 40 frames per second in RMXP and 60 frames per second in RMVX) Then, in the update method, you would have an if statement that checks this variable. If it is at or below 0, you call a method to add the next letter to the message. If not, you subtract 1 from the timer variable, and move on. This will solve your pausing problem, and it will still allow you to make it letter by letter. If you want me to explain that a bit more, or perhaps give an example, go ahead and ask.
 

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