Tools and Getting Started

Scripting & Language Improvements

Code: any_neighbor_country = { tag = GER } NOT = { is_in_faction_with = GER }

Code: is_neighbor_not_in_german_faction = { any_neighbor_country = { tag = GER } NOT = { is_in_faction_with = GER } }

The AI

Hi everyone, this weeks diary is going to get really technical! We will be talking modding and improvements we have made for the modders in HOI4. This is also going to be a very long oneWhen starting out we decided we wanted to make HOI4 our most moddable game yet. That meant not hard coding things (HOI3 had a lot of hard coded logic and references to certain nations). In HOI4 all these things are in soft code, or part of scenario script setups making it a much better platform for cool mods. We have also decided to include the tool we use (more further down), and while it is provided as-is and not really polished compared to the real game its very useful. The game is also much better at letting you know when you have made mistakes and everything that can go wrong will usually let you know with logs etc.Getting started with the creation of mods are now easier than ever before!Using the launchers mod tool will allow you to create an empty mod for the game without any hassle and without even starting the game.Then starting the game with the “-debug” flag will enable the “modder mode” that adds some extra sanity checks and enabling tools useful for modifying the game.For example the in game Nudger tool that provides a simple interface to modify the properties of the map.Here I created the awesome state of Östergötland by redistributing some provinces from Småland and tweaked the positions of the buildings.The Nudger tool will then validate my changes and save them to the appropriate files for me and my mod, just in a few mouse clicks.These files are of course human readable and can easily be edited with your favorite text editor for more advanced scripting or making smaller changes, most of the files (like state history setup) also have the option to be opened with a external program from the Nudger so you do not even need to find them in the filesystem.Another nice tool is the instant feedback system aka “Error Dawg” appearing in the lower right corner that will give you instant feedback about scripting errors and oddities during gameplay. Clicking on it will of course open the error log for you, painfully reminding you about things you have forgotten or otherwise faulty scripted.When satisfied with your mod and fixed all the errors you are just one click away from sharing it with the rest of the HoI4 community by uploading it to the steam workshop with the Mod tool.Another thing we have put a lot of effort into is reloadability. You can reload interfaces (even automatically as the game will check if files are modified and you will see changes instantly ingame) as well as several game systems. For example focus trees will reload with your changes making it really quick and easy to work with making them and not forcing you to restart the game all the time.One of the small help functions we’ve put in is the console command “trigger_docs”. This will print a list of all the triggers and effects we have in the game along with a small description of how they are used. We hope this can be a useful tool for new modders to find what they’re looking for and old modders to discover hidden possibilities. We of course still have the beloved debug dog to bark at you when something is wrong.We’re continuously trying to improve the user-friendliness in our script language itself. Therefore we try to take the good practices that has been introduced in our other games and integrate them to all of our titles. One of the later additions that we’ve ported over is scripted effects and triggers which function is that you can basically macro that can be referenced in the various script files of the game that will execute a whole block of an effect or a trigger respectively.An example of this could be that you might want to show one event option for Germany's neighbors that they are not in a faction with and a different event option for the rest of the world. This could be a common occurrence for all of your events and this would require all of those event options to have the following trigger:This could instead be created as a scripted trigger which we would define in the scripted_triggers folder in the game files as the following:Which could then be referenced in the different event option triggers as a one-line trigger (is_neighbor_not_in_german_faction = yes) in place of the multiple lines previously required.As commonly used combinations of triggers and effects grow increasingly complex this script feature has two big functions. Firstly in that it decreases the amount of code duplication that would otherwise have been needed. And secondly it will also make the code easier to maintain since when you find yourself in the position that you have to change something in your common conditions for your events you could just add it inside the scripted trigger and just have to update one place instead of having to find all of the different places that would need to be updated.Another great addition to the script language is the functionality of defining a particular scope as an event target inside an event or event chain, this feature has seen great usage in the script language of Crusader Kings II which always had an overload of scope changes.The event targets makes it easier to reference different provinces and nations in the event text and execute effects on the correct targets without the need to have a huge amount of hidden bounce events to get the event scopes to evaluate correctly and keep track of different actors or locations. And if you want to get really creative you can try to combine these two script features and define event targets which you then use inside your scripted trigger or effect to have it act as a sort of sub-routine.The AI in HOI3 was run though Lua scripts, but we decided to abandon these for several reasons in HOI4 (lack of lua knowledge at the company and low performance was the big ones). The AI is still however very moddable and has a lot of scripts to modify. I think its best to wait and talk about that in the dedicated dev diary on AI stuff I'll make @SteelVolt write before release thoughNext week we'll have @Sideburnout talk about all things 2D art and interface for HOI4. See you then!p.s whoever makes a Battletech mod first will forever live on in my heart.