SRL Archive - Help and Support

Total all of players[X].integers[P_AMOUNT]


YoHoJo

2011-03-11 16:08:48

How would I easily total
players[X].integers[P_AMOUNT]
for all of my players?

Need it for a progress report.

Gu3st...

2011-03-11 16:31:32

var
I, total : Integer;
begin
for I := 0 to HowManyPlayers -1 do
total := total + players.integers[blah];
writeln(inttostr(total));
end;

YoHoJo

2011-03-11 17:20:00

Yeah that's how I was thinking about doing it too, simple, thanks!

EvilChicken!

2011-03-12 03:56:43

Even better, use IncEx. ;)

YoHoJo

2011-03-12 04:11:43

From: EvilChicken!
Even better, use IncEx. ;)


How so?

EvilChicken!

2011-03-12 04:25:22

From: YoHoJo
How so?


It was more meant jokingly, although I must admit preferring Inc and IncEx over the alternatives because I think they're slightly easier on the eyes. Some even say they're faster, but the difference is insignificant for real usage.

Gu3st...

2011-03-12 08:15:33

From: EvilChicken!
It was more meant jokingly, although I must admit preferring Inc and IncEx over the alternatives because I think they're slightly easier on the eyes. Some even say they're faster, but the difference is insignificant for real usage.
Inc(I) is faster than I := I + 1; but IncEx(I, 1) is slower than both I := I + 1; and Inc()

E: Proof:
var
t, I, C : Integer;
begin
t := GetSystemTime;
for I := 1 to $ffff do
Inc(C);
WriteLn('Inc: ' + IntToStr(GetSystemTime-t));
t := GetSystemTime;
for I := 1 to $ffff do
C := C + 1;
WriteLn('C+1: ' + IntToStr(GetSystemTime-t));
t := GetSystemTime;
for I := 1 to $ffff do
C := C + 50;
WriteLn('C+50: ' + IntToStr(GetSystemTime-t));
t := GetSystemTime;
for I := 1 to $ffff do
IncEx(C, 1);
WriteLn('IncEx1: ' + IntToStr(GetSystemTime-t));
t := GetSystemTime;
for I := 1 to $ffff do
IncEx(C, 50);
WriteLn('IncEx50: ' + IntToStr(GetSystemTime-t));
end.
Compiled succesfully in 31 ms.
Inc: 172
C+1: 187
C+50: 187
IncEx1: 359
IncEx50: 358
Successfully executed.

Home

2011-03-12 08:27:51

var
I, total: Integer;
begin
for I := 0 to GetArrayLength(Players) - 1 do
total := total + players[I].integers[blah];
writeln(inttostr(total));
end;



~Home

EvilChicken!

2011-03-12 08:32:05

From: Home
var
I, total: Integer;
begin
for I := 0 to GetArrayLength(Players) - 1 do
total := total + players[I].integers[blah];
writeln(inttostr(total));
end;



~Home


That's exactly what Zy aswered with, but wrapped in SIMBA tags..?

Floor66

2011-03-12 10:55:22

Guess he didn't read the whole thread :P

Gu3st...

2011-03-12 10:55:45

From: EvilChicken!
That's exactly what Zy aswered with, but wrapped in SIMBA tags..?
<3 :)

YoHoJo

2011-03-12 13:56:21

From: EvilChicken!
That's exactly what Zy aswered with, but wrapped in SIMBA tags..?


I like Homes better, it's standardized and has Simba tags

Gu3st...

2011-03-12 22:56:42

From: YoHoJo
I like Homes better, it's standardized and has Simba tags
Lol'd :p
I'm just lazy.

E: Mine's standardized too, it just doesn't show because I don't use Simba tags ;) + I use HowManyPlayers which is both faster and better practice than Home's GetArrayLength(Players);, and GetArrayLength() is actually wrong. You should always use SetLength/Length and not SetArrayLength/GetArrayLength (There's some bug somewhere in those functions… Check mantis if you care)