Difference between revisions of "Debugging"

From Tales of Maj'Eyal
Jump to: navigation, search
(Added Example of changing actor's phys resistance)
(Formatting. Minor updates)
Line 1: Line 1:
== Debugging: Figuring out what went wrong ==
+
Developer Mode (also known as "cheat") is a special game mode geared towards development of modules and addons for the game.
  
=== Updating your configuration ===
+
The easiest way to enable this mode is to select ''Developer Mode'' from the Options menu.
Enabling cheat/development mode will grant you access to the internal Lua console and some additional dialogs/options useful for debugging.  It will stop you from uploading characters online, though, but you can always turn this mode off.
+
  
<ul>
+
=Overview=
<li>Navigate to the corresponding configuration directory (replace HOME with your home directory).
+
Developer mode grants the user several privileges and disables others to prevent abuse.
 +
 
 +
Pros:
 +
* The ability to see hidden modules
 +
* Access to the internal Lua console
 +
* Additional debugging dialogs/options
 +
 
 +
Cons:
 +
* Disables uploading characters online
 +
* Invalidates game saves loaded while enabled, making them permanently ineligible for achievements.
 +
 
 +
=Config location=
 +
 
 +
Developer Mode is saved as a setting in <code>cheat.cfg</code> in one of the following directories based off your OS. Deleting this file will disable Developer Mode. If enabled, the value for the <code>cheat</code> key is either <code>true</code> or <code>false</code>.
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 14: Line 26:
 
| Mac OSX || HOME\Library\Application Support\T-Engine\4.0\settings ||
 
| Mac OSX || HOME\Library\Application Support\T-Engine\4.0\settings ||
 
|}
 
|}
</li>
 
<li>Create a file called ''cheat.cfg'' in that directory, and put the following text in that file.
 
<pre>
 
cheat = true
 
</pre>
 
<li>
 
To turn cheat/development mode off, just change ''true'' to ''false'' or delete the ''cheat.cfg'' file.
 
</li>
 
</ul>
 
  
=== Inside of ToME ===
+
=Game options=
  
Enabling cheat mode gives you the following functions:
+
Enabling cheat mode gives you the following options:
  
 
{| class="wikitable"
 
{| class="wikitable"
 
! Key Shortcut !! Result
 
! Key Shortcut !! Result
 
|-
 
|-
| Ctrl+L || Lua console  
+
| Ctrl+L || Lua console. Click on the console title bar or outside the window to exit.
 
|-
 
|-
 
| (not assigned by default) || Debug menu
 
| (not assigned by default) || Debug menu
Line 50: Line 53:
 
|}
 
|}
  
=== Debug menu ===
+
=Debug menu=
  
 
Debug menu (aka debug mode) offers a menu with various options like changing zones, creating items, altering quests, etc.  All of this can also be done via the Lua console, but the debug menu is much easier to use.
 
Debug menu (aka debug mode) offers a menu with various options like changing zones, creating items, altering quests, etc.  All of this can also be done via the Lua console, but the debug menu is much easier to use.
Line 56: Line 59:
 
The keybinding for debug mode may not be assigned by default.  Press Esc and go under Key Bindings to assign it.
 
The keybinding for debug mode may not be assigned by default.  Press Esc and go under Key Bindings to assign it.
  
=== Lua console ===
+
=Lua console =
  
 
Summary of features:
 
Summary of features:
Line 64: Line 67:
 
* Copy and paste with system clipboard
 
* Copy and paste with system clipboard
  
The Lua console drops you into the global namespace and gives you access to [[t4modules engine structure|the engine]].  If you want to inspect values, start the line with an equal sign.  For example, say you want to inspect the player:
+
The Lua console drops you into the global namespace and gives you access to [[T4_Modules_Howto_Guide/Engine_Structure|the engine]].  If you want to inspect values, start the line with an equal sign.  For example, say you want to inspect the player:
  
<code>
+
<code>=game.player</code>
=game.player
+
</code>
+
  
The console has cursor positioning so you can use the Left and Right arrows, as well as Home and End to move to the beginning and end of the current line, respectively.  You can paste the clipboard's contents to the cursor position with Ctrl+V (note, not Apple+V on Mac).  The current line can be copied to the clipboard with Ctrl+C (again, not Apple+C).
+
The console has cursor positioning so you can use the Left and Right arrows, as well as Home and End to move to the beginning and end of the current line, respectively.  You can paste the clipboard's contents to the cursor position with <kbd>Ctrl</kbd>+<kbd>V</kbd> (note, not <kbd>CMD</kbd>+<kbd>V</kbd> on Mac).  The current line can be copied to the clipboard with <kbd>Ctrl</kbd>+<kbd>C</kbd> (again, not <kbd>CMD</kbd>+<kbd>C</kbd> on Mac).
  
 
Here are some useful commands to know.
 
Here are some useful commands to know.
Line 206: Line 207:
  
  
=== Lua code ===
+
=Lua code=
  
 
To output values into the log file you can use 2 different functions:
 
To output values into the log file you can use 2 different functions:
  
 
;Print any text
 
;Print any text
<code>
+
<code>print("your message")</code>
print("yourmessage")
+
</code>
+
  
  
 
;Display the content of an object. This lists all variables contained in the object foo.
 
;Display the content of an object. This lists all variables contained in the object foo.
<code>
+
<code>table.print(foo)</code>
table.print(foo)
+
</code>
+
  
== Output log text to file immediately (only needed on Windows) ==
+
=Output log text to file immediately (only needed on Windows)=
  
 
Without this, you have to close the game for the log file to be updated!
 
Without this, you have to close the game for the log file to be updated!
  
 
Instructions:
 
Instructions:
 +
* Create a shortcut to t-engine.exe.
 +
* Right-click the shortcut and select Properties.
 +
* Add the command to the end of the "Target" line: <code>--flush-stdout</code>
  
<ol>
+
The end of the Target line should look like this then: <code>\t-engine.exe --flush-stdout</code>
<li>Create a shortcut to t-engine.exe.</li>
+
<li>Right-click the shortcut and select Properties.</li>
+
<li>Add the command to the end of the "Target" line:
+
<code>
+
--flush-stdout
+
</code>
+
</li>
+
</ol>
+
 
+
The end of the Target line should look like this then: <pre>\t-engine.exe --flush-stdout</pre>
+
  
 
This can be used in combination with a [http://en.wikipedia.org/wiki/Tail_(Unix) tail] program that shows the content of the log file in realtime.
 
This can be used in combination with a [http://en.wikipedia.org/wiki/Tail_(Unix) tail] program that shows the content of the log file in realtime.
  
== Load module and create character on startup ==
+
=Load module and create character on startup=
  
 
You can create a character once then use the premade from the command line:
 
You can create a character once then use the premade from the command line:
  
<pre>
+
<code>t-engine -Mtome -n -E"auto_quickbirth='player'"</code>
t-engine -Mtome -n -E"auto_quickbirth='player'"
+
</pre>
+
  
if your premade was named "player."  (Or create a shortcut in Windows, similarly to the instructions above for outputting log text to a file.)
+
If your premade was named "player."  (Or create a shortcut in Windows, similarly to the instructions above for outputting log text to a file.)

Revision as of 04:41, 16 January 2021

Developer Mode (also known as "cheat") is a special game mode geared towards development of modules and addons for the game.

The easiest way to enable this mode is to select Developer Mode from the Options menu.

Overview

Developer mode grants the user several privileges and disables others to prevent abuse.

Pros:

  • The ability to see hidden modules
  • Access to the internal Lua console
  • Additional debugging dialogs/options

Cons:

  • Disables uploading characters online
  • Invalidates game saves loaded while enabled, making them permanently ineligible for achievements.

Config location

Developer Mode is saved as a setting in cheat.cfg in one of the following directories based off your OS. Deleting this file will disable Developer Mode. If enabled, the value for the cheat key is either true or false.

Windows HOME\T-Engine\4.0\settings For example C:\Users\USERNAME\T-Engine\4.0\settings
Linux HOME/.t-engine/4.0/settings
Mac OSX HOME\Library\Application Support\T-Engine\4.0\settings

Game options

Enabling cheat mode gives you the following options:

Key Shortcut Result
Ctrl+L Lua console. Click on the console title bar or outside the window to exit.
(not assigned by default) Debug menu
Ctrl+S Save the game
Ctrl+Alt+Shift+R Reload the last save
Ctrl+G Hit yourself for ~100 damage
Mouse Result
Ctrl-Left click Teleport to the targeted square
Right click Right-clicking a monster offers several debug functions, such as the ability to inspect inventory.
Shift-Ctrl-Right click Instantly kill the targeted creature. This does work on yourself.

Debug menu

Debug menu (aka debug mode) offers a menu with various options like changing zones, creating items, altering quests, etc. All of this can also be done via the Lua console, but the debug menu is much easier to use.

The keybinding for debug mode may not be assigned by default. Press Esc and go under Key Bindings to assign it.

Lua console

Summary of features:

  • Inspect values and execute code
  • Cursor positioning
  • Tab auto-completion
  • Copy and paste with system clipboard

The Lua console drops you into the global namespace and gives you access to the engine. If you want to inspect values, start the line with an equal sign. For example, say you want to inspect the player:

=game.player

The console has cursor positioning so you can use the Left and Right arrows, as well as Home and End to move to the beginning and end of the current line, respectively. You can paste the clipboard's contents to the cursor position with Ctrl+V (note, not CMD+V on Mac). The current line can be copied to the clipboard with Ctrl+C (again, not CMD+C on Mac).

Here are some useful commands to know.


Level up to level 50

game.player:forceLevelup(50)


Remove godmode invulnerability

game.player.invulnerable=0


Change your damage bonus

game.player.inc_damage.all=


Change your resistance

game.player.resists.all=


Learn a new talent (1 level in Slash in the example)

game.player:learnTalent(game.player.T_SLASH, true, 1)


Learn a new talent type (wild-gift/harmony in the example)

game.player:learnTalentType("wild-gift/harmony", true)


Change category mastery

game.player:setTalentTypeMastery("cunning/survival", 1.5)


Change base stat - up to 100 max (reduce strength by 20 in the example)

game.player:incStat("str", -20)


Change stat bonus (set Cunning bonus to 50 in the example)

game.player.inc_stats[game.player.STAT_CUN] = 50


Apply an effect on the player (frozen for 10 turns)

game.player:setEffect(game.player.EFF_FROZEN, 10, {})


Change your max HP

game.player.max_life=1 game.player:resetToFull()


Teleport (to the Assassin Lord)

game:changeLevel(2,"thieves-tunnels")


Add 5000 gold

game.player:incMoney(5000)


Give yourself 10 unassigned class skills

game.player.unused_talents=10


Give yourself 10 unused stat points

game.player.unused_stats=10


Give yourself an extra stat point each level (default=3)

game.player.stats_per_level=4


Give yourself 10 unused generic points

game.player.unused_generics=10


Give yourself 10 unused prodigies points

game.player.unused_prodigies=10


Give yourself 10 unused category points

game.player.unused_talents_types=10


Give yourself 10 lives

game.player.easy_mode_lifes=10


Change another actor's physical resistance to 50
  1. Right-click then Lua inspect [Actor] to get their actor ID
  2. __uids[ActorID here].resists.PHYSICAL=50


Lua code

To output values into the log file you can use 2 different functions:

Print any text

print("your message")


Display the content of an object. This lists all variables contained in the object foo.

table.print(foo)

Output log text to file immediately (only needed on Windows)

Without this, you have to close the game for the log file to be updated!

Instructions:

  • Create a shortcut to t-engine.exe.
  • Right-click the shortcut and select Properties.
  • Add the command to the end of the "Target" line: --flush-stdout

The end of the Target line should look like this then: \t-engine.exe --flush-stdout

This can be used in combination with a tail program that shows the content of the log file in realtime.

Load module and create character on startup

You can create a character once then use the premade from the command line:

t-engine -Mtome -n -E"auto_quickbirth='player'"

If your premade was named "player." (Or create a shortcut in Windows, similarly to the instructions above for outputting log text to a file.)