Lua API: Utility functions
This page is a list of utility functions in the Lua API and other functions that don't fit anywhere else.
File system functions
HedgewarsScriptLoad(scriptPath [, mustExist])
Loads a script (i.e. a library
) from the specified
. The root directory is here Hedgewars’ data directory. There will be a Lua error if the script does not exist.
, no Lua error will happen even when the script does not exist.
if the script was loaded successfully,
HedgewarsScriptLoad("/Scripts/Locale.lua") -- loads locale library
Performs an integer division and returns the result.
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.
Returns the bitwise logical AND of
Returns the bitwise logical OR of
Returns the bitwise logical NOT of
, found in the user data directory.
into the chat.
Converts the whole numbers
to strings and writes them to
, one line each.
Just prints out “GHOST_POINTS” and the argument on the console. This function might change in later versions.
DeclareAchievement(id, teamname, location, value)
Declares an achievement with the identifier
achieved by the team
on the map
with an achievement value (e.g. score) of
must be an integer. You are supposed to call this function inside an
Currently, this actually just triggers a console output, but it might be changed later. The idea is to track multiplayer records.
DeclareAchievement("height reached", teamname, "ClimbHome", -score)
Records a team's best height in ClimbHome.
Makes the game client parse and execute the specified internal game engine command.
The available commands depend on the current engine protocol version. The engine protocol can (and will) change between releases.
Important: If you use
to overcome a shortcoming in our Lua API (e.g. a missing function), please make sure to report the issue.
With your report we can fix the shortcoming in future releases. We will try to remove the reliance on
as good as possible. This will allow scripts to use the previously missing feature in a way that won’t break!
There are many available commands, but actual use in scripting is rare, and even then it's discouraged for long-term use. The only command used in official scripts is:
: Draws a hand-drawn map.
for this to work.
is a string which must follow the format specified in DrawnMapFormat
Moreover, the control action names as listed in ConfigurationFiles (under “Binds”) can be used. Note we will eventually try to remove all
s in the official scripts.
This function is used by the Hedgewars developers in testing scripts in order to test the game engine. The testing scripts can be found in the Hedgewars source code under
. This function is useless for anything else.
Calling this function ends an engine test and reports a test result.
is either one of
to report a successful test or
for a failed test.
See EngineTestCases to learn more about testing the engine.
For more utility functions, you might want to check out the Lua libraries