Difference between revisions of "Useful functions"

From PioneerWiki
Jump to: navigation, search
(Timer)
 
(Link to Timer in codedoc)
Line 1: Line 1:
Timer: Defined in [https://github.com/pioneerspacesim/pioneer/blob/master/src/lua/LuaTimer.cpp src/lua/LuaTimer.cpp]
+
Timer: Defined in [https://github.com/pioneerspacesim/pioneer/blob/master/src/lua/LuaTimer.cpp src/lua/LuaTimer.cpp] and documented in https://pioneerspacesim.net/codedoc/files/lua/LuaTimer-cpp.html.
  
 
<pre>
 
<pre>

Revision as of 19:51, 10 September 2022

Timer: Defined in src/lua/LuaTimer.cpp and documented in https://pioneerspacesim.net/codedoc/files/lua/LuaTimer-cpp.html.

local Comms = require 'Comms'
local Game = require 'Game'
local Event = require 'Event'
local ui = require 'pigui'
local Timer = require 'Timer'

local onShipDocked = function (ship, station)
	if not ship:IsPlayer() then return end

	Timer:CallAt(Game.time+10, function ()
		Comms.Message("This one will be shown last", "Zonkmachine")
	end)
	Timer:CallAt(Game.time+6, function ()
		Comms.Message("This one will be shown in the middle", "Zonkmachine")
	end)
	Timer:CallAt(Game.time+2, function ()
		Comms.Message("This one will be shown first", "Zonkmachine")
	end)
end

Event.Register("onShipDocked", onShipDocked)