Total War: WARHAMMER II

Total War: WARHAMMER II

32 rating
Debug your script: Activating Script Logging
Oleh IfThenOrElse
This guide shows you how to activate script logging to help you debug your mod scripts.
   
Penghargaan
Favorit
Difavoritkan
Batalkan favorit
Preface
This is not a guide on scripting (hopefully these will come along in the near future from the growing scripting community) and assumes you have a basic understanding of mod scripts for Total War.
Introduction:
The world of script modding for Total War: Warhammer is a wonderful area of potential – but it is also similar to any form of scripting. Things WILL go wrong and will never work first time.

As such, you will be spending most of your time figuring out why your script isn’t working. Outputting a script log will massively help you in this process.
But why?
  • Using a script log will allow you to output specific messages at specific points in your script so that you know specifically what part of your script is broken.

  • Script logs can also help you track variables by outputting their value at specific areas within your script.
How to activate script logging.
EDIT: check below to learn how to activate logging for yourself, alternatively you can run this mod alongside yours when debugging: http://steamcommunity.com/sharedfiles/filedetails/?id=1271877744

To activate script loading, you will need to edit the “all_scripted.lua” file and include it in your pack file. (you can find this vanilla script in the games data.pack file)

The edit is simple, change a single Boolean from false to true.
"__write_output_to_logfile = true "



You then load the script into your pack file, as shown below.



and BAM! when you launch the game with your mod enabled - it will create log files.

Script logs are easily identified, named “script_log_{date}_{time} and they are created in your game directory. E.g. steam\steamapps\common\Total War WARHAMMER II.

The output command
The command to output is simple, see below for three example cases. (The variable in the example is a Boolean).
  • out(“This string will be seen”)
  • out(tostring(VARIABLE))
  • out(“this string will be seen “..tostring(VARIABLE))


Note: tostring() will convert your varaible to a string format becuase output() won't recognise other variable types.
Making your output identifiable.
If you were to quickly access the game with script logging enabled, then take a look at the log – you will quickly realise that there is a lot of stuff already in there from the base game.


As such, you need to ensure your own script log outputs are quick to find. The easiest method to do this is to prefix every output with something unique to your mod e.g.
  • out(“STEC”..tostring(VARIABLE))
  • out(“STEC SCRIPT INITIATED”)
This will allow you to "ctrl + f" your unique prefix and find every output utilising it.
How to best use the output() command.
Click the below image to look at an example script with a number of output logs present.
NOTE: The screenshot was taken a while ago before some script changes by CA as such, the image incorrectly uses ouput() - you should NOW USE out().


  • The first output log on line 6 informs that the script initiates sucessfully.
  • The second log demonstrates that the function is called correctly.
  • The third log shows that the listener has fired.
  • The fourth outputs the value of VARIABLE before the listner function does stuff.
  • The fifth outputs after the If statement conditions have passed.
  • The final log outputs the value of VARIABLE after the function has done its stuff.

Now if the message doesn't pop up when you expect- you have far less guesswork to do to figure out why. For example:
  • If you see no logs from your mod, then initiation has broken.
  • logs from 3 to 6 are not registering, then you know the conditions for your listener (line 20) are not passing when they should.
  • The fourth output might show you that VARIABLE value is not what you expected it to be.
  • If the fifth log does not register, then you know something is up with your IF statement.
  • If all your script logs appear to work - then perhaps there is an issue with the fields you selected for your message.
Reverting your mod back to "retail".
It is very bad practice to leave script logging active in a mod. This will result in your mod creating text files on somebody else’s computer. This is morally ambiguous, annoying and potentially something that could land you in hot water.

Luckily it’s an easy fix. Simply delete the “all_scripted.lua” script from your mod.



With this step done, your mod will no longer produce script logs. Something you may want to consider is also removing the “out()” lines from your script. While this is not necessary, it will make your script negligibly lighter.
5 Komentar
Figaround 8 Nov 2020 @ 9:13am 
@Finaldeath Did I do the right thing, see screenshot [prnt.sc]? However, you didn't say how to create the file "enable_console_logging" (no extension) ", I created a text file. Then I renamed it to enable_console_logging and removed the extension. That should work? Or what type of file should I create?
Figaround 8 Nov 2020 @ 9:08am 
"To activate script loading, you will need to edit the "all_scripted.lua" file and include it in your pack file. (you can find this vanilla script in the game data.pack file)".

I need to change something in the data.pack file, which can be found at D:\Program Files (x86)\Steam\steamapps\common\Total War WARHAMMER II\data ?
Is it normal that it weighs almost 4 gb? And how do I open it, I don't have a program associated with the .pack extension type yet?
Finaldeath 9 Apr 2020 @ 1:50pm 
For those new modders like me who found this a tip; you can now just put a file named "enable_console_logging" (no extension) into "steamapps\common\Total War WARHAMMER II\data\script" folder - it turns on logging. You can put the file in a mod pack file but easier to just put it directly in the directory.
IfThenOrElse  [pembuat] 24 Feb 2018 @ 2:55pm 
cheers buddy - jsut launched a new one that documents the new script loading CA launched with TK update. Others will start to come along when I get time!
mahgah 15 Feb 2018 @ 7:02pm 
Your guides are great mate