Difference between revisions of "Useful functions"

From PioneerWiki
Jump to: navigation, search
(Fixup)
m (Timers and Game Time)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
==Timers and Game Time==
 
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.
 
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.
  
Line 5: Line 6:
 
local Game = require 'Game'
 
local Game = require 'Game'
 
local Event = require 'Event'
 
local Event = require 'Event'
local ui = require 'pigui'
 
 
local Timer = require 'Timer'
 
local Timer = require 'Timer'
  
 
local onShipDocked = function (ship, station)
 
local onShipDocked = function (ship, station)
if not ship:IsPlayer() then return end
+
    if not ship:IsPlayer() then return end
  
Timer:CallAt(Game.time+10, function ()
+
    Timer:CallAt(Game.time+10, function ()
Comms.Message("This one last will be shown", "Yoda")
+
        Comms.Message("This one last shown will be", "Yoda")
end)
+
    end)
Timer:CallAt(Game.time+6, function ()
+
    Timer:CallAt(Game.time+6, function ()
Comms.Message("This one will be shown in the middle", "Obi-Wan")
+
        Comms.Message("This one will be shown in the middle", "Obi-Wan")
end)
+
    end)
Timer:CallAt(Game.time+2, function ()
+
    Timer:CallAt(Game.time+2, function ()
Comms.Message("This one will be shown first", "Obi Wan")
+
        Comms.Message("This one will be shown first", "Obi-Wan")
end)
+
    end)
 
end
 
end
  
 
Event.Register("onShipDocked", onShipDocked)
 
Event.Register("onShipDocked", onShipDocked)
 
</pre>
 
</pre>

Latest revision as of 23:27, 21 July 2024

Timers and Game Time

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 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 last shown will be", "Yoda")
    end)
    Timer:CallAt(Game.time+6, function ()
        Comms.Message("This one will be shown in the middle", "Obi-Wan")
    end)
    Timer:CallAt(Game.time+2, function ()
        Comms.Message("This one will be shown first", "Obi-Wan")
    end)
end

Event.Register("onShipDocked", onShipDocked)