Mod API Reference: Difference between revisions
m Added category |
→Newer API features: add button getters and setters for icons |
||
| (55 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
This explains how to use | This explains how to use War.app's [[Mods|mod]] API and links to the documentation for each object type. | ||
== Types == | == Types == | ||
When writing a mod, you'll encounter variables/objects of three basic types: | When writing a mod, you'll encounter variables/objects of three basic types: | ||
* Primitives: strings, | * Primitives: strings, numbers, booleans, etc. | ||
* Tables: collections of key/value pairs. A table is a lot like a hashmap or dictionary in other languages. Note that in | * Tables: collections of key/value pairs. A table is a lot like a hashmap or dictionary in other languages. Note that in War.app, the key of a table will always be either a string or an integer. Some places in this reference will refer to Arrays which are just tables with numeric keys starting at 1. | ||
* Proxy objects: Discussed in the next section. | * Proxy objects: Discussed in the next section. | ||
== Proxy Objects == | == Proxy Objects == | ||
A '''proxy object''' proxies information back and forth between your mod and | A '''proxy object''' proxies information back and forth between your mod and War.app. You can tell if an object is a proxy object by looking for a <code>proxyType</code> field. All proxy objects always have the following fields: | ||
* proxyType: A string identifying the type of proxy object. | * proxyType: A string identifying the type of proxy object. | ||
| Line 20: | Line 20: | ||
Here's a handy function you can include in your mod to print out everything on a proxy object: | Here's a handy function you can include in your mod to print out everything on a proxy object: | ||
<pre style="overflow: auto"> | |||
function PrintProxyInfo(obj) | |||
print('type=' .. obj.proxyType .. ' readOnly=' .. tostring(obj.readonly) .. ' readableKeys=' .. table.concat(obj.readableKeys, ',') .. ' writableKeys=' .. table.concat(obj.writableKeys, ',')); | print('type=' .. obj.proxyType .. ' readOnly=' .. tostring(obj.readonly) .. ' readableKeys=' .. table.concat(obj.readableKeys, ',') .. ' writableKeys=' .. table.concat(obj.writableKeys, ',')); | ||
end | |||
</pre> | |||
== Writing Tables == | == Writing Tables == | ||
If a writable | If a writable War.app proxy object exposes a table, and you wish to make changes to that table, you must assign the table back to the proxy object. For example, assume you have a <code>GameStanding</code> object named <code>standing</code> which exposes the <code>Cards</code> table, and you want to add something at index 9: | ||
standing.Cards[9] = something --WRONG! | standing.Cards[9] = something --WRONG! | ||
| Line 53: | Line 55: | ||
* [[Mod API Reference:CardGameBlockade|CardGameBlockade]] | * [[Mod API Reference:CardGameBlockade|CardGameBlockade]] | ||
* [[Mod API Reference:CardGameBomb|CardGameBomb]] | * [[Mod API Reference:CardGameBomb|CardGameBomb]] | ||
* [[Mod API Reference:CardGameCustom|CardGameCustom]] | |||
* [[Mod API Reference:CardGameDiplomacy|CardGameDiplomacy]] | * [[Mod API Reference:CardGameDiplomacy|CardGameDiplomacy]] | ||
* [[Mod API Reference:CardGameGift|CardGameGift]] | * [[Mod API Reference:CardGameGift|CardGameGift]] | ||
| Line 76: | Line 79: | ||
* [[Mod API Reference:GameOrderAttackTransferResult|GameOrderAttackTransferResult]] | * [[Mod API Reference:GameOrderAttackTransferResult|GameOrderAttackTransferResult]] | ||
* [[Mod API Reference:GameOrderBossEvent|GameOrderBossEvent]] | * [[Mod API Reference:GameOrderBossEvent|GameOrderBossEvent]] | ||
* [[Mod API Reference:GameOrderCustom|GameOrderCustom]] | |||
* [[Mod API Reference:GameOrderDeploy|GameOrderDeploy]] | * [[Mod API Reference:GameOrderDeploy|GameOrderDeploy]] | ||
* [[Mod API Reference:GameOrderDiscard|GameOrderDiscard]] | * [[Mod API Reference:GameOrderDiscard|GameOrderDiscard]] | ||
* [[Mod API Reference:GameOrderEvent|GameOrderEvent]] | |||
* [[Mod API Reference:GameOrderPlayCard|GameOrderPlayCard]] | * [[Mod API Reference:GameOrderPlayCard|GameOrderPlayCard]] | ||
* [[Mod API Reference:GameOrderPlayCardAbandon|GameOrderPlayCardAbandon]] | * [[Mod API Reference:GameOrderPlayCardAbandon|GameOrderPlayCardAbandon]] | ||
| Line 84: | Line 89: | ||
* [[Mod API Reference:GameOrderPlayCardBlockade|GameOrderPlayCardBlockade]] | * [[Mod API Reference:GameOrderPlayCardBlockade|GameOrderPlayCardBlockade]] | ||
* [[Mod API Reference:GameOrderPlayCardBomb|GameOrderPlayCardBomb]] | * [[Mod API Reference:GameOrderPlayCardBomb|GameOrderPlayCardBomb]] | ||
* [[Mod API Reference:GameOrderPlayCardCustom|GameOrderPlayCardCustom]] | |||
* [[Mod API Reference:GameOrderPlayCardDiplomacy|GameOrderPlayCardDiplomacy]] | * [[Mod API Reference:GameOrderPlayCardDiplomacy|GameOrderPlayCardDiplomacy]] | ||
* [[Mod API Reference:GameOrderPlayCardFogged|GameOrderPlayCardFogged]] | * [[Mod API Reference:GameOrderPlayCardFogged|GameOrderPlayCardFogged]] | ||
| Line 100: | Line 106: | ||
* [[Mod API Reference:GameStanding|GameStanding]] | * [[Mod API Reference:GameStanding|GameStanding]] | ||
* [[Mod API Reference:GameWL|GameWL]] | * [[Mod API Reference:GameWL|GameWL]] | ||
* [[Mod API Reference:IncomeMod|IncomeMod]] | |||
* [[Mod API Reference:IsVersionOrHigher|IsVersionOrHigher]] | |||
* [[Mod API Reference:MapDetails|MapDetails]] | * [[Mod API Reference:MapDetails|MapDetails]] | ||
* [[Mod API Reference:MapFamily|MapFamily]] | * [[Mod API Reference:MapFamily|MapFamily]] | ||
| Line 113: | Line 121: | ||
* [[Mod API Reference:TerritoryModification|TerritoryModification]] | * [[Mod API Reference:TerritoryModification|TerritoryModification]] | ||
* [[Mod API Reference:TerritoryStanding|TerritoryStanding]] | * [[Mod API Reference:TerritoryStanding|TerritoryStanding]] | ||
* [[Mod API Reference:TickCount|TickCount]] | |||
* [[Mod API Reference:UI|UI]] | * [[Mod API Reference:UI|UI]] | ||
[[Category:Mod API Reference]] | * [[Mod API Reference:WL|WL]] | ||
== Newer API features == | |||
Some features were introduced after the first version of the Mod API framework and should be checked for using [[Mod_API_Reference:IsVersionOrHigher|IsVersionOrHigher]]: | |||
{| class="wikitable" | |||
|- | |||
! Version | |||
! Features | |||
|- | |||
| 6.09 | |||
| [[Mod API Reference:UI|UI]].InterceptNextMapClick<br>Fixed viewing a game's settings breaking that game's mods until their menu was opened again. Afterwards, a mod's open menu could fail calling UI.InterceptNextTerritoryClick, and Mod.PublicGameData and Mod.PlayerGameData read as empty. | |||
|- | |||
| 6.08 | |||
| Babylon rendering engine (for [[Mod_API_Reference:Client Visual|Client_Visual]] in 2D mode)<br>Map layers from [[Mod API Reference:Client MapLayers|Client_MapLayers]] are no longer rebuilt on every refresh<br>[[Mod API Reference:Client_MapLayers#layers.Create|layers.Create]] <code>buildFunction</code> as argument 2 (before argument 2 was <code>defaultVisible</code> now it's argument 3)<br>[[Mod API Reference:Client_MapLayers#Layer functions|layer]].AddLabel argument 3, field <code>ID</code><br>layer.AddShape argument 1.<br>layer.Remove<br>layer.Clear<br>layer.Rebuild<br>layer.IsVisible | |||
|- | |||
| 6.07 | |||
| [[Mod Hooks#Client Hooks|Client_MapLayers]]<br>[[Mod Hooks#Client Hooks|Client_DescribeOrder]]<br>[[Mod Hooks#Client Hooks|Client_TurnAdvanced]]<br>[[Mod Hooks#Client Hooks|Client_TerritoryInfo]]<br>[[Mod Game Data Storage#Mod.ClientStorage|Mod.ClientStorage]]<br>[[Mod_API_Reference:UI|UI]].SetMenuBadge<br>[[Mod API Reference:ClientGame|ClientGame]].MapWidth<br>ClientGame.MapHeight<br>Client_Visual now also draws visuals for [[Mod API Reference:GameOrderPlayCardCustom|GameOrderPlayCardCustom]] and [[Mod API Reference:GameOrderCustom|GameOrderCustom]] orders, using the hook of the mod that defines the card. They also show faded as you build your turn, just like built-in orders do.<br>[[Mod_API_Reference:Client Visual|Client_Visual]] > SetDepthTest<br>Fixed "Move to top" and "Move to bottom" in the orders list moving orders past orders of other phases when a mod's custom order was in the way, which made mods fail with OrdersInIncorrectOrder when they next set orders. | |||
|- | |||
| 6.06 | |||
| [[Mod_API_Reference:UI|UI]].CreateImage<br>UI button getters and setters for Icon, IconPreferredWidth, IconPreferredHeight, IconMinWidth, IconMinHeight<br>UI.CreateSnapshot<br>[[Mod Hooks#Client Hooks|Client_Visual]]<br>Improved mod crash messages in website.<br>Fixed team swaps from breaking tournaments or quickmatch | |||
|- | |||
| 6.05.1 | |||
| [[Mod_API_Reference:UI|TextInputField]].MultiLine<br>Fixed teammates attack visuals staying on the screen after team swap<br>Fixed perspective options when viewing history after team swap<br>Fixed "Opponent's cards" so it correctly shows the teams at the point in history you're viewing when it's opened | |||
|- | |||
| 6.05 | |||
| [[Mod_API_Reference:GameOrderEvent]].AssignTeamOpt<br>[[Mod_API_Reference:Custom_Cards|playCard]] argument 6 | |||
|- | |||
| 6.04 | |||
| [[Mod_API_Reference:UI|TextInputField]].OnValueChanged<br>[[Mod_API_Reference:UI|NumberInputField]].OnValueChanged<br>[[Mod API Reference:GameOrderEvent|GameOrderEvent]].Icon<br>[[Mod API Reference:GameOrderCustom|GameOrderCustom]].Icon<br>[[Mod API Reference:GameOrderPlayCardCustom|GameOrderPlayCardCustom]].Icon | |||
|- | |||
| 6.03 | |||
| GameOrderReceiveCard, GameOrderStateTransition, and ActiveCardWoreOff are now sent to mods via the Server_AdvanceTurn_Order mod hook. Note that, unlike player-inputted orders, these types of orders cannot be skipped<br>Fixed setting a table entry to nil not deleting that value from the table | |||
|- | |||
| 6.02 | |||
| Fixed writing into proxy tables without __newindex | |||
|- | |||
| 6.01 | |||
| During picking, pickable territories now show the structures on the territory if a mod put any there<br>Fixed a case where structures would be lost if two mods wrote structures to the same territory in Server_StartGame<br>Fixed importing metatable objects into game code<br>Fixed integer input boxes not accepting negative signs on mobile<br> | |||
|- | |||
| 6.00 | |||
| Fixed fog modifications not being correctly restored when resuming a saved single player game<br>Fixed special units sometimes not rendering correctly on territories | |||
|- | |||
| 5.43 | |||
| Added new colors to supported button colors: Yellow: ABA500 Green: 198225 Light blue: 50B2E3 Blue: 242D9A Red: 9A2929<br>Fixed "CardStackVM Disposed" error that could come up in modded games | |||
|- | |||
| 5.42 | |||
| Fixed a bug that could cause a stack overflow if a player had negative gold<br>Fixed creating mega games with mods that used the Server_Created hook | |||
|- | |||
| 5.41 | |||
| [[Mod_API_Reference:UI|UI.PromptFromList]] can now specify a [[Mod_API_Reference:GamePlayer|player]]<br>Fixed playing cards when a mod changes your orders list in Client_GameOrderCreated<br>Fixed allowing too-high values for power on custom special units, which would break the game. Power is now limited to 100,000.<br>Fixed [[Mod_API_Reference:TerritoryStanding|TerritoryStanding]].Structures so it's consistent across platforms when using numbers instead of the enum values as the table key | |||
|- | |||
| 5.40 | |||
| If a mod makes an invalid custom structure string, the game now displays blank instead of throwing errors | |||
|- | |||
| 5.39 | |||
| Settings panel mod contents are now left-aligned by default<br>Fixed icons next to mods sometimes not showing up in the settings dialog<br>Fixed GameOrderEvent’s tooltip when modifying custom structures<br>Fixed Toggle's value-changed event on website from firing on repeat values, or not firing when disabling<br>Fixed allowing custom orders being inserted into orders list during territory distribution<br>Fixed custom cards persisting in a template after the mod that created that card was removed | |||
|- | |||
| 5.38 | |||
| [[Mod_API_Reference:StructureType|WL.StructureType.Custom]]<br>Mods are no longer limited to 5 special unit images<br>Mods may now use lua files in subdirectories, using the syntax require("folder.filename")<br>When an income mod wears off, it’s now visible to all players in the game<br>Fixed a bug that could cause an error when spying on a player who captured a territory out from a FogModded territory | |||
|- | |||
| 5.37 | |||
| Fixed a bug that could cause opponent’s cards to show incorrectly when added or removed by mods in some cases<br>If mods get into an infinite loop of adding orders, the error message now details which mods added how many orders, to help track down the offending mods<br>Fixed the "visible to" line when inspecting a GameOrderEvent so it's clear it's also visible to players who are affected by the order<br>Fixed TerritoryModification.AddStructuresOpt events from not showing up in the orders list to players who could see the territories<br>Fixed a bug that made FogMods not properly wear off in no-fog games<br>Fixed loading orders on the client so it doesn’t reset the current phase | |||
|- | |||
| 5.36 | |||
| Transferring or airlifting a special unit to a teammate now updates the unit's owner<br>Added new tags: Special Units, Cards, Random<br>Fixed not being able to assign owner of a special unit to neutral<br>Fixed deployment not updating properly if a mod changed orders from Client_GameOrderCreated<br>Fixed Feature.png not showing correctly while mod was in development | |||
|- | |||
| 5.35 | |||
| Added mod browser, with sort/filter/search options, for easily finding or sorting through mods. It's viewable at https://www.war.app/Mods/, or integrated into the Create Game page when you click Change Mods.<br>Mega games now allow mods<br>Added a dedicated page for each mod, to replace the small mod info dialog<br>Mods can now have icons and images to show themselves off to players when browsing mods<br>Territory annotations now show in a faded form on the map when the order is not selected<br>Fixed a bug that caused an error if a mod sent a custom message without having a custom message handler, and at least one other mod in the game did have a custom message handler<br>Fixed annotation font sizes<br>Fixed guids so they're consistently converted to strings on different platforms<br>Fixed multi-attack games assuming no special units exist if commanders were turned off | |||
|- | |||
| 5.34.1 | |||
| [[Mod Hooks#Client Hooks|Client_CreateGame]]<br>Add <em>TerritoryAnnotationsOpt</em> to [[Mod API Reference:GameOrderEvent|GameOrderEvent]], [[Mod API Reference:GameOrderCustom|GameOrderCustom]] and [[Mod API Reference:GameOrderPlayCardCustom|GameOrderPlayCardCustom]]<br>Add <em>JumpToActionSpotOpt</em> to [[Mod API Reference:GameOrderCustom|GameOrderCustom]] and [[Mod API Reference:GameOrderPlayCardCustom|GameOrderPlayCardCustom]]<br>Add parameter 9 (<em>ActiveCardExpireBehaviorOptions</em>) to <em>addCard</em> when using [[Mod API Reference:Custom Cards|Custom Cards]]<br>Add optional parameters 4 and 5 to <em>playCard</em> when using [[Mod API Reference:Custom Cards|Custom Cards]]<br>Add <em>MinWidth</em> and <em>MinHeight</em> to all [[Mod API Reference:UI|UI]] elements<br>Add <em>Alignment</em> to UI Label element<br>Fixed a bug that caused stack traces to not show up in mod errors in some cases in Unity<br>Fixed fog mods on No-Fog games from giving errors<br>Fixed skipping of deploy orders in Client_GameOrderCreated making the deployment status report incorrectly<br>Fixed copying a game that used a mod that used the Server_Created hook | |||
|- | |||
| 5.34 | |||
| Create [[Mod_API_Reference:UI|radio buttons]]<br>Lua errors in the browser now give stack traces with line numbers in the mod-crashed dialog<br>[[Mod API Reference:Custom Cards|Client_PresentPlayCardUI]] now gives mods the ability to close the cards dialog - <em>closeCardsDialog</em><br>Fixed [[Mod Hooks#Client Hooks|Client_GameOrderCreated]] not being able to read territory picks in manual distribution games<br>Fixed WL.enumtype.ToString() functions<br>Fixed [[Mod API Reference:Custom Cards|Client_PresentPlayCardUI]] not registering [[Mod Game Data Storage|Mod]] and [[Mod API Reference:UI|UI]] hooks if it was called before other client hooks<br>Fixed an error if you set number of card pieces to 0 or negative<br>Fixed [[Mod API Reference:GameOrderAirliftResult|GameOrderAirliftResult]].Results throwing an error instead of returning nil when there are no results yet<br>Fixed allowing [[Mod API Reference:GameOrderAttackTransferResult|GameOrderAttackTransferResult]].ActualArmies to be set to a negative number<br>Fixed "can't transfer to a neutral" error that occurred when a mod resurrected a failed transfer | |||
|- | |||
| 5.33 | |||
| [[Mod API Reference:FogMod|WL.FogMod]]<br>[[Mod API Reference:GameOrderEvent|GameOrderEvent.FogModsOpt]]<br>[[Mod API Reference:GameOrderEvent|GameOrderEvent.RemoveFogModsOpt]]<br>[[Mod API Reference:GameStanding|GameStanding.IncomeMods]]<br>Fixed the AI trying to move its commander even if it doesn't control the territory the commander is on (which can happen with mods)<br>Fixed a bug that could make a generic War.app error instead of a mod failed error if you tried to set a property on a destroyed object (for example, Button's SetInteractable) | |||
|- | |||
| 5.32.0.1 | |||
| "addCard" callback function now returns the card ID of the newly added card<br>Fixed a bug with custom cards that made old clients produce an error | |||
|- | |||
| 5.32 | |||
| [[Mod_Hooks#Client_Hooks|Client_GameOrderCreated]]<br>[[Mod_Hooks#Client_Hooks|Client_GameCommit]]<br>[[Mod API Reference:Custom Cards|Custom Cards]] | |||
|- | |||
| 5.31 | |||
| Proper support for Neutral Special Units<br>Fixed GameOrderCustom.TurnPhase not correctly persisting in multi-player<br>Fixed Lua global state not persisting in some cases on the website<br>Note: this update <em>may have</em> prevented the use of custom turn phases | |||
|- | |||
| 5.26 | |||
| Use [[Mod_API_Reference:ServerGame|ServerGame.SetPlayerResource]] in [[Mod_Hooks#Server_Hooks|Server_StartGame]]<br>Fixed a bug with airlifting special units that are set to always visible | |||
|- | |||
| 5.24.2 | |||
| [[Mod_API_Reference:CustomSpecialUnit|CustomSpecialUnit.Health]] | |||
|- | |||
| 5.24.1 | |||
| [[Mod_API_Reference:CustomSpecialUnit|CustomSpecialUnit.CombatOrder]]<br>[[Mod_API_Reference:TickCount|WL.TickCount]] | |||
|- | |||
| 5.22.2 | |||
| [[Mod_API_Reference:Boss1|Boss1.CombatOrder]]<br>[[Mod_API_Reference:Boss2|Boss2.CombatOrder]]<br>[[Mod_API_Reference:Boss3|Boss3.CombatOrder]]<br>[[Mod_API_Reference:Boss4|Boss4.CombatOrder]]<br>[[Mod_API_Reference:Commander|Commander.CombatOrder]]<br>[[Mod_API_Reference:CustomSpecialUnitBuilder|CustomSpecialUnitBuilder.Health]] | |||
|- | |||
| 5.22 | |||
| [[Mod_API_Reference:GameOrderCustom|GameOrderCustom.OccursInPhaseOpt]]<br>[[Mod_API_Reference:TerritoryModification|TerritoryModification.RemoveSpecialUnitsOpt]] | |||
|- | |||
| 5.21 | |||
| [[Mod_Hooks#Client_Hooks|Client_PresentCommercePurchaseUI]]<br>[[Mod_API_Reference:ClientGame|ClientGame.CreateLocatorCircle]]<br>[[Mod_API_Reference:ClientGame|ClientGame.HighlightTerritories]]<br>[[Mod_API_Reference:CustomSpecialUnit|CustomSpecialUnit]]<br>[[Mod_API_Reference:GameOrderEvent|GameOrderEvent.JumpToActionSpotOpt]]<br>[[Mod_API_Reference:GameOrderEventResult|GameOrderEventResult.CardInstancesCreated]]<br>[[Mod_API Reference:UI|UI.IsDestroyed]]<br>[[Mod_API_Reference:UI|WL.CancelClickIntercept]] | |||
|- | |||
| 5.20 | |||
| Setting [[Mod_API_Reference:TerritoryStanding|TerritoryStanding]].OwnerPlayerID to [[Mod_API_Reference:PlayerID|WL.PlayerID.AvailableForDistribution]]<br>[[Mod_API_Reference:GameOrderEvent|GameOrderEvent.AddCardPiecesOpt]]<br>[[Mod_API_Reference:GameOrderEvent|GameOrderEvent.AddResourceOpt]]<br>[[Mod_API_Reference:GameOrderEvent|GameOrderEvent.RemoveWholeCardsOpt]]<br>[[Mod_API_Reference:TerritoryModification|TerritoryModification.AddArmies]]<br>[[Mod_API_Reference:TerritoryModification|TerritoryModification.AddStructuresOpt]] | |||
|- | |||
| 5.17 | |||
| Using argument two of <code>addNewOrder</code> in [[Mod_Hooks#Server_Hooks|Server_AdvanceTurn_Order]]<br>[[Mod_API_Reference:GameOrderEvent|GameOrderEvent.IncomeMods]]<br>[[Mod_API_Reference:IncomeMod|IncomeMod]]<br>[[Mod_API_Reference:UI|UI.InterceptNextBonusLinkClick]]<br>[[Mod_API_Reference:UI|UI.InterceptNextTerritoryClick]]<br>[[Mod_API_Reference:IsVersionOrHigher|WL.IsVersionOrHigher]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Arena]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.ArmyCache]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.ArmyCamp]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Attack]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Crafter]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.DigSite]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Draft]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Hospital]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Market]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.MercenaryCamp]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Mine]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.MoneyCache]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Mortar]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Power]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Recipe]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.ResourceCache]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Smelter]] | |||
|} | |||
There is a chance that a player has a version of the app that pre-dates the introduction of the [[Mod_API_Reference:IsVersionOrHigher|IsVersionOrHigher]] function. Many features were added after the first version of the Mod API Framework, but before the introduction of the function: | |||
{| class="wikitable" | |||
|- | |||
! Version | |||
! Features | |||
|- | |||
| Up to 4.14.2 | |||
| Various bug fixes / performance enhancements relating to mods. No other changes made to mod API framework until version 5.17. | |||
|- | |||
| 3.20.2 | |||
| Mod support for Commerce games (Commerce added in 3.20.0) | |||
|- | |||
| 3.19.3 | |||
| Bug fixes for GameOrderPlayCard, Armies.Add, Armies.Subtract<br>[[Mod_Hooks#Client_Hooks|Client_GameRefresh]]<br>[[Mod_Hooks#Client_Hooks|Client_PresentMenuUI]]<br>[[Mod_Game_Data_Storage|Data storage]]<br>[[Mod_API_Reference:Game|Game]].CreateDialog<br>[[Mod_API_Reference:Game|Game]].SendGameCustomMessage<br>[[Mod_API_Reference:GamePlayer|GamePlayer]].Income<br>[[Mod_Hooks#Server_Hooks|Server_GameCustomMessage]] | |||
|- | |||
| 3.19.2 | |||
| [[Mod_API_Reference:GameOrderCustom|GameOrderCustom]]<br>[[Mod_API_Reference:UI|UI]].Alert<br>UI.Destroy<br>UI.PromptFromList | |||
|- | |||
| 3.18.2 | |||
| Moved all WarLight mod classes into the global "WL" namespace. For example, to create an Armies object instead of just saying "Armies()", you now say WL.Armies.Create() | |||
|- | |||
| 3.18.0 | |||
| Mod API Framework added | |||
|} | |||
[[Category:Mod Developers Guide]][[Category:Mod API Reference|!]] | |||
Latest revision as of 15:23, 30 November 2026
This explains how to use War.app's mod API and links to the documentation for each object type.
Types
When writing a mod, you'll encounter variables/objects of three basic types:
- Primitives: strings, numbers, booleans, etc.
- Tables: collections of key/value pairs. A table is a lot like a hashmap or dictionary in other languages. Note that in War.app, the key of a table will always be either a string or an integer. Some places in this reference will refer to Arrays which are just tables with numeric keys starting at 1.
- Proxy objects: Discussed in the next section.
Proxy Objects
A proxy object proxies information back and forth between your mod and War.app. You can tell if an object is a proxy object by looking for a proxyType field. All proxy objects always have the following fields:
- proxyType: A string identifying the type of proxy object.
- readOnly: False if you're allowed to make changes to this proxy object, or true if it's read-only.
- readableKeys: An array containing all fields you're allowed to read from this object.
- writableKeys: An array containing all fields you're allowed to change on this object if readOnly is False.
To read a field, simply read it like a property: obj.field. Similarly, to write to a proxy object, just assign to that field: obj.field = newVal.
Here's a handy function you can include in your mod to print out everything on a proxy object:
function PrintProxyInfo(obj)
print('type=' .. obj.proxyType .. ' readOnly=' .. tostring(obj.readonly) .. ' readableKeys=' .. table.concat(obj.readableKeys, ',') .. ' writableKeys=' .. table.concat(obj.writableKeys, ','));
end
Writing Tables
If a writable War.app proxy object exposes a table, and you wish to make changes to that table, you must assign the table back to the proxy object. For example, assume you have a GameStanding object named standing which exposes the Cards table, and you want to add something at index 9:
standing.Cards[9] = something --WRONG!
This code won't work since the proxy object isn't having anything assigned to it. Proxy objects are only aware of changes when something is directly assigned into them. To make this work, you must assign the table into the proxy object's field:
local cards = standing.Cards cards[9] = something standing.Cards = cards; --Right
Note: If you use lua's type function, proxy objects will identify themselves as tables. However, that should be considered an implementation detail. For the purposes of this wiki, proxy objects aren't considered tables.
API Reference
- ActiveCard
- ActiveCardWoreOff
- Armies
- BonusDetails
- Boss1
- Boss2
- Boss3
- Boss4
- CardGame
- CardGameAbandon
- CardGameAirlift
- CardGameBlockade
- CardGameBomb
- CardGameCustom
- CardGameDiplomacy
- CardGameGift
- CardGameOrderDelay
- CardGameOrderPriority
- CardGameReconnaissance
- CardGameReinforcement
- CardGameSanctions
- CardGameSpy
- CardGameSurveillance
- CardInstance
- ClanPlayerInfo
- ClientGame
- Commander
- CustomScenario
- CustomScenarioTerritory
- DistributionMode
- Game
- GameColor
- GameOpenSeat
- GameOrder
- GameOrderAttackTransfer
- GameOrderAttackTransferResult
- GameOrderBossEvent
- GameOrderCustom
- GameOrderDeploy
- GameOrderDiscard
- GameOrderEvent
- GameOrderPlayCard
- GameOrderPlayCardAbandon
- GameOrderPlayCardAirlift
- GameOrderPlayCardAirliftResult
- GameOrderPlayCardBlockade
- GameOrderPlayCardBomb
- GameOrderPlayCardCustom
- GameOrderPlayCardDiplomacy
- GameOrderPlayCardFogged
- GameOrderPlayCardGift
- GameOrderPlayCardOrderDelay
- GameOrderPlayCardOrderPriority
- GameOrderPlayCardReconnaissance
- GameOrderPlayCardReinforcement
- GameOrderPlayCardSanctions
- GameOrderPlayCardSpy
- GameOrderPlayCardSurveillance
- GameOrderReceiveCard
- GameOrderStateTransition
- GamePlayer
- GameSettings
- GameStanding
- GameWL
- IncomeMod
- IsVersionOrHigher
- MapDetails
- MapFamily
- NoParameterCardInstance
- PendingStateTransition
- PlayerCards
- PlayerInfo2
- ReinforcementCardInstance
- ServerGame
- SpecialUnit
- TerritoryConnection
- TerritoryDetails
- TerritoryModification
- TerritoryStanding
- TickCount
- UI
- WL
Newer API features
Some features were introduced after the first version of the Mod API framework and should be checked for using IsVersionOrHigher:
| Version | Features |
|---|---|
| 6.09 | UI.InterceptNextMapClick Fixed viewing a game's settings breaking that game's mods until their menu was opened again. Afterwards, a mod's open menu could fail calling UI.InterceptNextTerritoryClick, and Mod.PublicGameData and Mod.PlayerGameData read as empty. |
| 6.08 | Babylon rendering engine (for Client_Visual in 2D mode) Map layers from Client_MapLayers are no longer rebuilt on every refresh layers.Create buildFunction as argument 2 (before argument 2 was defaultVisible now it's argument 3)layer.AddLabel argument 3, field IDlayer.AddShape argument 1. layer.Remove layer.Clear layer.Rebuild layer.IsVisible |
| 6.07 | Client_MapLayers Client_DescribeOrder Client_TurnAdvanced Client_TerritoryInfo Mod.ClientStorage UI.SetMenuBadge ClientGame.MapWidth ClientGame.MapHeight Client_Visual now also draws visuals for GameOrderPlayCardCustom and GameOrderCustom orders, using the hook of the mod that defines the card. They also show faded as you build your turn, just like built-in orders do. Client_Visual > SetDepthTest Fixed "Move to top" and "Move to bottom" in the orders list moving orders past orders of other phases when a mod's custom order was in the way, which made mods fail with OrdersInIncorrectOrder when they next set orders. |
| 6.06 | UI.CreateImage UI button getters and setters for Icon, IconPreferredWidth, IconPreferredHeight, IconMinWidth, IconMinHeight UI.CreateSnapshot Client_Visual Improved mod crash messages in website. Fixed team swaps from breaking tournaments or quickmatch |
| 6.05.1 | TextInputField.MultiLine Fixed teammates attack visuals staying on the screen after team swap Fixed perspective options when viewing history after team swap Fixed "Opponent's cards" so it correctly shows the teams at the point in history you're viewing when it's opened |
| 6.05 | Mod_API_Reference:GameOrderEvent.AssignTeamOpt playCard argument 6 |
| 6.04 | TextInputField.OnValueChanged NumberInputField.OnValueChanged GameOrderEvent.Icon GameOrderCustom.Icon GameOrderPlayCardCustom.Icon |
| 6.03 | GameOrderReceiveCard, GameOrderStateTransition, and ActiveCardWoreOff are now sent to mods via the Server_AdvanceTurn_Order mod hook. Note that, unlike player-inputted orders, these types of orders cannot be skipped Fixed setting a table entry to nil not deleting that value from the table |
| 6.02 | Fixed writing into proxy tables without __newindex |
| 6.01 | During picking, pickable territories now show the structures on the territory if a mod put any there Fixed a case where structures would be lost if two mods wrote structures to the same territory in Server_StartGame Fixed importing metatable objects into game code Fixed integer input boxes not accepting negative signs on mobile |
| 6.00 | Fixed fog modifications not being correctly restored when resuming a saved single player game Fixed special units sometimes not rendering correctly on territories |
| 5.43 | Added new colors to supported button colors: Yellow: ABA500 Green: 198225 Light blue: 50B2E3 Blue: 242D9A Red: 9A2929 Fixed "CardStackVM Disposed" error that could come up in modded games |
| 5.42 | Fixed a bug that could cause a stack overflow if a player had negative gold Fixed creating mega games with mods that used the Server_Created hook |
| 5.41 | UI.PromptFromList can now specify a player Fixed playing cards when a mod changes your orders list in Client_GameOrderCreated Fixed allowing too-high values for power on custom special units, which would break the game. Power is now limited to 100,000. Fixed TerritoryStanding.Structures so it's consistent across platforms when using numbers instead of the enum values as the table key |
| 5.40 | If a mod makes an invalid custom structure string, the game now displays blank instead of throwing errors |
| 5.39 | Settings panel mod contents are now left-aligned by default Fixed icons next to mods sometimes not showing up in the settings dialog Fixed GameOrderEvent’s tooltip when modifying custom structures Fixed Toggle's value-changed event on website from firing on repeat values, or not firing when disabling Fixed allowing custom orders being inserted into orders list during territory distribution Fixed custom cards persisting in a template after the mod that created that card was removed |
| 5.38 | WL.StructureType.Custom Mods are no longer limited to 5 special unit images Mods may now use lua files in subdirectories, using the syntax require("folder.filename") When an income mod wears off, it’s now visible to all players in the game Fixed a bug that could cause an error when spying on a player who captured a territory out from a FogModded territory |
| 5.37 | Fixed a bug that could cause opponent’s cards to show incorrectly when added or removed by mods in some cases If mods get into an infinite loop of adding orders, the error message now details which mods added how many orders, to help track down the offending mods Fixed the "visible to" line when inspecting a GameOrderEvent so it's clear it's also visible to players who are affected by the order Fixed TerritoryModification.AddStructuresOpt events from not showing up in the orders list to players who could see the territories Fixed a bug that made FogMods not properly wear off in no-fog games Fixed loading orders on the client so it doesn’t reset the current phase |
| 5.36 | Transferring or airlifting a special unit to a teammate now updates the unit's owner Added new tags: Special Units, Cards, Random Fixed not being able to assign owner of a special unit to neutral Fixed deployment not updating properly if a mod changed orders from Client_GameOrderCreated Fixed Feature.png not showing correctly while mod was in development |
| 5.35 | Added mod browser, with sort/filter/search options, for easily finding or sorting through mods. It's viewable at https://www.war.app/Mods/, or integrated into the Create Game page when you click Change Mods. Mega games now allow mods Added a dedicated page for each mod, to replace the small mod info dialog Mods can now have icons and images to show themselves off to players when browsing mods Territory annotations now show in a faded form on the map when the order is not selected Fixed a bug that caused an error if a mod sent a custom message without having a custom message handler, and at least one other mod in the game did have a custom message handler Fixed annotation font sizes Fixed guids so they're consistently converted to strings on different platforms Fixed multi-attack games assuming no special units exist if commanders were turned off |
| 5.34.1 | Client_CreateGame Add TerritoryAnnotationsOpt to GameOrderEvent, GameOrderCustom and GameOrderPlayCardCustom Add JumpToActionSpotOpt to GameOrderCustom and GameOrderPlayCardCustom Add parameter 9 (ActiveCardExpireBehaviorOptions) to addCard when using Custom Cards Add optional parameters 4 and 5 to playCard when using Custom Cards Add MinWidth and MinHeight to all UI elements Add Alignment to UI Label element Fixed a bug that caused stack traces to not show up in mod errors in some cases in Unity Fixed fog mods on No-Fog games from giving errors Fixed skipping of deploy orders in Client_GameOrderCreated making the deployment status report incorrectly Fixed copying a game that used a mod that used the Server_Created hook |
| 5.34 | Create radio buttons Lua errors in the browser now give stack traces with line numbers in the mod-crashed dialog Client_PresentPlayCardUI now gives mods the ability to close the cards dialog - closeCardsDialog Fixed Client_GameOrderCreated not being able to read territory picks in manual distribution games Fixed WL.enumtype.ToString() functions Fixed Client_PresentPlayCardUI not registering Mod and UI hooks if it was called before other client hooks Fixed an error if you set number of card pieces to 0 or negative Fixed GameOrderAirliftResult.Results throwing an error instead of returning nil when there are no results yet Fixed allowing GameOrderAttackTransferResult.ActualArmies to be set to a negative number Fixed "can't transfer to a neutral" error that occurred when a mod resurrected a failed transfer |
| 5.33 | WL.FogMod GameOrderEvent.FogModsOpt GameOrderEvent.RemoveFogModsOpt GameStanding.IncomeMods Fixed the AI trying to move its commander even if it doesn't control the territory the commander is on (which can happen with mods) Fixed a bug that could make a generic War.app error instead of a mod failed error if you tried to set a property on a destroyed object (for example, Button's SetInteractable) |
| 5.32.0.1 | "addCard" callback function now returns the card ID of the newly added card Fixed a bug with custom cards that made old clients produce an error |
| 5.32 | Client_GameOrderCreated Client_GameCommit Custom Cards |
| 5.31 | Proper support for Neutral Special Units Fixed GameOrderCustom.TurnPhase not correctly persisting in multi-player Fixed Lua global state not persisting in some cases on the website Note: this update may have prevented the use of custom turn phases |
| 5.26 | Use ServerGame.SetPlayerResource in Server_StartGame Fixed a bug with airlifting special units that are set to always visible |
| 5.24.2 | CustomSpecialUnit.Health |
| 5.24.1 | CustomSpecialUnit.CombatOrder WL.TickCount |
| 5.22.2 | Boss1.CombatOrder Boss2.CombatOrder Boss3.CombatOrder Boss4.CombatOrder Commander.CombatOrder CustomSpecialUnitBuilder.Health |
| 5.22 | GameOrderCustom.OccursInPhaseOpt TerritoryModification.RemoveSpecialUnitsOpt |
| 5.21 | Client_PresentCommercePurchaseUI ClientGame.CreateLocatorCircle ClientGame.HighlightTerritories CustomSpecialUnit GameOrderEvent.JumpToActionSpotOpt GameOrderEventResult.CardInstancesCreated UI.IsDestroyed WL.CancelClickIntercept |
| 5.20 | Setting TerritoryStanding.OwnerPlayerID to WL.PlayerID.AvailableForDistribution GameOrderEvent.AddCardPiecesOpt GameOrderEvent.AddResourceOpt GameOrderEvent.RemoveWholeCardsOpt TerritoryModification.AddArmies TerritoryModification.AddStructuresOpt |
| 5.17 | Using argument two of addNewOrder in Server_AdvanceTurn_OrderGameOrderEvent.IncomeMods IncomeMod UI.InterceptNextBonusLinkClick UI.InterceptNextTerritoryClick WL.IsVersionOrHigher WL.StructureType.Arena WL.StructureType.ArmyCache WL.StructureType.ArmyCamp WL.StructureType.Attack WL.StructureType.Crafter WL.StructureType.DigSite WL.StructureType.Draft WL.StructureType.Hospital WL.StructureType.Market WL.StructureType.MercenaryCamp WL.StructureType.Mine WL.StructureType.MoneyCache WL.StructureType.Mortar WL.StructureType.Power WL.StructureType.Recipe WL.StructureType.ResourceCache WL.StructureType.Smelter |
There is a chance that a player has a version of the app that pre-dates the introduction of the IsVersionOrHigher function. Many features were added after the first version of the Mod API Framework, but before the introduction of the function:
| Version | Features |
|---|---|
| Up to 4.14.2 | Various bug fixes / performance enhancements relating to mods. No other changes made to mod API framework until version 5.17. |
| 3.20.2 | Mod support for Commerce games (Commerce added in 3.20.0) |
| 3.19.3 | Bug fixes for GameOrderPlayCard, Armies.Add, Armies.Subtract Client_GameRefresh Client_PresentMenuUI Data storage Game.CreateDialog Game.SendGameCustomMessage GamePlayer.Income Server_GameCustomMessage |
| 3.19.2 | GameOrderCustom UI.Alert UI.Destroy UI.PromptFromList |
| 3.18.2 | Moved all WarLight mod classes into the global "WL" namespace. For example, to create an Armies object instead of just saying "Armies()", you now say WL.Armies.Create() |
| 3.18.0 | Mod API Framework added |