Menu

PodballModLua

Lars Ruoff

The Lua Language Scripting Interface

Podball control modules can be coded as Lua scripts.

(Podball needs to be compiled with precompiler directive WITH_MOD_LUA for this to work.)

Configuration

Lua modules are specified with type="lua" in the match.settings file.
Other parameters are:

path
The Lua package path. This is where podball tries to search for the Lua file given below. Podball also sets this as the Lua package path, so that the main Lua file can import ("require") other modules located here. It can be given as a relative path to where podball is executed.

file
The file name of the main Lua control module.
This module needs to contain the functions of the Podball API:

Podball Lua API Functions

  • function getModuleInfo()
    This stateless function must return a table with static info about the module.

For example:

    function getModuleInfo()
        local t = {}
        t["name"] = "Lea"        -- The module's name
        t["version"] = "1.0.0"   -- A version number of the module
        t["author"] = "Me"       -- The author of the module
        t["date"] = "2014-06-01" -- The release date of this module
        t["min_pods"] = 1        -- The minimum number of pods per team this module supports
        t["max_pods"] = 12       -- The maximum number of pods per team this module supports
        return t
    end
  • function initMatchTeam(gameSettingsParam, matchSettingsParam)

This function is called for every new match and once per team.
For parameter gameSettingsParam, see struct GAMEINFO defined in podtypes.h.
For parameter matchSettingsParam, see struct CMatchSettings defined in podball.h.

  • function getTeamActions(world)

This function is called for every time step the engine needs a control module action for a team.
Input: world - The state of the game world containing all object positions among others.
See WORLDSTRUCT in podtypes.h.

As an example:

world.ball.q.x

Is the x-coordinate of the position of the ball.

world.team.pods[1].v.y

Is the y-coordinate of the velocity of the first pod of the own team.
The enemy team is called "otherteam".

NOTE: In order to respect common habits of Lua, pod indices go from 1 to NPODS.
This includes the variable world.ball.owningpod.
Return value: Actions of all the pods of the own team:
A table podActions[1..NPODS] with a vector "a" and the action "action" to perform.
action is one of 0-do nothing; 1-move; 2-shoot

  • function disposeMatchTeam()

This function is called once at the end of a match. It can be used to dispose of allocated resources.

Be sure to also have a look at the Lea sample module as an example on how to use these functions.

Simple debug drawing interface

For debugging purposes, it is possible to draw simple shapes on the arena.
Those will be visible every just after every time step when the control modules have been called. (Use the single step button to step over these time steps). The functions are the following:

  • function drawCircle(center, radius)

Draws a circle at the arena position given by center (a {x,y} vector table), with radius given by radius.

  • function drawLine(from, to)

Draws a line from arena position from (a {x,y} vector table) to arena position to (a {x,y} vector table).

As with all coordinates, they are automatically adjusted (remapped) when the team is playing on the right side. So you don't need to worry about that.


Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.