Post your scripting questions / solutions here
Moderator: Moderators
digitac
Sergeant
Posts: 58 Joined: Mon Jul 28, 2003 3:30 pm
Post
by digitac » Thu Jan 22, 2004 3:53 pm
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++
}
}
Bjarne BZR
Site Admin
Posts: 3298 Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:
Post
by Bjarne BZR » Thu Jan 22, 2004 7:10 pm
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...
Admin .MAP Forums
Head above heels.
jv_map
Site Admin
Posts: 6521 Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:
Post
by jv_map » Fri Jan 23, 2004 7:27 am
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
Bjarne BZR
Site Admin
Posts: 3298 Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:
Post
by Bjarne BZR » Fri Jan 23, 2004 10:41 am
Ehr... yes...
I guess c / C++ and a naive wish for standardization took over there.
jv is once again correct. thanx.
What the h**l was the language designer thinking?
Admin .MAP Forums
Head above heels.
jv_map
Site Admin
Posts: 6521 Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:
Post
by jv_map » Fri Jan 23, 2004 11:05 am
Well to be honest I like starting arrays at 1... it just seems more convenient
Bjarne BZR
Site Admin
Posts: 3298 Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:
Post
by Bjarne BZR » Fri Jan 23, 2004 11:23 am
I dont mind starting at 1, its starting different arrays in different ways I cant see the point of.
Admin .MAP Forums
Head above heels.