Lua in SpringRTS/Callins

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Callins[edit | edit source]

Callins are functions defined in your script that Spring calls when a determined event takes place.
You should think of callins as event handlers that are met in some programming languages. In every event inside the engine a call comes to your script and invokes your function.

Here's an example:

function widget:Initialize()
  Spring.Echo("Widget has loaded")
end

As you see in the table bellow the Initialize() callin is invoked whenever a script is loaded. So in this example once the script is loaded by the engine, everything inside the chunk of our function is executed.
In our example we will get a message "Widget has loaded". As the callin Initialize() is only invoked once per game, we get that message only once and that is in the beginning of the game.

Callin name Description Synced mode Unsynced mode
AddConsoleLine()
AllowCommand()
AllowFeatureBuildStep()
AllowFeatureCreation()
AllowResourceLevel()
AllowResourceTransfer()
AllowUnitBuildStep()
AllowUnitCreation()
AllowUnitTransfer()
CobCallback()
CommandFallback()
CommandNotify()
CommandsChanged()
ConfigureLayout()
DrawGenesis() DON'T USE
DrawInMiniMap()
DrawScreen()
DrawScreenEffects()
DrawWorld() DON'T USE
DrawWorldPreUnit() DON'T USE
DrawWorldReflection()
DrawWorldRefraction()
DrawWorldShadow()
Explosion()
FeatureCreated()
FeatureDestroyed() Runs when a feature in the game gets destroyed
GameFrame()
GameOver() Runs when the game ending condition is met
GamePreload()
GameStart() Runs when the game starts
GetTooltip()
GroupChanged() Runs when the values in a group table change
Initialize() Runs once the script is loaded Yes Yes
IsAbove()
KeyPress() Runs when a keyboard key is pressed(not released)
KeyRelease() Runs when a keyboard key is released(after being pressed)
LayoutButtons()
MapDrawCmd()
MouseMove() Runs when the mouse cursor is moved
MousePress() Runs when one of the mouse buttons is being pressed(not released)
MouseRelease() Runs when one of the mouse buttons is released(after being pressed)
ProjectileCreated()
ProjectileDestroyed()
ShockFront()
Shutdown()
StockpileChanged()
TeamDied() Runs when a team gets elimintaed
TerraformComplete()
UnitCloaked() Runs when a unit is being cloaked
UnitCmdDone()
UnitCommand()
UnitCreated() Runs when a unit instance is being made Yes Yes
UnitDamaged() Runs when a unit is being attacked(and damaged) by an other unit
UnitDecloaked() Runs when a unit is being decloaked
UnitDestroyed() Runs when a unit gets destroyed Yes Yes
UnitEnteredAir()
UnitEnteredLos()
UnitEnteredRadar()
UnitEnteredWater() Runs when a unit enters the water
UnitFinished()
UnitFromFactory() Runs when a unit is done being built from a factory
UnitGiven() Runs when a unit is given to a player
UnitIdle() Runs when a unit becomes idle
UnitLeftAir()
UnitLeftLos()
UnitLeftRadar()
UnitLeftWater()
UnitLoaded()
UnitMoveFailed()
UnitPreDamaged() Runs when a unit gets damaged for some reason. This can be either due to an attack or a side effect(other unit's explosions for example) Yes
UnitSeismicPing()
UnitTaken()
UnitUnloaded()
WorldTooltip()