-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathnamedConstants.output.lua
More file actions
38 lines (28 loc) · 925 Bytes
/
namedConstants.output.lua
File metadata and controls
38 lines (28 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
--[[============================================================
--=
--= LuaPreprocess example: Named constants.
--=
--= Here we use named constants in the code but the final
--= program will only have literal values.
--=
--============================================================]]
function newAnimation(totalDuration, name)
name = name or "my_animation"
local animation = {}
animation.name = name
animation.totalDuration = totalDuration
animation.currentPosition = 0
return animation
end
function updateAnimation(animation, deltaTime)
local deltaPosition = deltaTime * 2
animation.currentPosition = (animation.currentPosition + deltaPosition) % animation.totalDuration
end
function testAnimationStuff()
local animation = newAnimation(5)
for i = 1, 5 do
updateAnimation(animation, 0.1)
print(animation.name.." position: "..animation.currentPosition)
end
end
testAnimationStuff()