Guest Access
EVENTALIST
EVENTALIST
EVENTALIST
profile
Like in most games you have a console that allows you to edit values while playing the game, this does just that.
If you have a question or comment post here or feel free to PM me.
mr_wiggles
profile
Script Console
Version: 1.2
Author: Mr_Wiggles
Date: Dec. 26, 2010
Version History
Version: 1.2
Author: Mr_Wiggles
Date: Dec. 26, 2010
Version History
- Version 1.2 : Initial Release
Planned Future Versions
- More features, not sure what yet so suggest something.
Description
Like in most games you have a console that allows you to edit values while playing the game, this does just that.
Features
- Have the ability to run script commands from the map and any scene while debugging.
Instructions
Paste in your script database above main but below the default scripts. Open console with F6 while in debug mode. Then just type in your script command.Screenshot
script
- Code:
#==============================================================================
# ** Script Console **
#==============================================================================
# By: Mr Wiggles
# Version: 1.2
# Dec 26, 2010
#==============================================================================
# Instructions
# --------------------------------
# Call from the game map with F6. Once the console is open you are free to
# enter script commands into it. Once you have your command typed press
# Enter to have it evaluated. Use Esc key to exit and return to the game.
#
# NOTE: you can only open the console in debug mode.
#
#==============================================================================
# Usfull Commands
# --------------------------------
# help : displays console commands, "?" also works.
#
# $game_switches[id] : this will allow you to edit the state of the switch.
# e.q. = $game_switches[10] = false
#
# switch_state(id) : returns state of switch
#
# $game_variables[id] : this will allow you to edit the state of the variable.
# e.q. = $game_variables[5] += 5 <- will add 5 to variable
# $game_variables[6] *= 2 <- will multiply the variable by 2
# $game_variables[10] = 2 / 6 + 7
#
# variable_value(id) : returns value of the variable
#
# $scene = Class.new : call scripts from the console.
# e.q. = $scene = Scene_Menu.new <- calls game menu
# $scene = Scene_Title.new <- calls game title
#
# move_console(x, y) : this will move the console to new position
# e.q. = move_console <- return to default posistion
# move_console(100, 100) <- this will move it to the set X and Y
# move_console("up right") <- moves to upper right corner
# knows = "up left", "low left", "up right", "low right", "center"
#
# exit : this will exit the console and return to the map.
#
# clear : clears prevous commands.
#
#==============================================================================
# This just makes the bar blink (aesthetics only), turing this off reduces lag.
BAR_BLINK = false
#==============================================================================
# ** Console
#==============================================================================
class Console
attr_accessor :active
attr_accessor :pause_update
#-----------------------------------------------------------------------------
# * Initialize
#-----------------------------------------------------------------------------
def initialize
@active = false
@text = ""
@max_mem = 4
@pause_update = 0
@frame_wait = 0
@prevous_commands = []
@text_window = Console_Window.new
@text_window.visible = false
end
#-----------------------------------------------------------------------------
# * Update
#-----------------------------------------------------------------------------
def update
# exit loop prevention
if @pause_update != 0
@frame_wait = 5
@active = false
@text_window.visible = false
return
end
if @frame_wait != 0
@frame_wait -= 1
return
end
# close if active and trigger F6
if @active
Key_Map.update
if Key_Map.trigger?(Key_Map::F6)
exit_console
return
end
end
# open if not active and trigger F6
if !@active
@text_window.visible = false
@active = true if Input.trigger?(Input::F6)
return
end
# exit if ESC key was pressed
if Key_Map.trigger?(Key_Map::ESC)
exit_console
return
end
# show console window
return if @text_window.nil?
@text_window.visible = true
# update window
@text_window.update(@text, @prevous_commands)
# remove text if BACKSPACE was pressed
if Key_Map.repeat?(Key_Map::BACKSPACE)
text = ""
if @text.size != 0
for i in 0...@text.size - 1
text += @text[i].chr
end
@text = text
end
return
end
# evaluate command if ENTER was pressed
if Key_Map.trigger?(Key_Map::ENTER)
if @text == "exit"
@prevous_commands.insert(0, @text)
@prevous_commands.delete_at(@max_mem) if @prevous_commands.size > @max_mem
exit_console
return
end
evaluate
return
end
# text overflow prevention
if @text.size < 45
update_keys
else
$game_system.se_play($data_system.buzzer_se) if Key_Map.press_anykey?
end
end
#-----------------------------------------------------------------------------
# * Exit Console
#-----------------------------------------------------------------------------
def exit_console
$game_system.se_play($data_system.cancel_se)
@active = false
@text_window.visible = false
@text = ""
@pause_update = 5
end
#-----------------------------------------------------------------------------
# * Move Console
#-----------------------------------------------------------------------------
def move_console(*args)
args = *args
args = "up left" if args.nil?
if args.is_a?(String)
case args
when "up left" then pos = [-16, -16]
when "low left" then pos = [-16, 365]
when "up right" then pos = [310, -16]
when "low right" then pos = [310, 365]
when "center" then pos = [150, 170]
else
@text = "Invalid Command - " + args
return
end
else
pos = args
end
@text_window.move_self(pos[0], pos[1])
end
#-----------------------------------------------------------------------------
# * Show Variable Value
#-----------------------------------------------------------------------------
def variable_value(id = 1)
@text = "Variable #{id} = #{$game_variables[id]}"
return
end
#-----------------------------------------------------------------------------
# * Show Switch State
#-----------------------------------------------------------------------------
def switch_state(id = 1)
@text = "Switch #{id} = #{$game_switches[id]}"
return
end
#-----------------------------------------------------------------------------
# * Clear Prevous
#-----------------------------------------------------------------------------
def clear
@text = ""
@prevous_commands = []
return
end
#-----------------------------------------------------------------------------
# * Show Help
#-----------------------------------------------------------------------------
def help
@text = ""
help_lines = ["Commands :",
"variable_value(), move_console(), switch_state(),",
"help, exit, clear"]
for line in help_lines
@prevous_commands.insert(0, line)
@prevous_commands.delete_at(@max_mem) if @prevous_commands.size > @max_mem
end
end
#-----------------------------------------------------------------------------
# * Evaluate
#-----------------------------------------------------------------------------
def evaluate
@text = "help" if @text == "?"
if syntax_error?
@text = "Syntax Error - " + @text
else
eval(@text) rescue @text = "Unknown Command - " + @text
end
if @text.include?("Unknown Command") or @text.include?("Syntax Error")
$game_system.se_play($data_system.buzzer_se)
else
$game_system.se_play($data_system.decision_se)
end
if $scene.is_a?(Scene_Map) and @text.include?("$game_")
$game_map.refresh
$scene.update(true)
end
@prevous_commands.insert(0, @text) if @text != ""
@prevous_commands.delete_at(@max_mem) if @prevous_commands.size > @max_mem
text_additions
@text = ""
@text_window.update(@text, @prevous_commands)
end
#-----------------------------------------------------------------------------
# * Text Additions
#-----------------------------------------------------------------------------
def text_additions
# variable
if @text.include?("game_variables")
@text.gsub!(/\[([0-9]+)\]/) {"\1[#{$1}]"}
variable_value($1.to_i)
@prevous_commands.insert(0, @text)
@prevous_commands.delete_at(@max_mem) if @prevous_commands.size > @max_mem
# switch
elsif @text.include?("game_switches")
@text.gsub!(/\[([0-9]+)\]/) {"\1[#{$1}]"}
switch_state($1.to_i)
@prevous_commands.insert(0, @text)
@prevous_commands.delete_at(@max_mem) if @prevous_commands.size > @max_mem
end
end
#-----------------------------------------------------------------------------
# * Error Check
#-----------------------------------------------------------------------------
def syntax_error?
return true if @text == "$" or @text == "@" or @text == "!" or
@text == "%" or @text == "^" or @text == "&" or @text == "*" or
@text == "-" or @text == "=" or @text == ")" or @text == "(" or
@text == "+" or @text == "/" or @text == "<" or @text == ">" or
@text == "." or @text == "," or @text == "\\" or @text == "|"
return true if @text == "not" or @text == "if" or @text == "and" or
@text == "or" or @text == "next" or @text == "end" or
@text == "def" or @text == "class" or @text == "module" or
@text == "else" or @text == "elsif"
return true if @text.count("(") != @text.count(")")
return true if @text.count("[") != @text.count("]")
return true if @text.count("{") != @text.count("}")
return true if (@text.count("\'") % 2) == 1
return true if (@text.count("\"") % 2) == 1
return false
end
#-----------------------------------------------------------------------------
# * Update Keys
#-----------------------------------------------------------------------------
def update_keys
@text += " " if Key_Map.trigger?(Key_Map::SPACE)
#----------------------------------------------------------------
# if shift is depresed then write the chars in higher case
if Key_Map.press?(Key_Map::SHIFT)
@text += "A" if Key_Map.trigger?(Key_Map::A)
@text += "B" if Key_Map.trigger?(Key_Map::B)
@text += "C" if Key_Map.trigger?(Key_Map::C)
@text += "D" if Key_Map.trigger?(Key_Map::D)
@text += "E" if Key_Map.trigger?(Key_Map::E)
@text += "F" if Key_Map.trigger?(Key_Map::F)
@text += "G" if Key_Map.trigger?(Key_Map::G)
@text += "H" if Key_Map.trigger?(Key_Map::H)
@text += "I" if Key_Map.trigger?(Key_Map::I)
@text += "J" if Key_Map.trigger?(Key_Map::J)
@text += "K" if Key_Map.trigger?(Key_Map::K)
@text += "L" if Key_Map.trigger?(Key_Map::L)
@text += "M" if Key_Map.trigger?(Key_Map::M)
@text += "N" if Key_Map.trigger?(Key_Map::N)
@text += "O" if Key_Map.trigger?(Key_Map::O)
@text += "P" if Key_Map.trigger?(Key_Map::P)
@text += "Q" if Key_Map.trigger?(Key_Map::Q)
@text += "R" if Key_Map.trigger?(Key_Map::R)
@text += "S" if Key_Map.trigger?(Key_Map::S)
@text += "T" if Key_Map.trigger?(Key_Map::T)
@text += "U" if Key_Map.trigger?(Key_Map::U)
@text += "V" if Key_Map.trigger?(Key_Map::V)
@text += "W" if Key_Map.trigger?(Key_Map::W)
@text += "X" if Key_Map.trigger?(Key_Map::X)
@text += "Y" if Key_Map.trigger?(Key_Map::Y)
@text += "Z" if Key_Map.trigger?(Key_Map::Z)
#----------------------------------------------------------------
# If shift is not depresed then write in lower case
else
@text += "a" if Key_Map.trigger?(Key_Map::A)
@text += "b" if Key_Map.trigger?(Key_Map::B)
@text += "c" if Key_Map.trigger?(Key_Map::C)
@text += "d" if Key_Map.trigger?(Key_Map::D)
@text += "e" if Key_Map.trigger?(Key_Map::E)
@text += "f" if Key_Map.trigger?(Key_Map::F)
@text += "g" if Key_Map.trigger?(Key_Map::G)
@text += "h" if Key_Map.trigger?(Key_Map::H)
@text += "i" if Key_Map.trigger?(Key_Map::I)
@text += "j" if Key_Map.trigger?(Key_Map::J)
@text += "k" if Key_Map.trigger?(Key_Map::K)
@text += "l" if Key_Map.trigger?(Key_Map::L)
@text += "m" if Key_Map.trigger?(Key_Map::M)
@text += "n" if Key_Map.trigger?(Key_Map::N)
@text += "o" if Key_Map.trigger?(Key_Map::O)
@text += "p" if Key_Map.trigger?(Key_Map::P)
@text += "q" if Key_Map.trigger?(Key_Map::Q)
@text += "r" if Key_Map.trigger?(Key_Map::R)
@text += "s" if Key_Map.trigger?(Key_Map::S)
@text += "t" if Key_Map.trigger?(Key_Map::T)
@text += "u" if Key_Map.trigger?(Key_Map::U)
@text += "v" if Key_Map.trigger?(Key_Map::V)
@text += "w" if Key_Map.trigger?(Key_Map::W)
@text += "x" if Key_Map.trigger?(Key_Map::X)
@text += "y" if Key_Map.trigger?(Key_Map::Y)
@text += "z" if Key_Map.trigger?(Key_Map::Z)
end
#----------------------------------------------------------------
# Numbers
if Key_Map.press?(Key_Map::SHIFT)
@text += "!" if Key_Map.trigger?(Key_Map::NKEY[1])
@text += "@" if Key_Map.trigger?(Key_Map::NKEY[2])
@text += "#" if Key_Map.trigger?(Key_Map::NKEY[3])
@text += "$" if Key_Map.trigger?(Key_Map::NKEY[4])
@text += "%" if Key_Map.trigger?(Key_Map::NKEY[5])
@text += "^" if Key_Map.trigger?(Key_Map::NKEY[6])
@text += "&" if Key_Map.trigger?(Key_Map::NKEY[7])
@text += "*" if Key_Map.trigger?(Key_Map::NKEY[8])
@text += "(" if Key_Map.trigger?(Key_Map::NKEY[9])
@text += ")" if Key_Map.trigger?(Key_Map::NKEY[0])
else
@text += "0" if Key_Map.trigger?(Key_Map::NKEY[0]) or Key_Map.trigger?(Key_Map::NPAD[0])
@text += "1" if Key_Map.trigger?(Key_Map::NKEY[1]) or Key_Map.trigger?(Key_Map::NPAD[1])
@text += "2" if Key_Map.trigger?(Key_Map::NKEY[2]) or Key_Map.trigger?(Key_Map::NPAD[2])
@text += "3" if Key_Map.trigger?(Key_Map::NKEY[3]) or Key_Map.trigger?(Key_Map::NPAD[3])
@text += "4" if Key_Map.trigger?(Key_Map::NKEY[4]) or Key_Map.trigger?(Key_Map::NPAD[4])
@text += "5" if Key_Map.trigger?(Key_Map::NKEY[5]) or Key_Map.trigger?(Key_Map::NPAD[5])
@text += "6" if Key_Map.trigger?(Key_Map::NKEY[6]) or Key_Map.trigger?(Key_Map::NPAD[6])
@text += "7" if Key_Map.trigger?(Key_Map::NKEY[7]) or Key_Map.trigger?(Key_Map::NPAD[7])
@text += "8" if Key_Map.trigger?(Key_Map::NKEY[8]) or Key_Map.trigger?(Key_Map::NPAD[8])
@text += "9" if Key_Map.trigger?(Key_Map::NKEY[9]) or Key_Map.trigger?(Key_Map::NPAD[9])
end
#----------------------------------------------------------------
# Special Keys
if Key_Map.press?(Key_Map::SHIFT)
@text += "_" if Key_Map.trigger?(Key_Map::DASH)
@text += "+" if Key_Map.trigger?(Key_Map::IS)
@text += "{" if Key_Map.trigger?(Key_Map::LBRACK)
@text += "}" if Key_Map.trigger?(Key_Map::RBRACK)
@text += ":" if Key_Map.trigger?(Key_Map::COLON)
@text += "\"" if Key_Map.trigger?(Key_Map::QUOTE)
@text += "<" if Key_Map.trigger?(Key_Map::COMMA)
@text += ">" if Key_Map.trigger?(Key_Map::DOT)
@text += "?" if Key_Map.trigger?(Key_Map::FS)
@text += "|" if Key_Map.trigger?(Key_Map::BS)
@text += "~" if Key_Map.trigger?(Key_Map::TIDLE)
else
@text += "-" if Key_Map.trigger?(Key_Map::DASH)
@text += "=" if Key_Map.trigger?(Key_Map::IS)
@text += "[" if Key_Map.trigger?(Key_Map::LBRACK)
@text += "]" if Key_Map.trigger?(Key_Map::RBRACK)
@text += ";" if Key_Map.trigger?(Key_Map::COLON)
@text += "\'" if Key_Map.trigger?(Key_Map::QUOTE)
@text += "," if Key_Map.trigger?(Key_Map::COMMA)
@text += "." if Key_Map.trigger?(Key_Map::DOT)
@text += "/" if Key_Map.trigger?(Key_Map::FS)
@text += "\\" if Key_Map.trigger?(Key_Map::BS)
@text += "`" if Key_Map.trigger?(Key_Map::TIDLE)
end
end
end
#==============================================================================
# ** Module Input
#==============================================================================
module Input
class << self
alias :console_update :update
def update
if $DEBUG
return if $console.nil?
$console.update
if $console.pause_update != 0
$console.pause_update -= 1
return
end
console_update if !$console.active
else
console_update
end
end
end
end
#==============================================================================
# ** Scene Title
#==============================================================================
class Scene_Title
alias :console_update :update
def update
$console = Console.new if $console.nil? and $DEBUG
console_update
end
end
#==============================================================================
# ** Scene Map
#==============================================================================
class Scene_Map
alias :console_update :update
def update(force = false)
if $DEBUG
return if $console.active and !force
end
console_update
end
end
#============================================================================
# * Console Window
#============================================================================
class Console_Window < Window_Base
def initialize
super(-16, -16, 346, 132)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Arial"
self.opacity = 0
self.z = 210
@blink = 10
@text = ""
@old_text = nil
@prevous_text = []
refresh
end
def refresh
self.contents.clear
self.contents.fill_rect(Rect.new(0, 0, 346, 132), Color.new(10, 10, 10, 150))
self.contents.fill_rect(Rect.new(6, 64, 300, 28), Color.new(10, 10, 10, 210))
self.contents.font.size = 18
width = self.contents.text_size(@text).width
size = width > 290 ? 14 : 18
self.contents.font.size = size
text = @text
if BAR_BLINK
if @blink <= -10
@blink = 10
elsif @blink <= 0
text += "|"
end
@blink -= 1
else
text += "|"
end
self.contents.draw_text(10, 60, 300, 32, text)
self.contents.font.size = 14
size = @prevous_text.size
for i in 0...size
text = @prevous_text[i]
next if text.nil?
self.contents.draw_text(10, 37 - (i * 15), 300, 32, text)
end
end
def update(text, prev_text)
@text = text
@prevous_text = prev_text
if @old_text != @text and !BAR_BLINK
@old_text = @text
refresh
elsif BAR_BLINK
refresh
end
end
def move_self(new_x, new_y)
self.x = new_x
self.y = new_y
refresh
end
end
#==============================================================================
# ** Key Map
#==============================================================================
module Key_Map
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Alphabet Keys
A = 65; N = 78
B = 66; O = 79
C = 67; P = 80
D = 68; Q = 81
E = 69; R = 82
F = 70; S = 83
G = 71; T = 84
H = 72; U = 85
I = 73; V = 86
J = 74; W = 87
K = 75; X = 88
L = 76; Y = 89
M = 77; Z = 90
# Number Keys
zero = 48; five = 53
one = 49; six = 54
two = 50; seven = 55
three = 51; eight = 56
four = 52; nine = 57
NKEY = [zero, one, two, three, four, five, six, seven, eight, nine]
# Numpad Keys
pad0 = 45; pad5 = 12
pad1 = 35; pad6 = 39
pad2 = 40; pad7 = 36
pad3 = 34; pad8 = 38
pad4 = 37; pad9 = 33
NPAD = [pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9]
# Function Keys
F1 = 112; F7 = 118
F2 = 113; F8 = 119
F3 = 114; F9 = 120
F4 = 115; F10 = 121
F5 = 116; F11 = 122
F6 = 117; F12 = 123
# Special Keys
DASH = 189 # -
IS = 187 # =
LBRACK = 219 # [
RBRACK = 221 # ]
COLON = 186 # ;
QUOTE = 222 # '
COMMA = 188 # ,
DOT = 190 # .
FS = 191 # \
BS = 220 # /
TIDLE = 192 # `
# Action Keys
SHIFT = 16 ; BACKSPACE = 8
LSHIFT = 160; SPACE = 32
RSHIFT = 161; ESC = 27
ENTER = 13 ; TAB = 9
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
STATE = Win32API.new('user32', 'GetKeyState', ['i'], 'i')
KEY = Win32API.new('user32', 'GetAsyncKeyState', ['i'], 'i')
# All ASCII keys
All_keys = 8..222
@repeating = []; 256.times{@repeating.push(-1)}
#--------------------------------------------------------------------------
# get_current_state
#--------------------------------------------------------------------------
def self.get_current_state(key)
return STATE.call(key).between?(0, 1)
end
#--------------------------------------------------------------------------
# test_key
#--------------------------------------------------------------------------
def self.test_key(key)
return (KEY.call(key) & 0x01 == 1)
end
#--------------------------------------------------------------------------
# update
#--------------------------------------------------------------------------
def self.update
@_keys = (@_keys == nil ? [] : @_keys) | (@keys == nil ? [] : @keys.clone)
@keys, @pressed = [], []
All_keys.each {|key|
@keys.push(key) if test_key(key) && !@_keys.include?(key)
if get_current_state(key)
@_keys.delete(key)
@repeating[key] = 0
else
@pressed.push(key)
if @repeating[key] > 0
if @repeating[key] < 17
@repeating[key] += 1
else
@repeating[key] = 14
end
else
@repeating[key] = 1
end
end}
end
#--------------------------------------------------------------------------
# press_anykey?
#--------------------------------------------------------------------------
def self.press_anykey?
for key in All_keys
return true if trigger?(key)
end
return false
end
#--------------------------------------------------------------------------
# trigger?
#--------------------------------------------------------------------------
def self.trigger?(keys)
keys = [keys] unless keys.is_a?(Array)
return (keys.any? {|key| @keys.include?(key) && !@_keys.include?(key)})
end
#--------------------------------------------------------------------------
# press?
#--------------------------------------------------------------------------
def self.press?(keys)
keys = [keys] unless keys.is_a?(Array)
return (keys.any? {|key| @pressed.include?(key)})
end
#--------------------------------------------------------------------------
# repeat?
#--------------------------------------------------------------------------
def self.repeat?(keys)
keys = [keys] unless keys.is_a?(Array)
return (keys.any? {|key| [1, 16].include?(@repeating[key])})
end
end
Support
If you have a question or comment post here or feel free to PM me.
Known Compatibility Issues
None that i know of.
Restrictions
DO NOT POST ON ANY OTHER SITE WITH OUT MY PERMISSION. You are free to edit for YOUR USE only and i must be credited.None that i know of.
Restrictions
EVENTALIST
Show Signature
EVENTALIST
Administrator
Administrator
Administrator
profile
G@MeF@Ce
profile
Wiggles! another great script, this one gives a quick to call and an easier interface in debug for testing and on the fly script command ... thanks for sharing.
Administrator
Show Signature