Version: 3.1.1
Introduction
Some months ago, I have post my console script. It was a good start but very buggy and not user friendly. I have decided to repost the new script to get rid of the old topic.
As the title says, this is a console script. The console let you debug your game by writing down script into it. It does almost the same thing as the "Call Script" command but you can call the console scene anytime on the map by pressing "~".
You will notice that only a one-lined text field is available. Don't worry, you can work as if you were working in a multi-lined text field!
Examples and tutorials
1)Creating and using a global variable
First of all, enter $your_variable = x in the console
It will remember this variable forever.
Them if you want to use it, just place $your_variable anywhere in your new line.
Ex:
Line1: $x = $game_player.x
Line2: $x += 1
Line3: p $x
Line4: $game_actors[1].name += $x.to_s
Line5: p $game_actors[1].name
2)Multi-lined code
The console doesn't support multi-lined text field. However, you can "fake" it. Instead of pressing Enter to add a new line, put a semicolon ";" after an operation.
Ex:
if $game_player.x == 0; $game_player.moveto(10,10); end
Screenshots
http://img46.imageshack.us/img46/2351/c ... xx6.th.jpg[/img]
Demo
Not yet. I think than this script is easy enough to use!
Don't you?
Script
Here's the good part!
Code:
#==============================================================================
# ** Console Script
#==============================================================================
# Dargor
# Version 3.1.1
# 20.01.07
#==============================================================================
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log("Console Script", "Dargor", 3, "20.01.07")
#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state("Console Script") == true
# Console module
module CONSOLE
def self.update(log)
$game_temp.console_log.push("~"+$log)
$game_temp.txt_console_log.push("~"+$log)
$game_temp.console_refresh = true
self.eval_commands($log)
end
def self.eval_commands(command)
case command
when "god"
# code
add("God mode on")
else
value = eval(command) rescue add("Unknown command #{command}");
add("#{command} is #{value}") if value != [] and value != nil
end
end
def self.add(text)
if $game_temp == nil
$game_temp = Game_Temp.new
end
$game_temp.console_log.push(text)
$game_temp.txt_console_log.push(text)
$game_temp.console_refresh = true
if $game_temp.txt_logging == false
$game_temp.txt_console_log.clear
end
end
end
#=============================================================================
# ** Input Created by: Cybersam
#-----------------------------------------------------------------------------
#  Adds full keyboard support to module Input.
#=============================================================================
module Input
#--------------------------------------------------------------------------
# * Returns true when a key is pressed.
#--------------------------------------------------------------------------
def Input.getkey(key)
Win32API.new("user32", "GetAsyncKeyState", "i", "i").call(key) & 0x01 == 1
end
#--------------------------------------------------------------------------
# * Returns a key's state.
#--------------------------------------------------------------------------
def Input.getstate(key)
return (not Win32API.new("user32", "GetKeyState", "i", "i").call(key).between?(0, 1))
end
end
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
# This class handles temporary data that is not included with save data.
# Refer to "$game_temp" for the instance of this class.
#==============================================================================
class Game_Temp
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :console_refresh
attr_accessor :console_log
attr_accessor :txt_console_log
attr_accessor :txt_logging
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias console_initialize initialize
def initialize
console_initialize
@console_refresh = false
@console_log = []
@txt_console_log = []
@txt_logging = false
end
end
#=============================================================================
# ** Window_Console
#-----------------------------------------------------------------------------
#  Displays console messages.
#=============================================================================
class Window_Console < Window_Base
#--------------------------------------------------------------------------
# * Initializes console window.
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 432)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.size = 16
self.back_opacity = 160
refresh
end
#--------------------------------------------------------------------------
# * Refreshes console window.
#--------------------------------------------------------------------------
def refresh
$game_temp.console_log.delete_at(0) while $game_temp.console_log.size > 25
self.contents.clear
for i in 0..$game_temp.console_log.size - 1
self.contents.draw_text(0, i * 16 - 8, 640, 32, $game_temp.console_log[i])
end
CONSOLE.update_txt_logging if $game_temp.txt_logging
$game_temp.console_refresh = false
end
#--------------------------------------------------------------------------
# * Updates console window.
#--------------------------------------------------------------------------
def update
refresh if $game_temp.console_refresh
super
end
end
#=============================================================================
# ** Window_ConsoleInput Originally created by: Cybersam
#-----------------------------------------------------------------------------
#  Based on the Full-Keyboard Input script created by Cybersam.
#=============================================================================
class Window_ConsoleInput < Window_Base
#--------------------------------------------------------------------------
# * Initializes console input window.
#--------------------------------------------------------------------------
def initialize
super(0, 432, 640, 48)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.size = 16
self.back_opacity = 160
@text = []
refresh
end
#--------------------------------------------------------------------------
# * Refreshes console input window.
#--------------------------------------------------------------------------
def refresh
$log = @text.to_s
self.contents.clear
cx = contents.text_size("~" + @text.to_s + "_").width
if cx >= 600
x = 640-cx - 40
else
x = 0
end
self.contents.draw_text(x+8, -16, 10000, 48, "~" + @text.to_s + "_")
rect = Rect.new(0,-16,16,48)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(0, -16, 32, 48, "~")
end
#--------------------------------------------------------------------------
# * Refreshes console input window.
#--------------------------------------------------------------------------
def add(char)
@text.push(char.to_s)
refresh
end
#--------------------------------------------------------------------------
# * Refreshes console input window.
#--------------------------------------------------------------------------
def clear
@text = []
refresh
end
#--------------------------------------------------------------------------
# * Updates input console window.
#--------------------------------------------------------------------------
def update
# Sends console message.
if Input.getkey(13)
if @text.size == 0
$game_system.se_play($data_system.buzzer_se)
else
@text.clear
refresh
end
end
# Removes last entry in test.
if Input.getkey(8)
if @text.size == 0
$game_system.se_play($data_system.buzzer_se)
else
@text.delete_at(-1)
refresh
end
end
# Adds a pressed key.
if Input.getstate(16)
add("A") if Input.getkey(65)
add("B") if Input.getkey(66)
add("C") if Input.getkey(67)
add("D") if Input.getkey(68)
add("E") if Input.getkey(69)
add("F") if Input.getkey(70)
add("G") if Input.getkey(71)
add("H") if Input.getkey(72)
add("7I") if Input.getkey(73)
add("J") if Input.getkey(74)
add("K") if Input.getkey(75)
add("L") if Input.getkey(76)
add("M") if Input.getkey(77)
add("N") if Input.getkey(78)
add("O") if Input.getkey(79)
add("P") if Input.getkey(80)
add("Q") if Input.getkey(81)
add("R") if Input.getkey(82)
add("S") if Input.getkey(83)
add("T") if Input.getkey(84)
add("U") if Input.getkey(85)
add("V") if Input.getkey(86)
add("W") if Input.getkey(87)
add("X") if Input.getkey(88)
add("Y") if Input.getkey(89)
add("Z") if Input.getkey(90)
add(")") if Input.getkey(48)
add("!") if Input.getkey(49)
add("@") if Input.getkey(50)
add("#") if Input.getkey(51)
add("$") if Input.getkey(52)
add("%") if Input.getkey(53)
add("^") if Input.getkey(54)
add("&") if Input.getkey(55)
add("*") if Input.getkey(56)
add("(") if Input.getkey(57)
add(":") if Input.getkey(186)
add("+") if Input.getkey(187)
add("<") if Input.getkey(188)
add("_") if Input.getkey(189)
add(">") if Input.getkey(190)
add("?") if Input.getkey(191)
add("{") if Input.getkey(219)
add("|") if Input.getkey(220)
add("}") if Input.getkey(221)
add("\"") if Input.getkey(222)
else
add("a") if Input.getkey(65)
add("b") if Input.getkey(66)
add("c") if Input.getkey(67)
add("d") if Input.getkey(68)
add("e") if Input.getkey(69)
add("f") if Input.getkey(70)
add("g") if Input.getkey(71)
add("h") if Input.getkey(72)
add("i") if Input.getkey(73)
add("j") if Input.getkey(74)
add("k") if Input.getkey(75)
add("l") if Input.getkey(76)
add("m") if Input.getkey(77)
add("n") if Input.getkey(78)
add("o") if Input.getkey(79)
add("p") if Input.getkey(80)
add("q") if Input.getkey(81)
add("r") if Input.getkey(82)
add("s") if Input.getkey(83)
add("t") if Input.getkey(84)
add("u") if Input.getkey(85)
add("v") if Input.getkey(86)
add("w") if Input.getkey(87)
add("x") if Input.getkey(88)
add("y") if Input.getkey(89)
add("z") if Input.getkey(90)
add("0") if Input.getkey(48)
add("1") if Input.getkey(49)
add("2") if Input.getkey(50)
add("3") if Input.getkey(51)
add("4") if Input.getkey(52)
add("5") if Input.getkey(53)
add("6") if Input.getkey(54)
add("7") if Input.getkey(55)
add("8") if Input.getkey(56)
add("9") if Input.getkey(57)
add(";") if Input.getkey(186)
add("=) if Input.getkey(187)
add(",") if Input.getkey(188)
add("-") if Input.getkey(189)
add(".") if Input.getkey(190)
add("/") if Input.getkey(191)
add("[") if Input.getkey(219)
add("\\") if Input.getkey(220)
add(]") if Input.getkey(221)
add("'") if Input.getkey(222)
end
add(" ") if Input.getkey(32)
add("*") if Input.getkey(106)
add("+") if Input.getkey(107)
add("-") if Input.getkey(109)
add("/") if Input.getkey(111)
end
end
#=============================================================================
# ** Scene_Console
#-----------------------------------------------------------------------------
#  Creates the console.
#=============================================================================
class Scene_Console
def main
@spriteset = Spriteset_Map.new
@console_window = Window_Console.new
@input_window = Window_ConsoleInput.new
Graphics.transition
loop do
Graphics.update
update
if $scene != self
break
end
end
Graphics.freeze
@spriteset.dispose
@console_window.dispose
@input_window.dispose
end
def update
$game_map.update
$game_system.map_interpreter.update
$game_system.update
$game_screen.update
@spriteset.update
if Input.getkey(13)
CONSOLE.update($log)
@input_window.clear
end
@console_window.update
@input_window.update
if Input.getkey(27)
$scene = Scene_Map.new
end
end
end
class Scene_Map
alias console_update update
def update
console_update
if Input.getkey(222)
if $DEBUG
$scene = Scene_Console.new
end
end
end
end
#------------------------------------------------------------------------------
# * End SDK Enable Test
#------------------------------------------------------------------------------
end
Instructions
Just place it above main and under every other scripts.
FAQ
none
Compatibility
Compatible with any scripts
Can be used without SDK
Credits and Thanks
Well, the only one to credit is me I guess!
Author's Notes
*IMPORTANT*
1) The game will crash if you input only numbers separated with an empty space.
ex: entering 12345 67890 into the console will make the game crash.