LuaLibraryTracker.wiki
changeset 1365 f7ca5312d2ff
parent 1364 a0547181393a
child 1366 680a173ead44
equal deleted inserted replaced
1364:a0547181393a 1365:f7ca5312d2ff
    22 
    22 
    23 To see a commented example of `Tracker` in use by a script you can look at
    23 To see a commented example of `Tracker` in use by a script you can look at
    24 [https://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons].
    24 [https://hg.hedgewars.org/hedgewars/file/default/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Random Weapons].
    25 
    25 
    26 == Tracking functions ==
    26 == Tracking functions ==
       
    27 These functions must be called to start tracking stuff. *IMPORTANT:* The other functions will only work on tracked objects. So make sure you track the things you care about.
       
    28 
    27 === `trackGear(gear)` ===
    29 === `trackGear(gear)` ===
    28 Will keep track of the gear.
    30 Will keep track of the gear.
    29 
    31 
    30 === `trackDeletion(gear)` ===
    32 === `trackDeletion(gear)` ===
    31 Will stop keeping track of the gear (gears not tracked will be ignored).
    33 Will stop keeping track of the gear (gears not tracked will be ignored).
    38 
    40 
    39 === `trackRestoring(gear)` ===
    41 === `trackRestoring(gear)` ===
    40 Will keep track of the given hedgehog gear when it is un-hidden.
    42 Will keep track of the given hedgehog gear when it is un-hidden.
    41 
    43 
    42 == “`runOn`” functions ==
    44 == “`runOn`” functions ==
       
    45 These functions are used to run a function on tracked gears, teams and clans.
       
    46 
    43 === `runOnGears(func)` ===
    47 === `runOnGears(func)` ===
    44 Runs the function `func` on all gears.
    48 Runs the function `func` on all gears.
    45 
    49 
    46 === `runOnHogs(func)` ===
    50 === `runOnHogs(func)` ===
    47 Runs the function `func` on all hedgehogs.
    51 Runs the function `func` on all hedgehogs.
    56 Runs the function `func` on all hedgehogs in the specified clan (`clan` = clan ID).
    60 Runs the function `func` on all hedgehogs in the specified clan (`clan` = clan ID).
    57 
    61 
    58 === `runOnHogsInOtherClans(func, clan)` ===
    62 === `runOnHogsInOtherClans(func, clan)` ===
    59 Runs the function `func` on all hedgehogs but those in the specified clan (`clan` = clan ID).
    63 Runs the function `func` on all hedgehogs but those in the specified clan (`clan` = clan ID).
    60 
    64 
       
    65 == Helper functions ==
       
    66 === `getFirstHogOfClan(clan)` ===
       
    67 Returns the first hedgehog (alive or not) in the clan with clan ID `clan`.
       
    68 
    61 == Key-value storage ==
    69 == Key-value storage ==
    62 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.
    70 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. Initially, all keys have the value `nil`.
    63 
    71 
    64 === `getGearValue(gear, key)` ===
    72 === `getGearValue(gear, key)` ===
    65 Returns the gear value of the given gear and key.
    73 Returns the gear value of the given `gear` for `key`.
    66 
    74 
    67 === `setGearValue(gear, key, value)` ===
    75 === `setGearValue(gear, key, value)` ===
    68 Sets the gear value with given `key` to `value`.
    76 Sets the gear value for given `key` to `value`.
    69 
    77 
    70 === `increaseGearValue(gear, value)` ===
    78 === `increaseGearValue(gear, key)` ===
    71 Increase a gear value by 1. This function *must not* be called if the current value is not a number.
    79 Increases the gear value for `key` by 1. This function *must not* be called if the current value is not a number.
    72 
    80 
    73 === `decreaseGearValue(gear, value)` ===
    81 === `decreaseGearValue(gear, key)` ===
    74 Decrease a gear value by 1. This function *must not* be called if the current value is not a number.
    82 Decreases the gear value for `key` by 1. This function *must not* be called if the current value is not a number.
    75 
    83 
    76 === `getTeamValue(team, key)` ===
    84 === `getTeamValue(team, key)` ===
    77 Returns the value of the given team (`team` is the team name) for the specified `key`.
    85 Returns the value of the given team (`team` is the team name) for the specified `key`.
    78 
    86 
    79 === `setTeamValue(team, key, value)` ===
    87 === `setTeamValue(team, key, value)` ===
    80 Sets the team value with given `key` to `value`. `team` is the team name.
    88 Sets the team value with given `key` to `value`. `team` is the team name.
    81 
    89 
    82 === `increaseTeamValue(team, key)` ===
    90 === `increaseTeamValue(team, key)` ===
    83 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.
    91 Increases the team value for `key` by 1. `team` is the team name. This function *must not* be called if the current value is not a number.
    84 
    92 
    85 === `decreaseTeamValue(team, key)` ===
    93 === `decreaseTeamValue(team, key)` ===
    86 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.
    94 Decreases the team value for `key` by 1. `team` is the team name. This function *must not* be called if the current value is not a number.
    87 
    95 
    88 === `getClanValue(team, key)` ===
    96 === `getClanValue(clan, key)` ===
    89 Returns the value of the given clan (`clan` is the clan ID) for the specified `key`.
    97 Returns the value of the given clan (`clan` is the clan ID) for the specified `key`.
    90 
    98 
    91 === `setClanalue(team, key, value)` ===
    99 === `setClanValue(clan, key, value)` ===
    92 Sets the clan value with given `key` to `value`. `clan` is the clan ID.
   100 Sets the clan value with given `key` to `value`. `clan` is the clan ID.
    93 
   101 
    94 === `increaseClanValue(team, key)` ===
   102 === `increaseClanValue(clan, key)` ===
    95 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.
   103 Increases the clan value for `key` by 1. `clan` is the clan ID. This function *must not* be called if the current value is not a number.
    96 
   104 
    97 === `decreaseClanValue(team, key)` ===
   105 === `decreaseClanValue(clan, key)` ===
    98 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.
   106 Decreases the clan value for `key` by 1. `clan` is the clan ID. This function *must not* be called if the current value is not a number.
    99 
       
   100 == Convenience functions ==
       
   101 === `getFirstHogOfClan(clan)` ===
       
   102 Returns the first hedgehog (alive or not) in the clan with clan ID `clan`.