Page 1 of 1

Counting players

Posted: Thu Jan 22, 2004 3:53 pm
by digitac
How can i count my players ?

i have this but it doesn't work

Code: Select all

local.as = 0
local.al = 0
for ( local.n = 1 ; local.n <= $player.size ; local.n++ ) 
{ 
	if ( $player[local.n].dmteam == "axis" )
	{
		local.as++
	}
	else
		local.al++
	}
}

Re: Counting players

Posted: Thu Jan 22, 2004 7:10 pm
by Bjarne BZR
Try this:

Code: Select all

local.as = 0
local.al = 0
for ( local.n = 0 ; local.n < $player.size ; local.n++ ) 
{ 
	if ( $player[local.n].dmteam == "axis" )
	{
		local.as++
	}
	else
	{
		local.al++
	}
}
You forgot a bracket after 'else' and arrays start at index 0
If you looked at the console, you would probably have seen the script error printed out there ;)
Not sure if you will count spectators as allied in this way...

Re: Counting players

Posted: Fri Jan 23, 2004 7:27 am
by jv_map
Bjarne BZR wrote:You forgot a bracket after 'else' and arrays start at index 0.
Nope, not targetname arrays, they start at 1. Vector arrays and strings start indexing at 0 though :?

Posted: Fri Jan 23, 2004 10:41 am
by Bjarne BZR
Ehr... yes... :oops:
I guess c / C++ and a naive wish for standardization took over there. :oops:
jv is once again correct. thanx. :)

What the h**l was the language designer thinking? :lol:

Posted: Fri Jan 23, 2004 11:05 am
by jv_map
Well to be honest I like starting arrays at 1... it just seems more convenient :)

Posted: Fri Jan 23, 2004 11:23 am
by Bjarne BZR
I dont mind starting at 1, its starting different arrays in different ways I cant see the point of. :twisted: