Scripting Tutorial

From Europa Universalis 4 Wiki
Jump to navigation Jump to search

EU4 scripting can be intimidating for newcomers, regardless of previous programming experience. This guide will attempt to explain some of the idiosyncrasies of EU4 scripting, and give a general overview of how its different components fit together.

The Scripting Model[edit | edit source]

To begin to understand EU4 scripting we should first break it down into its most basic components, and show how they relate to and interact with each other.

EU4 Scripting Model.png

The Game State[edit | edit source]

The Game State is an abstract concept that isn't actually part of EU4 scripting, but it's still helpful as it allows us to understand how the other components interact with each other. The Game State is basically how it sounds; the entire state of the game at a given moment. It encompasses all the values and variables attached to every country, province, trade node, and more. The Game State will tell you the primary culture of a given country, or even if that country exists at all. It can tell you how much treasury a country has, what the base production of a province is, or how many units of cavalry are in that province.

Scopes[edit | edit source]

Main article: Scopes

Scopes are the context within which you can interact with the Game State. They are how you select what you are interacting with in that portion of code, whether that is a single country, a province, a region, or more. Scopes also determine which effects and triggers (covered in the next section) you can use, as some are only valid when used in a province scope, others are only valid when used in a country scope, and others still can be used in either province or country scopes.

Effects[edit | edit source]

Main article: Effects

Effects are used to immediately make instant changes to the Game State. They are the primary way that you do things to the game in EU4 scripting. With effects, you can add to a country's treasury, change its religion or primary culture, or have one country completely take control of another country's provinces.

Triggers[edit | edit source]

Main article: Triggers

Triggers are ways of getting info from the Game State about the conditions of the current scope. They let you check if a country is a certain religion, if they have an ally, or if a province has a certain amount of base manpower. Triggers can be used to further refine a set of scopes down to exactly what you want, or they can be used within a single scope to determine whether certain effects should be applied or not, or whether decision is visible or not.

Modifiers[edit | edit source]

Main article: Modifier list

Modifiers are similar to Effects in that they alter the Game State, but they differ because Modifiers apply continuous effects to the Game State, while an Effect makes a one-off change instead. Modifiers are how you increase a country's tax income by a percentage (or fixed) amount, how you increase the number of available merchants, or how you increase the siege defensiveness of a province. Modifiers are applied to a scope directly by an effect, or by being coded into some other mechanic (like the modifiers a country gets from its religion). They can last for a fixed duration, for the life of a ruler, or for the rest of the game (unless programmatically removed).

Documentation EffectsTriggersModifiersScopesVariablesLocalisationCustomizable localizationRun filesList of event pictures
Scripting Scripted functionAdvisorsAgesBookmarksBuildingsCasus belliColonial regionsCountriesCultureDecisionsDefinesDiplomatic actionsDisastersEmpire of ChinaEstatesEventsFactionsGovernmentGovernment MechanicsGreat projectsHistoryHoly Roman EmpireIdea groupsInstitutionsMercenariesMissionsModifiersNation designerOn ActionsParliamentPeace treatiesPoliciesRebel typesReligionSubject typesTechnologyTrade companiesTrade goodsUnits
Map MapMap Modding Quick ReferenceNation designerRandom New WorldTrade nodes
Graphics 3D ModelsInterfaceGraphical AssetsFontsParticlesShadersUnit models
Audio MusicSound
Other Console commandsChecksumJoroDox mod making toolMod structureTroubleshootingThe ValidatorRun files
Guides Adding a provinceMap Modding Quick ReferenceSave-game editingScripting Tutorial