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.

Show Question

Show Question
Version: 1.0

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.

Screenshot

http://img230.imageshack.us/img230/2699/showquestiondu0.jpg[/IMG]

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! :P
 
People will have problems calling it that way.
If you want to use it, place it in the call script window like this:

Code:
$game_variables[1] = show_question(
'some text')
 
sandgolem said:
People will have problems calling it that way.
If you want to use it, place it in the call script window like this:

Code:
$game_variables[1] = show_question(
'some text')
I don't understand, is not the same?
 
No. The code you posted to call that would only work in one badly hacked-up illegal version. The real RMXP splits it like this:

$game_variables[1] = show_question
('some text')
Do not use this code, just an example

The "('some text')" would not be associated with show_question and it'll crash
 

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