Forum

> > CS2D > Scripts > Arrays
Forums overviewCS2D overview Scripts overviewLog in to reply

English Arrays

4 replies
To the start Previous 1 Next To the start

old Arrays

4729
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end

intArray(10)

=

array = { 
i = 0,
i = 0,
i = 0,
i = 0,
i = 0,
i = 0,
i = 0,
i = 0,
i = 0,
i = 0
}            ?????

i don't understand

old Re: Arrays

Infinite Rain
Reviewer Off Offline

Quote
no, it's

array = {
[1] = 0,
[2] = 0,
[3] = 0,
[4] = 0,
[5] = 0,
[6] = 0,
[7] = 0,
[8] = 0,
[9] = 0,
[10] = 0,
}

old Re: Arrays

Avo
User Off Offline

Quote
1
2
3
4
5
6
7
function initArray(m,v)
	local t={}
	for i=1,m do
		t[i]=v
	end
	return t
end

is better, you can set value of table(array) index and remember that you shouldn't use array as local variable and array as global variable.

1
array=initArray(5,10)

is equal to

1
array={[1]=10,[2]=10,[3]=10,[4]=10,[5]=10}
edited 1×, last 19.07.12 05:22:02 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview