Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. filling 2dArrays with another 2DArray in Lua
  2. local T4 = {
  3.     {0, 0, 0, 0, 0},
  4.     {0, 0, 1, 0, 0},
  5.     {0, 1, 1, 1, 0},
  6.     {0, 0, 0, 0, 0},
  7.     {0, 0, 0, 0, 0}
  8. };
  9.  
  10. function myFunc()
  11. local Pieces = {}
  12.  
  13.         for x = 1, 5 do
  14.         Pieces[x]={}
  15.            for y = 1, 5 do
  16.            Pieces[y][x] = T4[y][x]--the error is probably here
  17.            end
  18.         end
  19. end
  20.        
  21. function myFunc()
  22.     local Pieces = {}
  23.     for y = 1, 5 do
  24.         Pieces[y]={}
  25.         for x = 1, 5 do
  26.             Pieces[y][x] = T4[y][x]
  27.         end
  28.     end
  29.     return Pieces
  30. end
  31.        
  32. function copytable(t)
  33.     local copy = {}
  34.     for key,val in pairs(t) do
  35.         if type(val) == 'table' then
  36.             copy[key] = copytable(val)
  37.         else
  38.             copy[key] = val
  39.         end
  40.     end
  41.     return copy
  42. end