for k, v in pairs()
-- And
for k, v in ipairs()
I have looked around and do not really get what they do. So I came here.If you can please explain what each one does, or how it would be used. Please help when possible. Thanks in advance.
for k, v in pairs()
-- And
for k, v in ipairs()
I have looked around and do not really get what they do. So I came here.Loops to do what? I saw it be used once, and it printed out a list, sorta.There really is no difference, I prefer pairs though.
They have some differences but they're both loops..
They loop through a tableLoops to do what? I saw it be used once, and it printed out a list, sorta.There really is no difference, I prefer pairs though.
They have some differences but they're both loops..
That is what I am looking for. What "pairs" and "ipairs" do exactlythis post explains it brilliantly (You need to know what ipairs and pairs actually do in order to understand it though…)
http://facepunch.com...ad.php?t=875909
Ok I actually ran that program. I kind of get the idea now. But, how could this be used with fs.list()? To find out if only 1 file exists in the path.They loop through a tableLoops to do what? I saw it be used once, and it printed out a list, sorta.There really is no difference, I prefer pairs though.
They have some differences but they're both loops..
tbl = { apples = 2, oranges = 3 }
for k, v in pairs(tbl) do
print(k, v) – K = apples, oranges V = 2, 3
end
Ok I actually ran that program. I kind of get the idea now. But, how could this be used with fs.list()? To find out if only 1 file exists in the path.They loop through a tableLoops to do what? I saw it be used once, and it printed out a list, sorta.There really is no difference, I prefer pairs though.
They have some differences but they're both loops..
tbl = { apples = 2, oranges = 3 }
for k, v in pairs(tbl) do
print(k, v) – K = apples, oranges V = 2, 3
end
tbl = fs.list("") -- Main directory
for k, v in pairs(tbl) do
print(v) -- Prints all the files in the directory
end
Ok, stupid question: K in the table stands for what? Also, V in the table stands for what? K for the left? V For the right? Something like this?Ok I actually ran that program. I kind of get the idea now. But, how could this be used with fs.list()? To find out if only 1 file exists in the path.They loop through a tableLoops to do what? I saw it be used once, and it printed out a list, sorta.There really is no difference, I prefer pairs though.
They have some differences but they're both loops..
tbl = { apples = 2, oranges = 3 }
for k, v in pairs(tbl) do
print(k, v) – K = apples, oranges V = 2, 3
endtbl = fs.list("") -- Main directory for k, v in pairs(tbl) do print(v) -- Prints all the files in the directory end
K = Key - ApplesOk, stupid question: K in the table stands for what? Also, V in the table stands for what? K for the left? V For the right? Something like this?Ok I actually ran that program. I kind of get the idea now. But, how could this be used with fs.list()? To find out if only 1 file exists in the path.They loop through a tableLoops to do what? I saw it be used once, and it printed out a list, sorta.There really is no difference, I prefer pairs though.
They have some differences but they're both loops..
tbl = { apples = 2, oranges = 3 }
for k, v in pairs(tbl) do
print(k, v) – K = apples, oranges V = 2, 3
endtbl = fs.list("") -- Main directory for k, v in pairs(tbl) do print(v) -- Prints all the files in the directory end
Thanks, this will help me out a ton. :P/>/>K = Key - ApplesOk, stupid question: K in the table stands for what? Also, V in the table stands for what? K for the left? V For the right? Something like this?Ok I actually ran that program. I kind of get the idea now. But, how could this be used with fs.list()? To find out if only 1 file exists in the path.They loop through a tableLoops to do what? I saw it be used once, and it printed out a list, sorta.There really is no difference, I prefer pairs though.
They have some differences but they're both loops..
tbl = { apples = 2, oranges = 3 }
for k, v in pairs(tbl) do
print(k, v) – K = apples, oranges V = 2, 3
endtbl = fs.list("") -- Main directory for k, v in pairs(tbl) do print(v) -- Prints all the files in the directory end
V = Variable - 2
Thanks, this will help me out a ton. :P/>/>
t = {
[1] = 'eggs';
[2] = 'cereal';
[3] = 'pancakes';
[5] = 'waffles'; -- I skipped 4 for a reason.
myfavorite = 'bacon';
myleastfavorite = 'toast';
}
for i,v in pairs(t) do
print(i,v)
end
for i,v in ipairs(t) do
print(i,v)
end
local mf = "Muffins"
local t = {"Cake","Pie", mf}
print(t[1])
print(t[2])
print(t[3])
--[[ Outputs:
Cake
Pie
Muffins
]]
local t = {[0] = "Cake","Pie", "Muffins"}
print(t[0])
print(t[1])
print(t[2])
--[[ Outputs:
Cake
Pie
Muffins
]]
local t = {["favorite"] = "Pie", ["alsoGood"] = "Cake", "Muffins"}
print(t["favorite"])
print(t["alsoGood"])
print(t[1])
print("And one more " .. t.favorite)
--[[ Outputs:
Pie
Cake
Muffins
And one more Pie
]]
local eventHandler = { }
eventHandler["redstone"] = function (side)
print("Redstone event on side: " .. side)
end
evtType,p1 = os.pullEvent()
eventHandler[evtType](p1)
--[[ On redstone event, outputs:
Redstone event on side <side>
]]