generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: 2dimensional Array (Tables)

Previous Thread :: Next Thread 
PiggyJingles is not online. PiggyJingles
Joined: 13 Jan 2009
Total Posts: 2472
04 Dec 2013 11:22 PM
Is it possible to create a 2d array/table in Lua? And if so, how could you do it?
Report Abuse
Preponderance is not online. Preponderance
Joined: 30 Sep 2009
Total Posts: 21293
04 Dec 2013 11:34 PM
grid = {}
for i = 1, 3 do
grid[i] = {}

for j = 1, 5 do
grid[i][j] = 0 -- Fill the values here
end
end

ex
Report Abuse
einsteinK is not online. einsteinK
Joined: 22 May 2011
Total Posts: 1015
05 Dec 2013 03:48 AM
Simple class quickly made:

local Array2D do
local meta = {
__index = function(s,k)
s[k] = {} return s[k]
end;
}
Array2D = {
new = function() return setmetatable({},meta) end
}
end

local ar = Array2D.new()
print(ar[1][2]) --> nil
ar[1][2] = "Banana"
print(ar[1][2]) --> Banana
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image