Forum

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

English Arrays

19 replies
To the start Previous 1 Next To the start

old Arrays

J4x
User Off Offline

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

old Re: Arrays

Yasday
User Off Offline

Quote
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.
edited 1×, last 06.02.11 02:49:35 am

old Re: Arrays

J4x
User Off Offline

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

old Re: Arrays

Yasday
User Off Offline

Quote
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.

old Re: Arrays

J4x
User Off Offline

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

old Re: Arrays

Yasday
User Off Offline

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

old Re: Arrays

Unknown_Soldier
User Off Offline

Quote
FN_Linkin Park has written
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.

old Re: Arrays

J4x
User Off Offline

Quote
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..

old Re: Arrays

Yasday
User Off Offline

Quote
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

old Re: Arrays

J4x
User Off Offline

Quote
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"
     }

old Re: Arrays

oxytamine
User Off Offline

Quote
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.
edited 1×, last 07.02.11 01:23:12 pm

old Re: Arrays

J4x
User Off Offline

Quote
Oxytamine, thats chinese for me ...

old Re: Arrays

Banaan
User Off Offline

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

old Re: Arrays

SQ
Moderator Off Offline

Quote
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.
edited 1×, last 07.02.11 11:42:56 am

old Re: Arrays

oxytamine
User Off Offline

Quote
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.

old Re: Arrays

J4x
User Off Offline

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

old Re: Arrays

Lee
Moderator Off Offline

Quote
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.

old Re: Arrays

J4x
User Off Offline

Quote
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
edited 3×, last 19.02.11 09:06:30 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview