Total War: WARHAMMER II

Total War: WARHAMMER II

126 ratings
Modding Devtool Console
   
Award
Favorite
Favorited
Unfavorite
Tags: mod, UI
File Size
Posted
Updated
499.676 KB
25 Nov, 2018 @ 9:11am
22 Feb, 2022 @ 8:54am
7 Change Notes ( view )

Subscribe to download
Modding Devtool Console

Description
A mod for modders ;) The purpose of this tool is to provide you with an UI that lets you execute LUA code while the game is running. It has two UI mode, a minimized and maximized one. Both lets you enter any number of lines (limited to 150 char per line) and hit the "Execute" button to loadstring (eval) the code within the game.

It is inspired by browser developer tools console and aims to provide a basic REPL (read eval print loop) within the game.



The code you enter has access to the global scope, so any function definition or variables defined globally within the game are accessible (core, cm, etc.).

The Mini UI is essentially the same as the maximized one, but with a stripped down version, without the full-screen version, log outputs and current code pane.



Finally, to access the UI, a new button has been added to the menu_bar in the top left corner.



Automatically execute console_input.lua file

You can use the file "console_input.lua" in the game's "data/text" folder to automatically input commands into the console.

This file is "watched" so that the content of the file is executed on each save as if you were using the console textbox.

This features comes handy with the in-game textbox having limitations (namely the character size limitation and the inability to enter certain character like "[") and poor editing experience for longer chunks of code.

You can click the link below the command prompt to open the file in your text editor.

loadstring (eval)

About to the loadstring mechanism: When you hit the "Execute" button, the mod will concatenate all the lines you previously entered into a single string, separated by line breaks (\n) and compile the code using loadstring method[www.lua.org]. It is then executed using a pcall.

Compilation and runtime errors should be displayed in red in the log output panel.

Printing

The devtool console slightly changes the "print()" function (and adds a new "log()" one) for you to use and inspect variables in the console.

Similarly, the result of the commands you enter have better output for complex structures like tables by using the inspect library.

Options

The Options button in the top right lets you enable / disable file watching for the "data/text/console_input.lua" file

Environment

Here are are the special variables and functions available to you while executing commands and scripts

- print() / log(): Use this with any number of variables to inspect them in the console
- _(path): Function helper to get an UI component by its path (eg. ("layout > child > child"))
- __(path): Function helper to get detailed information for an UI component (childs, path, position, states, ...)
- _0: Variable which returns the last UIComponent clicked within the game
- _1: Variable which returns detailed information about the last UIComponent clicked (path, position, size, states, ...)

Credits

Huge thanks to Vandy for providing tons of helpful feedbacks and valuable testing. The char size limitation and the idea to workaround that using multiple lines comes from him.

Thanks to the following libraries, and respective authors. Licensed under the MIT License.

- https://github.com/kikito/inspect.lua - A really useful library to return human-readable representation of any Lua values. In use with the prints and return statements.
55 Comments
KalmarZ 24 Apr @ 3:51am 
Crashing when loading the game, I put it as second to SFO Grimhammer and nothing else.. Any suggestion on load order..?
John 11 27 Jul, 2023 @ 5:43am 
i am very happy this mod exists.
LordOmlette 22 Feb, 2022 @ 10:13am 
This mod will be invaluable whenever modding support is enabled in TW:WH3. Thank you for your hard work!
mklabs  [author] 22 Feb, 2022 @ 9:17am 
Should be fixed now. Sorry for taking so long.
Ares106 21 Oct, 2021 @ 7:27pm 
same here :(
FiftyTifty 9 Aug, 2021 @ 5:38pm 
Yep, same here
Jenglot 2 Aug, 2021 @ 9:28pm 
Crash when clicking the menu bar button on latest patch
kishkuma 28 Jan, 2021 @ 9:48pm 
... it was the quotes. -.- i used the generic quotes and it worked. that is what I get for writing the console strings out in a word doc instead of notepad. thanks very much for your help!
mklabs  [author] 28 Jan, 2021 @ 8:08am 
kishkuma, if you're unsure about LUA syntax, I would advise you to get VSCode text editor, and use it with the automatic execution of console_input.lua feature of the devtool. You can click the link below the command prompt to open the file in your text editor. A text editor with good LUA support (like VSCode) will highlight any syntax error you make. Save the file and the devtool should automatically execute its content and display the result of the command.
Groove Wizard  [author] 28 Jan, 2021 @ 5:14am 
You have to use regular quotes "" instead of fancy quotes “”, Lua doesn't like the fancy ones