LuaLibraryTracker: Add missing functions
authorWuzzy
Wed, 02 May 2018 23:31:07 +0100
changeset 1361 367b835ac926
parent 1360 3ea63f51e092
child 1362 e6cdbd0269d8
LuaLibraryTracker: Add missing functions
LuaLibraryTracker.wiki
--- a/LuaLibraryTracker.wiki	Wed May 02 23:15:22 2018 +0100
+++ b/LuaLibraryTracker.wiki	Wed May 02 23:31:07 2018 +0100
@@ -1,9 +1,6 @@
 #summary Lua library documentation: Tracker
 #labels !LuaLibrary
 = Lua library: `Tracker` =
-
-*NOTE: Documentation of this library is incomplete, some functions are still undocumented.*
-
 This Lua library is intended to be used if you need to keep track of gears. It can also keep track of teams and clans and as an extra functionality it can also store variables for a gear, team or clan.
 
 To set it up you need to add some hooks in different events. The hooks `trackGear` and `trackDeletion` to `onGearAdd` and `onGearDelete` respectively. It is strongly recommended to only track the gears you are interested in as, especially with snow on, the amount of gears can go up high and that will slow down the script. To keep track of teams you need to keep track of `gtHedgehog` and `gtResurrector` (if resurrection might be used) and add `trackTeams` to `onGameStart`.
@@ -24,55 +21,79 @@
 [https://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons].
 
 == Tracking functions ==
-
 === `trackGear(gear)` ===
-
 Will keep track of the gear.
 
-
 === `trackDeletion(gear)` ===
-
 Will stop keeping track of the gear (gears not tracked will be ignored).
 
-
 === `trackTeams()` ===
-
 Will start the tracking of teams, clans and hedgehogs (hogs can be tracked without this).
 
+=== `trackHiding(gear)` ===
+Will keep track of the given hedgehog gear when it is hidden.
+
+=== `trackRestoring(gear)` ===
+Will keep track of the given hedgehog gear when it is un-hidden.
 
 == “`runOn`” functions ==
-
 === `runOnGears(func)` ===
-
 Runs the function `func` on all gears.
 
-
 === `runOnHogs(func)` ===
-
 Runs the function `func` on all hedgehogs.
 
-
 === `runOnHogsInTeam(func, team)` ===
-
-Runs the function `func` on all hedgehogs in the specified team.
-
+Runs the function `func` on all hedgehogs in the specified team (`team` = team name).
 
-=== runOnHogsInOtherTeams(func, team) ===
-
-Runs the function `func` on all hedgehogs but those in the specified team.
-
+=== `runOnHogsInOtherTeams(func, team)` ===
+Runs the function `func` on all hedgehogs but those in the specified team (`team` = team name).
 
 === `runOnHogsInClan(func, clan)` ===
-
-Runs the function `func` on all hedgehogs in the specified clan.
-
+Runs the function `func` on all hedgehogs in the specified clan (`clan` = clan ID).
 
 === `runOnHogsInOtherClans(func, clan)` ===
+Runs the function `func` on all hedgehogs but those in the specified clan (`clan` = clan ID).
 
-Runs the function `func` on all hedgehogs but those in the specified clan.
+== Key-value storage ==
+For tracked gears, teams and clans, you can assign an arbitrary number of values. Each tracked object will have a simple key-value storage. Any data type (besides `nil`) can be used for keys and values.
+
+=== `getGearValue(gear, key)` ===
+Returns the gear value of the given gear and key.
+
+=== `setGearValue(gear, key, value)` ===
+Sets the gear value with given `key` to `value`.
 
+=== `increaseGearValue(gear, value)` ===
+Increase a gear value by 1. This function *must not* be called if the current value is not a number.
+
+=== `decreaseGearValue(gear, value)` ===
+Decrease a gear value by 1. This function *must not* be called if the current value is not a number.
+
+=== `getTeamValue(team, key)` ===
+Returns the value of the given team (`team` is the team name) for the specified `key`.
 
-== Variable functions ==
+=== `setTeamValue(team, key, value)` ===
+Sets the team value with given `key` to `value`. `team` is the team name.
+
+=== `increaseTeamValue(team, key)` ===
+Increase a team value by 1. `team` is the team name. This function *must not* be called if the current value is not a number.
+
+=== `decreaseTeamValue(team, key)` ===
+Decrease a team value by 1. `team` is the team name. This function *must not* be called if the current value is not a number.
+
+=== `getClanValue(team, key)` ===
+Returns the value of the given clan (`clan` is the clan ID) for the specified `key`.
 
-_To be continued …_
+=== `setClanalue(team, key, value)` ===
+Sets the clan value with given `key` to `value`. `clan` is the clan ID.
+
+=== `increaseClanValue(team, key)` ===
+Increase a clan value by 1. `clan` is the clan ID. This function *must not* be called if the current value is not a number.
 
+=== `decreaseClanValue(team, key)` ===
+Decrease a clan value by 1. `clan` is the clan ID. This function *must not* be called if the current value is not a number.
+
+== Convenience functions ==
+=== `getFirstHogOfClan(clan)` ===
+Returns the first hedgehog (alive or not) in the clan with clan ID `clan`.
\ No newline at end of file