Page 1 of 1
Rewritten DebugConsole
Posted: Sat Aug 21, 2010 12:16 am
by yufra
So I have no idea how much DG and others use the DebugConsole, but I thought I would take a look at it to see if I could improve it a bit. I had used it for some very basic stuff before, and only after looking through the source code did I realize the that "=" returns the output to the DebugConsole, like an in-game print. Previously I had been using the print command and looking at the stdout.
The highlights of the rewrite are as follows:
- Supports scrolling of the output using the mousewheel, similar to ToME's LogDisplay. The current command will always be visible at the bottom of the console.
- Added a "==" magic, which is a pretty print for table contents (uses pairs, not ipairs)... currently only supports depth=1 (pure recursive would crash)
- Added a four spaces to returned output to shift it relative to entered commands. Applies to both the "=" and "==" magics.
- Reversed the order of the UP and DOWN keystrokes so that pressing UP will give you the previous command and DOWN will return you back to the current command.
I will probably look at changing the colors of the commands and returned output to help guide the eye a bit, but wanted to get this first revision out there for feedback. Do people use the DebugConsole? Would you if it supported feature X? I personally like having an in-game tool for introspection.

Re: Rewritten DebugConsole
Posted: Sat Aug 21, 2010 12:46 am
by darkgod
I could not code without it
A few notes:
* The command results appear before the list of commands it looks weird

* Indent the code with tabs please

* when trying the == thing I got:
Lua Error: /engine/DebugConsole.lua:53: bad argument #1 to 'pairs' (table expected, got number)
At [C]:-1
At [C]:-1 pairs
At /engine/DebugConsole.lua:53 plain
At /engine/KeyCommand.lua:73 receiveKey
At /engine/KeyBind.lua:208
using those commands:
a={1,2,3,a=3}
==a
Otherwise is neat! Me wants it !
Re: Rewritten DebugConsole
Posted: Sat Aug 21, 2010 2:04 am
by yufra
darkgod wrote:I could not code without it

Really! Do you mind giving a bit of insight into how you use it? A tips/tricks thread from DG on module development would be nice.
* The command results appear before the list of commands it looks weird
I didn't realize what you meant until I tried the "=" magic in the code block below... fixed now, though.
* Indent the code with tabs please
Whoops, sorry. I am developing under Windows right now (usually on Mac) and the editor I had was defaulting to spaces instead of tabs. Should be fixed in the attached file.
* when trying the == thing I got:
Lua Error: /engine/DebugConsole.lua:53: bad argument #1 to 'pairs' (table expected, got number)
At [C]:-1
At [C]:-1 pairs
At /engine/DebugConsole.lua:53 plain
At /engine/KeyCommand.lua:73 receiveKey
At /engine/KeyBind.lua:208
using those commands:
a={1,2,3,a=3}
==a
Now this is a real question mark. The only thing I can think of is to upload the entire lua file instead of a patch and see if maybe the patch was wrong. Here is an example session and the output I get from running this modified DebugConsole on t-engine4-windows-1.0.0beta9b:
Code: Select all
a = {1, 2, 3, a=4}
=a
1 :=: table: myaddress
==a
1 :=: 1
2 :=: 2
3 :=: 3
a :=: 4
An additional caveat is that the "==" table magic only works with the "." delimited tables right now. For example, "==game.player" will work, but "==game['player']" will not. I haven't thought about fixing it for now, but if that is something you want to use then let me know.
Re: Rewritten DebugConsole
Posted: Sat Aug 21, 2010 9:27 am
by darkgod
Thanks, commited
Well I use it to teleport to zones, give myself levels, intrinsincs, reset my mana, ...
ToME is a very big game already so teleporting around is vital to test
Re: Rewritten DebugConsole
Posted: Sat Aug 21, 2010 12:47 pm
by yufra
I see, more of a speed-up for testing than for debugging and introspection.
Re: Rewritten DebugConsole
Posted: Fri Aug 27, 2010 11:25 am
by Kemsha
Ok, this must be a dumb question but what's the DebugConsole and how can I use it?
I've been playing around with a new module but I haven't been able to try anything too complex because I only use the print -> stdout technique
I've been a programmer for years (not with LUA obviously) and I know the difference debug does
I work in windows and have no special programs (I use Wordpad to edit the lua files...)
Re: Rewritten DebugConsole
Posted: Fri Aug 27, 2010 12:08 pm
by darkgod
Welcome module maker !
First, on windows you should use Notepad++ to edit your files, it supports lua syntax and is quite nice (much better than wordpad at least

)
The DebugConsole can be call like that:
Code: Select all
self:registerDialog(require("engine.DebugConsole").new())
Probably you want it bound to the LUA_CONSOLE keybind (ctrl+l)
From within it you can type any arbitrary line of lua code, allowing you to change things on the fly and you can inspect the values of expressions like this
= expr
I.E:
= 1 + 3
will print 4
So if you do:
= game.player.life
You'll see the current player HP and so on