Show Question
#1
Show Question
by Sheol
Version: 1.0
Jul 23 2006

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Last Update

July 23, 2006.

Introduction

This script allow you make questions to the player. This script works similar to the Game Maker's function: show_question(string)

Features
  • You just need to specify the question, but you can specify x, y, width and height of the window.
  • The newlines are made automatic.

Script


Code:
#==============================================================================
# ** Show Question
#------------------------------------------------------------------------------
# Slipknot
# 0.1
# 07.22.06
#==============================================================================

class Window_Question < Window_Selectable
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  Word_Yes = 'Yes'
  Word_No = 'No'
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height, text)
    super(x, y, width, height)
    self.contents = Bitmap.new(width - 32, height - 32)
    @text, @commands = text, [Word_Yes, Word_No]
    @index, @cursor_width = 0, 40
    @commands.each do |word|
      w = contents.text_size(word).width + 8
      @cursor_width = [@cursor_width, w].max
    end
    @item_max = @column_max = 2
    x, y, @cx = 4, 0, ((width - 40) - @cursor_width * 2 - 32) / 2
    @text.scan(/[\w'"¿?¡!]+/).each do |word|
      w = contents.text_size(word + ' ').width
      if x + w > width - 40
        x = 4
        y += 32
      end
      contents.draw_text(x, y, w, 32, word)
      x += w
    end
    @cy = y + 32
    x = 0
    @commands.each do |word|
      contents.draw_text(@cx + x, @cy, @cursor_width, 32, word, 1)
      x += @cursor_width + 32
    end
  end
  #--------------------------------------------------------------------------
  # * Update Cursor Rectangle
  #--------------------------------------------------------------------------
  def update_cursor_rect
    x = @cx + @index * @cursor_width + (@index == 0 ? 0 : 32)
    cursor_rect.set(x, @cy, @cursor_width, 32)
  end
end

class Interpreter
  #--------------------------------------------------------------------------
  # * Show Question
  # string : the question
  # hash : the hash keys: 'x', 'y', 'width', 'height'
  #--------------------------------------------------------------------------
  def show_question(string, hash = {})
    x = hash['x'] ? hash['x'] : 160
    y = hash['y'] ? hash['y'] : 320
    width = hash['width'] ? hash['width'] : 320
    height = hash['height'] ? hash['height'] : 96
    window, result = Window_Question.new(x, y, width, height, string), nil
    until result != nil
      Graphics.update
      Input.update
      window.update
      if Input.trigger?(Input::C)
        $game_system.se_play($data_system.decision_se)
        result = window.index == 0
      elsif Input.trigger?(Input::B)
        $game_system.se_play($data_system.cancel_se)
        result = false
      end
    end
    Input.update
    window.dispose
    return result
  end
end

Instructions

You need paste the code before Main.
To store the result in the variable 1 do this in the call script command:

Code:
$game_variables[1] = show_question('some text')

To draw it on top of the screen:

Code:
show_question('some text', 'y' => 32)


Compatibility

This script must work with anything.

Author's Notes

Enjoy it!
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Show a Message in any Scene Tsunokiette 1 3,459 08-17-2006, 01:15 PM
Last Post: GoldenShadow
  Show Map Name Sheol 0 2,521 04-02-2006, 01:00 PM
Last Post: Sheol
  Show all status names Guedez 0 2,328 12-26-2005, 01:00 PM
Last Post: Guedez



Users browsing this thread: 1 Guest(s)