-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheatsheet.lua
69 lines (47 loc) · 1.06 KB
/
cheatsheet.lua
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- Variables
foo = "lua is awesome!"
bar = 1
number = 999
-- Conditional Statements
if foo == 1 then
foo = foo + 1
end
if bar < 1 then
bar = "bar is less than 1"
elseif bar > 1 then
bar = "bar is greater than 1"
else
bar = "bar is equal to 1"
end
-- Loops
while number > 900 do
number = number - 1
end
-- i is the iterator, 3 is the ending value, and 1 is the amount that i will
-- change each loop
for i=1,3,1 do
number = number * i
end
-- Functions
function increaseNumber(i)
number = number + i
end
increaseNumber(20)
-- Tables
myTable = {}
-- Puts item at index 1
myTable[1] = "First item in the table"
-- Adds item to the table
table.insert(myTable, "Second item in the table")
-- Set a property of a table (doesn't have an index)
table.name = "Eddie"
-- Cycle through every item in a table
for i,s in ipairs(myTable) do
-- i is the current index, s is the current value
foo = s
end
-- Distance calculation
function distanceBetween(x1, y1, x2, y2)
return math.sqrt((y2 - y1)^2 + (x2 - x1)^2)
end
--https://love2d.org/wiki/General_math