Forum

> > CS2D > Scripts > Arrays
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Arrays

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Arrays

4729
User Off Offline

Zitieren
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

alt Re: Arrays

Infinite Rain
Reviewer Off Offline

Zitieren
no, it's

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

alt Re: Arrays

Avo
User Off Offline

Zitieren
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}
1× editiert, zuletzt 19.07.12 17:22:02
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht