04-14-2011, 01:00 PM (This post was last modified: 05-19-2017, 04:09 AM by DerVVulfman.)
Jaber's Debug Console
Jaberwocky
Apr 14 2011
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given.
This is the greatest debug console you will ever see.
Why? Because I made it.
Features:
-Omnipresent
-Omnipotent
-Omniscient
No, seriously. Omnipresent
It works anywhere at anytime from the title to battletests to your menus.
Omnipotent
It is an on-demand script call so it can do basically anything.
Omniscient
It has a special @routine variable. If it is nil, it does nothing. If it is not, it evals every frame.
Punch in:
@routine = '@textdata[0] = $game_variables[5].to_s; write("")'
OH SNAP CONSOLE NOW WORKS AS A DEBUG MONITOR
Use $console.writeline instead of p to non-intrusively debug your scripts, or use $console.log to log the debug lines to a file.
Set @debug_show to true and the console will stay visible when inactive so you can monitor any debug lines from your scripts as they happen.
HOLY SHIT JABER, SIGN ME UP
Setup is simple:
1. Delete the following from Scene_Map:
Code:
# If debug mode is ON and F9 key was pressed
if $DEBUG and Input.press?(Input::F9)
# Set debug calling flag
$game_temp.debug_calling = true
end
2. Paste '$console = Window_Console.new' after the '$game_system = Game_System.new' line in Scene_Title's main and battle_test methods.
3. Paste this above main:
The Script
Code:
#Jaber's Debug Console v1.02
class Window_Console < Window_Base
def update
if @routine != nil
begin
eval(@routine)
rescue Exception
@routine = "@is_active = true; writeline('--Exception raised on routine eval!'); @routine = nil"
end
end
if Input.trigger?(Input::F9) or @is_active
@is_active = true
@textdata[0] = ""
write
@keys[120] = 2
end
self.visible = (@is_active or @debug_show)
super if self.visible
while @is_active
Graphics.update
console_update
super
end
end
def key_down(key)
return @keys[key] > 0
end
def key_toggle(key)
return @key.call(key) % 2 == 1
end
def key_trigger(key)
return @keys[key] == 1
end
def key_release(key)
return @keys[key] == -1
end
def key_hold(key, hold)
return (@keys[key] >= hold)
end
def key_repeat(key, hold = 10, throttle = 3)
return (key_trigger(key) or (key_hold(key, hold) and @keys[key] % throttle == 0))
end # Input.repeat: hold=15 throttle=4
def update_keys
update_keyboard
i = 0
for key in @keyboard
@keys[i] = 0 if @keys[i] == nil
if (key.unpack("B*")[0].to_i > 1) or @keys[i] < 0
@keys[i] += 1 if @keys[i] < 15000
elsif @keys[i] > 0
@keys[i] = -1
end
i += 1
end
end
def update_text
@text = []
caps = key_toggle(20) != key_down(16)
for i in 65..90
@text.push(i + (caps ? 0 : 32)) if key_repeat(i)
end
caps = key_down(16)
for i in 48..57
@text.push(i) if key_repeat(i)
end
@text.push(caps ? 58 : 59) if key_repeat(186)
@text.push(caps ? 43 : 61) if key_repeat(187)
@text.push(caps ? 60 : 44) if key_repeat(188)
@text.push(caps ? 95 : 45) if key_repeat(189)
@text.push(caps ? 62 : 46) if key_repeat(190)
@text.push(caps ? 63 : 47) if key_repeat(191)
@text.push(caps ? 126 : 96) if key_repeat(192)
@text.push(caps ? 123 : 91) if key_repeat(219)
@text.push(caps ? 124 : 92) if key_repeat(220)
@text.push(caps ? 125 : 93) if key_repeat(221)
@text.push(caps ? 34 : 39) if key_repeat(222)
@text.push(32) if key_repeat(32)
@text = @text.pack("c*")
if caps
@text.gsub!(/1/) { "!" }
@text.gsub!(/2/) { "@" }
@text.gsub!(/3/) { "#" }
@text.gsub!(/4/) { "$" }
@text.gsub!(/5/) { "%" }
@text.gsub!(/6/) { "^" }
@text.gsub!(/7/) { "&" }
@text.gsub!(/8/) { "*" }
@text.gsub!(/9/) { "(" }
@text.gsub!(/0/) { ")" }
end
return !@text.empty?
end
def console_update
update_keys
last_text = @textdata[0].dup
last_insert = @insert_position
if update_text
if @insert_position == @textdata[0].length
@textdata[0] += @text
else
@textdata[0].slice!(@insert_position, @text.length) if key_toggle(45)
@textdata[0].insert(@insert_position, @text)
end
@insert_position += @text.length
end
if key_repeat(8) and @insert_position > 0
@insert_position -= 1
@textdata[0].slice!(@insert_position, 1)
end
@textdata[0].slice!(@insert_position, 1) if (key_repeat(46) and @insert_position < @textdata[0].length)
if key_repeat(35)
@insert_position = @textdata[0].length
elsif key_repeat(36)
@insert_position = 0
elsif key_repeat(37)
@insert_position = [@insert_position - 1, 0].max
elsif key_repeat(39)
@insert_position = [@insert_position + 1, @textdata[0].length].min
elsif key_repeat(38)
@memory_position = [@memory_position + 1, @memory.length - 1].min
@textdata[0] = @memory[@memory_position].dup if @memory_position >= 0
@insert_position = @textdata[0].length
elsif key_repeat(40)
@memory_position = [@memory_position - 1, -1].max
@textdata[0] = @memory_position == -1 ? "" : @memory[@memory_position].dup
@insert_position = @textdata[0].length
end
if key_repeat(13)
unless @textdata[0] == ""
@memory.unshift(@textdata[0])
@memory.pop if @memory.length > @linemax
end
writeline
begin
text_eval = @textdata[1].dup
text_eval.slice!(0,5) if @textdata[1].index(/[Ss][Hh][Oo][Ww] /) == 0
val = eval(text_eval)
writeline("=>" + val.inspect.to_s) if @textdata[1].index(/[Ss][Hh][Oo][Ww] /) == 0
rescue NameError
writeline("--NameError: No such method or variable")
rescue SyntaxError
writeline("--SyntaxError: Cannot eval this line")
rescue Exception
writeline("--Cannot eval this line")
end
@insert_position = 0
@memory_position = -1
write
elsif last_text != @textdata[0] or last_insert != @insert_position
write
end
if @clear_lines
@clear_lines = false
self.contents.clear
@textdata = [""]
write
end
if key_trigger(120)
@is_active = false
@keys = []
@textdata[0] = ""
@insert_position = 0
@memory_position = -1
write("")
Input.update
end
end
def draw_shadowed_text(x, y, wid, hei, text, align = 0, thickness = 1, direction = [2,3,6], olcolor = Color.new(0,0,0), incolor = Color.new(255,255,255))
color = self.font.color.dup
self.font.color = olcolor
draw_text(x - thickness,y + thickness,wid,hei,text, align) if direction.include?(1)
draw_text(x,y + thickness,wid,hei,text, align) if direction.include?(2)
draw_text(x + thickness,y + thickness,wid,hei,text, align) if direction.include?(3)
draw_text(x - thickness,y,wid,hei,text, align) if direction.include?(4)
draw_text(x + thickness,y,wid,hei,text, align) if direction.include?(6)
draw_text(x - thickness,y - thickness,wid,hei,text, align) if direction.include?(7)
draw_text(x,y - thickness,wid,hei,text, align) if direction.include?(8)
draw_text(x + thickness,y - thickness,wid,hei,text, align) if direction.include?(9)
self.font.color = color
self.font.color = incolor if incolor.is_a?(Color)
draw_text(x,y,wid,hei,text, align)
self.font.color = color
end
end
module Input
class << self
alias console_update update unless method_defined?(:console_update)
def update
console_update
$console.update
end
end
end
4. You're done!
Using the console
Press F9 to open/close the console. Gameplay will be paused while it is opened.
Type 'show' at the start of the line to display the output from that line, e.g. 'show $game_actors[1].hp'
Left/Right arrows move the cursor left/right. Up/Down arrows access previously entered commands.
You can clear the console window by typing in 'clear_lines'
The console has support for all my keys except the numberpad. Insert, delete, home, end, etc. all work.
Screenshots
A.K.A. PICTURES OF TEXT ON TOP OF PICTURES (Click to enlarge)
Changelog
1.02 - No longer requires replacing Input.update calls, thanks to Glitchfinder
1.01 - Replaced heavy outlines with shadowed text for better readability and less lag