Forum

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

Englisch Arrays

19 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Arrays

J4x
User Off Offline

Zitieren
Hi guys, can someone explain me what is an array, and for what i use it? Thanks for the amswers.

alt Re: Arrays

Yasday
User Off Offline

Zitieren
An array is used to store multiple data. Like money for every player on the server, so you won't need 32 variables for 32 players. Let's say it's just a table.
1× editiert, zuletzt 06.02.11 02:49:35

alt Re: Arrays

J4x
User Off Offline

Zitieren
Can u give me a example? Thanks for the answer.

alt Re: Arrays

Yasday
User Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function array_of_money()
	local tbl = {}
	for pl = 1,32 do
		if player(pl,"exists") then
			tbl[pl] = player(pl,"money")
		else
			tbl[pl] = 0
		end
	end
	return tbl
end

money = array_of_money()

money[1] = money of the first player
...
An array is a table.

alt Re: Arrays

J4x
User Off Offline

Zitieren
I dont want to be anoying but can u explain what si a table.. lol.

alt Re: Arrays

Yasday
User Off Offline

Zitieren
Well.. this
1
me = 1
isn't a table, but this
1
me = {[1] = 1}
is a table.

alt Re: Arrays

Unknown_Soldier
User Off Offline

Zitieren
FN_Linkin Park hat geschrieben
I dont want to be anoying but can u explain what si a table.. lol.


The table is an array, and that is like a variable, but it stores more than 1 value, to create an empty table, you need this

1
name = {}

you can write the values by yourself by 2 ways

1
name = {25,12,6,4}

that is like I write

1
2
3
4
name[1] = 25
name[2] = 12
name[3] = 6
name[4] = 4

this is usefull to make a variable to every player in the server, like money, lives, HP, armor, etc.

alt Re: Arrays

J4x
User Off Offline

Zitieren
let me see if i understand, i write this
1
2
3
4
Health[1] = 100
Health[2] = 120
Health[3] = 107
Health[4] = 400
But i still dont understand for what i use tables..

alt Re: Arrays

Yasday
User Off Offline

Zitieren
You use tables because you don't want to make 100 variables if you can use 1 table.
1
2
3
4
variable1 = 1
variable2 = 2
...
variable100 = 100

1
2
3
4
5
table = {}

for i = 1,100 do
	table[i] = i
end

alt Re: Arrays

J4x
User Off Offline

Zitieren
oh, i think i understand. so this is a table :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
TileMaterial = {
     [0] = "Soundless",
     [1] = "Wall",
     [2] = "Obstacle",
     [3] = "Wall (No Shadow)",
     [4] = "Obstacle (No Shadow)",
     [10] = "Dirt",
     [11] = "Snow",
     [12] = "Step",
     [13] = "Tile",
     [14] = "Water",
     [15] = "Metal",
     [16] = "Wood",
     [50] = "Deadly - Normal",
     [51] = "Deadly - Explosion",
     [52] = "Deadly - Toxic",
     [53] = "Deadly - Abyss"
     }

alt Re: Arrays

oxytamine
User Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
program test; uses crt;
var
X:array [1..5] of integer; 
i:byte;
begin
clrscr;
for i:=1 to 5 do 
read (X[i]);
end.
1× editiert, zuletzt 07.02.11 13:23:12

alt Re: Arrays

J4x
User Off Offline

Zitieren
Oxytamine, thats chinese for me ...

alt Re: Arrays

Banaan
User Off Offline

Zitieren
That's because it isn't Lua and therefore pretty useless here. I think it's Pascal, ain't it?

alt Re: Arrays

SQ
Moderator Off Offline

Zitieren
It is Pascal.
Crt lib is pretty useless there.

1
2
3
4
5
6
7
8
program Test;
var X : Array[1..5] of Char;
	Y : Byte;
begin
	for Y := 1 to 5 do X[Y] := Char(Random(255));
	for Y := 1 to 5 do WriteLn(X[Y]);
	ReadLn;
end.
1× editiert, zuletzt 07.02.11 11:42:56

alt Re: Arrays

oxytamine
User Off Offline

Zitieren
BlazingEyed, I usually use crt library just to clean screen. So I just put it in every TP7 program I make, even if it's example like I gave him.

alt Re: Arrays

J4x
User Off Offline

Zitieren
Well, can some one explain me what does
1
initArray(32)
means?

alt Re: Arrays

Lee
Moderator Off Offline

Zitieren
It creates a table with 32 indices (1 to 32) and fills them with 0. In most cases you do not need them, it was carried over from expectations I had from other programming languages.

alt Re: Arrays

J4x
User Off Offline

Zitieren
Thanks

Edit: is this correct:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
----------------------------------------
--- Effects script by FN_Nemesis 
--- for more info visit: Unrealsoftware.de
--- Date: 11/2/2011
----------------------------------------
Weapon tables = {
[Machinegun] = "40",
[rifles] = "30,31,32,33,38,39",
[snipers] = "34,35,36,37",
[pistols] = "1,2,3,4,5,6",
[Smg] = "20,21,22,23,24",
[Shotguns] = "10,11"}

addhook("attack","shake")
function shake(id)
if wpn == Machinegun then
parse("shake "..id.." 8")
end
end

addhook("attack","shake2")
function shake2(id)
if wpn == rifles then
parse("shake "..id.." 3")
end
end


addhook("attack","shake3")
function shake3(id)
if wpn == snipers then
parse("shake "..id.." 5")
end
end


addhook("attack","shake4")
function shake4(id)
if wpn == pistols then
parse("shake "..id.." 2")
end
end

addhook("attack","shake5")
function shake5(id)
if wpn == Smg then
parse("shake "..id.." 6")
end
end

addhook("attack","shake6")
function shake6(id)
if wpn == Shotguns then
parse("shake "..id.." 4")
end
end

addhook("hit","shake7")
function shake7(id)
parse("shake "..id.." 10")
end
3× editiert, zuletzt 19.02.11 21:06:30
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht