Module Hash Questions

Here is my method of word wrapper, it uses draw_text_ex though, and it's kinda laggy
Code:
  def process_character(c, text, pos)
    @text = text
    if text[0] != ' '
      w = text_size(get_word(text)).width + 6
      if (pos[:x] + w) >= contents.width
        process_new_line(text, pos)
        return
      end
    end
    super
  end
 
  def get_word(text)
    result = ''
    text.each_char do |c|
      break if c =~ /\s/
      result += c
    end
    result
  end
Here is my method of word wrapper, it uses draw_text_ex though, and it's kinda laggy
Code:
  def process_character(c, text, pos)
    @text = text
    if text[0] != ' '
      w = text_size(get_word(text)).width + 6
      if (pos[:x] + w) >= contents.width
        process_new_line(text, pos)
        return
      end
    end
    super
  end

How do you use either of these? And in what order? XD
 
  def get_word(text)
    result = ''
    text.each_char do |c|
      break if c =~ /\s/
      result += c
    end
    result
  end
Does the original text wrapper work if you do it like this?
Code:
  def draw_quest_description(quest_id)
    text = Setup.word_wrapper(self, Setup::Quests[quest_id][:description])
    draw_text_ex(0, 0, text)
  end

The reason being that draw_text_ex should include the text as altered by the word wrapper, and you haven't done that. You've just asked it to directly draw what was in the quest description.

Also, I notice you've added a function in Game_System to put all the quests into the variable @quests, but you never use this—you keep going back to the Setup module. You can use $game_system.quests instead.

On another note, when you're iterating over a hash, you can do hash.each_key if you just want to use the key, and hash.each_value if you just want to use the value. Engr. Adiktuzmiko mentioned this on previous page.
Cool, I got it to word wrap. Thank you. Also, how do you suggest I use the id keys I put into the variable I made? Cause outside of using it as an index, I cannot access the description of the quests without accessing the hash directly as far as I can tell.
So I found an issue with the script if you add more than one quest they write over one another in the window. Just when I thought I was out. XD I need to figure out now how to set up columns.

Wyn Wizard, please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.


If you want to add something after you posted, please use the 'Edit' button in the future.

Original thread: https://forums.rpgmakerweb.com/threads/module-hash-questions.99155/