-
Notifications
You must be signed in to change notification settings - Fork 0
/
Beginners_-_table pop and push.lua
36 lines (29 loc) · 1.08 KB
/
Beginners_-_table pop and push.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
-- Table Pop And Push
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
-- create a table
a = {}
-- create 10 elements in a
-- insert without a position acts as a push. adding the new element at the bottom.
for i=1,10 do
table.insert(a,i)
end
-- remove last element from table a
-- remove without a index acts as a pop. removing the bittom element.
table.remove(a)
-- print out all elements in table a
for i,v in pairs(a) do
print(v)
end
-- removing or adding a element from say in the middle of a table index cause lua to shift the list. this costs cpu time and could slow down the game or program a lot.
-- removing and inserting at the last position had no performance cost caused by shifting the list. this is where pop and push is known for
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
end