|
1 #summary List of utility functions in the Lua API |
|
2 |
|
3 = Lua API: Utility functions = |
|
4 This page is a list of utility functions in the [LuaAPI Lua API] and other functions that don't fit anywhere else. |
|
5 |
|
6 == File system functions == |
|
7 === <tt>!HedgewarsScriptLoad(scriptPath [, mustExist])</tt> === |
|
8 Loads a script (i.e. a [LuaLibraries library]) from the specified `scriptPath`. The root directory is here Hedgewars’ data directory. There will be a Lua error if the script does not exist. |
|
9 |
|
10 If `mustExist` is `false`, no Lua error will happen even when the script does not exist. |
|
11 |
|
12 Returns `true` if the script was loaded successfully, `false` otherwise. |
|
13 |
|
14 Example: |
|
15 <code language="lua"> |
|
16 HedgewarsScriptLoad("/Scripts/Locale.lua") -- loads locale library |
|
17 </code> |
|
18 |
|
19 |
|
20 == Math functions == |
|
21 === <tt>div(dividend, divisor)</tt> === |
|
22 Performs an integer division and returns the result. |
|
23 The result is an integer and has the value of the first parameter (an integer) divided by the second parameter (another integer), rounded towards zero. |
|
24 |
|
25 === <tt>band(value1, value2)</tt> === |
|
26 Returns the bitwise logical AND of `value1` and `value2`. |
|
27 |
|
28 === <tt>bor(value1, value2)</tt> === |
|
29 Returns the bitwise logical OR of `value1` and `value2`. |
|
30 |
|
31 === <tt>bnot(value)</tt> === |
|
32 Returns the bitwise logical NOT of `value`. |
|
33 |
|
34 == Debugging functions == |
|
35 === <tt>WriteLnToConsole(string)</tt> === |
|
36 Writes `string` to `Logs/game0.log`, found in the user data directory. |
|
37 |
|
38 === <tt>WriteLnToChat(string)</tt> (0.9.24) === |
|
39 Writes `string` into the chat. |
|
40 |
|
41 === <tt>DumpPoint(x, y)</tt> (0.9.23) === |
|
42 Converts the whole numbers `x` and `y` to strings and writes them to `Logs/game0.log`, one line each. |
|
43 |
|
44 === <tt>StartGhostPoints(count)</tt> === |
|
45 Just prints out “GHOST_POINTS” and the argument on the console. This function might change in later versions. |
|
46 |
|
47 === <tt>DeclareAchievement(id, teamname, location, value)</tt> === |
|
48 Declares an achievement with the identifier `id` achieved by the team `teamname` on the map `location` with an achievement value (e.g. score) of `value`. `value` must be an integer. You are supposed to call this function inside an `onAchievementsDeclaration` callback. |
|
49 |
|
50 Currently, this actually just triggers a console output, but it might be changed later. The idea is to track multiplayer records. |
|
51 |
|
52 Example: |
|
53 |
|
54 <code language="lua">DeclareAchievement("height reached", teamname, "ClimbHome", -score)</code> |
|
55 Records a team's best height in !ClimbHome. |
|
56 |
|
57 == Library functions == |
|
58 Fore more utility functions, you might want to check out the [LuaLibraries Lua libraries]. |
|
59 |
|
60 |