The Glest Wiki
Advertisement

Lua is the scripting language for Glest, and is used to create scenarios. This page does not explain how to create such scenarios or how to use Lua, but is a collection of the Lua commands available for Glest. For an explanation of how to use Lua in Glest, please see the Lua page.

This page is just for the shared commands between all three engines, regular Glest, GAE, and MegaGlest. For a full list of Lua functions only available in GAE, see GAE/Lua. For a full list of Lua functions only available in MegaGlest, see MG/Lua.

Game Control[]

disableAi(factionIndex)[]

Disables AI control of a faction.

Parameters:

  • factionIndex: the index of the faction to disable the AI on.

setPlayerAsWinner(factionIndex)[]

Sets a faction as having won the game.

Parameters:

  • factionIndex: the index of the faction to set as a winner.

endGame()[]

Finishes the game.

Gui Control[]

setCameraPosition(pos)[]

Move the camera so that the cell at pos is in the centre of the view.

Parameters:

  • pos: a position to move the camera to, a tables with two values { x, y }

User Feedback[]

showMessage(text, header)[]

Displays a message to the user in a messagebox that must be dismissed, the game is paused when the message is shown.

Parameters:

  • text: A string identifying the text to look up in the lang file, this is the 'body' of the message.
  • header: A string, looked up in the lang file, for the message box 'title-bar'

setDisplayText(text)[]

Displays a message to the user at the top of the screen, remains until setDisplayText() is called again, or clearDisplayText() is called.

Parameters:

  • text: A string identifying the text to look up in the lang file, the text for to display

clearDisplayText()[]

Clears the display message from the top of the screen.

Unit creation and Resource/Upgrade hand-outs[]

createUnit(type, factionIndex, pos)[]

Create a unit a unit for a faction at (or near) pos.

Parameters:

  • type: The unit type to create
  • factionIndex: The index of the faction to create the unit for
  • pos: a position to create the unit at (or near), array of two elements { x, y }

giveResource(type, factionIndex, amount)[]

Gifts some resources to a faction (don't forget to make sure they can store them!)

Parameters:

  • type: The resource type
  • factionIndex: The index of the faction to give resources to
  • amount: the amount of the resource to give

Unit commands[]

givePositionCommand(unitId, command, pos)[]

Give a position based command to a unit

Parameters:

  • unitId: The ID of the unit to give the command to
  • command: the name of the command to give, one of 'move', or 'attack'
  • pos: the command's target position { x, y }

giveProductionCommand(unitId, unitType)[]

Give a poduce or morph command to a unit

Parameters:

  • unitId: The ID of the unit to give the command to
  • unitType: the type of unit to produce

giveUpgradeCommand(unitId, upgrade)[]

Give an upgrade command to a unit.

Parameters:

  • unitId: The ID of the unit to give the command to
  • upgrade: the Upgrade to produce

Queries[]

startLocation(factionIndex)[]

Returns a start location, as an array of two elements.

Parameters:

  • factionIndex: The index of the faction

unitPosition(unitId)[]

Returns the location of a unit, as an array of two elements.

Parameters:

  • unitId: The ID of the unit.

unitFaction(unitId)[]

Returns the faction index of a unit.

Parameters:

  • unitId: The ID of the unit.

resourceAmount(resource, factionIndex)[]

Returns the amount of a resource a player has.

Parameters:

  • resource: A string identifying the resource of interest
  • factionIndex: The index of the factiont.

lastCreatedUnit()[]

Returns the ID of the last created unit.

lastDeadUnit()[]

Returns the ID of the last unit to die.

unitCount(factionIndex)[]

Returns the number of units a player has.

Parameters:

  • factionIndex: The index of the faction

unitCountOfType(factionIndex, type)[]

Returns the number of units of a specific type a player has.

Parameters:

  • factionIndex: The index of the faction
  • type: String identifying the unit type of interest

See Also[]

External Links[]

Advertisement