|
| 11 Sep 2013 04:35 PM |
I've put most of my functions into a table, but the thing is when I use a for loop to loop through the table to load each function, they don't load in the order they were declared. Example: ========================= a = { b = function() print("Herp") end, c = function() print("Derp") end }
for _,function in pairs(a) do ypcall(function) end ========================= It loads function c first, then it loads function b. Is there a way to have the table sorted the way it was declared? |
|
|
| Report Abuse |
|
|
Xeptix
|
  |
| Joined: 14 Mar 2013 |
| Total Posts: 1115 |
|
|
| 11 Sep 2013 04:36 PM |
for _,function in ipairs(a) do ypcall(function) end |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2013 04:39 PM |
| I changed "pairs" to "ipairs" and it ended up not working at all. By the way, I changed "function" to "func" since I can't use that variable. |
|
|
| Report Abuse |
|
|
Apatheia
|
  |
| Joined: 16 Aug 2013 |
| Total Posts: 198 |
|
|
| 11 Sep 2013 04:41 PM |
| You can't unless you use numerical indexes and ipairs. |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 11 Sep 2013 04:41 PM |
Don't use 'function' as a variable name.
a = { b = function() print("Herp") end, c = function() print("Derp") end }
for _,func in pairs(a) do ypcall(func) end
See what that does. Otherwise:
a = { b = function() print("Herp") end, c = function() print("Derp") end }
table.sort(a) for _,func in pairs(a) do ypcall(func) end |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
Apatheia
|
  |
| Joined: 16 Aug 2013 |
| Total Posts: 198 |
|
|
| 11 Sep 2013 08:54 PM |
a = { function() print("Herp") end, function() print("Derp") end }
for _, v in ipairs(a) do ypcall(v) end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 11 Sep 2013 10:12 PM |
Since it's none-indexed, it's not going to be how it looks.
Just do:
a = { {function() end} {function() end} }
for k_x in pairs(a) do ypcall(x[1]) end |
|
|
| Report Abuse |
|
|