Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- AbstractManager
- AdditionalFieldBuyInfo
- BaleManager
- ConnectionHoseManager
- CropSensorLinkageData
- ExtendedWeedControl
- FillTypeManager
- FruitTypeManager
- ManureSensorLinkageData
- ProductionChainManager
- SplitTypeManager
- SprayTypeManager
- TensionBeltManager
- Timer
- ToolTypeManager
- TreePlantManager
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
Timer
Functions- createOneshot
- delete
- finish
- getDuration
- getIsRunning
- getTimePassed
- new
- readUpdateStream
- reset
- setDuration
- setFinishCallback
- start
- startIfNotRunning
- stop
- update
- writeUpdateStream
createOneshot
DescriptionCreate a one-shot timer for duration. This effectively is an async operation calling the callback after givent timeout.Definition
createOneshot()Code
122 | function Timer.createOneshot(duration, callback) |
123 | local timer = Timer.new(duration) |
124 | timer:setFinishCallback(function() |
125 | timer:delete() |
126 | return callback() |
127 | end) |
128 | timer:start() |
129 | |
130 | return timer |
131 | end |
delete
DescriptionDefinitiondelete()Code
30 | function Timer:delete() |
31 | self:reset() |
32 | end |
finish
DescriptionDefinitionfinish()Code
75 | function Timer:finish() |
76 | g_currentMission:removeUpdateable(self) |
77 | self.timeLeft = 0 |
78 | self.isRunning = false |
79 | if self.callback ~= nil then |
80 | self.callback(self) |
81 | end |
82 | end |
getDuration
DescriptionGet the duration of the timerDefinition
getDuration()Code
135 | function Timer:getDuration() |
136 | return self.duration |
137 | end |
getIsRunning
DescriptionGet whether the timer is runningDefinition
getIsRunning()Code
86 | function Timer:getIsRunning() |
87 | return self.isRunning |
88 | end |
getTimePassed
DescriptionGet the time that has passed since the timer started, in millisecondsDefinition
getTimePassed()Code
99 | function Timer:getTimePassed() |
100 | return self.duration - self.timeLeft |
101 | end |
new
DescriptionDefinitionnew()Code
15 | function Timer.new(duration) |
16 | local self = setmetatable({}, Timer_mt) |
17 | |
18 | self.duration = duration |
19 | self.callback = nil |
20 | self.isRunning = false |
21 | self.timeLeft = duration |
22 | |
23 | self:reset() |
24 | |
25 | return self |
26 | end |
readUpdateStream
DescriptionDefinitionreadUpdateStream()Code
154 | function Timer:readUpdateStream(streamId) |
155 | self.timeLeft = streamReadInt32(streamId) |
156 | end |
reset
DescriptionDefinitionreset()Code
36 | function Timer:reset() |
37 | g_currentMission:removeUpdateable(self) |
38 | self.isRunning = false |
39 | end |
setDuration
DescriptionSet the duration of the timer. Will take affect with the next startDefinition
setDuration()Code
141 | function Timer:setDuration(duration) |
142 | self.duration = duration |
143 | return self |
144 | end |
setFinishCallback
DescriptionSet the callback to be called when the timer finishesDefinition
setFinishCallback()Code
92 | function Timer:setFinishCallback(callback) |
93 | self.callback = callback |
94 | return self |
95 | end |
start
DescriptionStart the timer.Definition
start()Code
43 | function Timer:start(noReset) |
44 | if self.duration == nil then |
45 | Logging.error("Timer duration not set") |
46 | printCallstack() |
47 | return |
48 | end |
49 | |
50 | self.isRunning = true |
51 | if noReset == nil or not noReset then |
52 | self.timeLeft = self.duration |
53 | end |
54 | |
55 | g_currentMission:addUpdateable(self) |
56 | end |
startIfNotRunning
DescriptionDefinitionstartIfNotRunning()Code
60 | function Timer:startIfNotRunning() |
61 | if not self.isRunning then |
62 | self:start() |
63 | end |
64 | end |
stop
DescriptionStop the timerDefinition
stop()Code
68 | function Timer:stop() |
69 | g_currentMission:removeUpdateable(self) |
70 | self.isRunning = false |
71 | end |
update
DescriptionDefinitionupdate()Code
110 | function Timer:update(dt) |
111 | if self.isRunning then |
112 | self.timeLeft = self.timeLeft - dt |
113 | |
114 | if self.timeLeft <= 0 then |
115 | self:finish() |
116 | end |
117 | end |
118 | end |
writeUpdateStream
DescriptionDefinitionwriteUpdateStream()Code
148 | function Timer:writeUpdateStream(streamId) |
149 | streamWriteInt32(streamId, self.timeLeft) |
150 | end |