Forum

> > CS2D > Scripts > LUA Array -.-
Forums overviewCS2D overview Scripts overviewLog in to reply

English LUA Array -.-

4 replies
To the start Previous 1 Next To the start

old LUA Array -.-

ThePewc
User Off Offline

Quote
I dont really find any kind of good tuts for lua anywhere... So i want learn it, but i need help with 1 thing. What does this array thing does?
1
2
3
4
5
6
7
function Array(size,value)
     local array = {}
     for i = 1, size do
          array[i] = value
     end
     return array
end

old Re: LUA Array -.-

MikuAuahDark
User Off Offline

Quote
Array is mostly used on player data(for inventory, custom money, etc.)

1
2
3
4
5
6
7
8
function Array(size,value)
     local array = {}
     for i = 1, size do
          array[i] = value
     end
     return array
end
lol = Array(32,0)
just same with
1
2
lol = {}
for id = 1,32 do lol[id]=0 end
1
function Array(size,value)
Creates a function called "Array" with size and value argument
1
local array = {}
create table called "array"
1
for i = 1, size do
create loop start from 1 and end on "size"(which can be called with this, example: lol = Array(32,0))
1
array[i] = value
set table "array" on location "i"(which is a loop) to "value"(which can be called with this: lol = Array(32,0))
1
return array
return the array table

old Re: LUA Array -.-

Starkkz
Moderator Off Offline

Quote
Arrays/tables are like databases, you can store values there and use them later.

1
2
myArray = {}
myArray["AnythingIWantToPutHere"] = "I don't know what else"

Strings/number iterating is valid.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview