Page 1 of 1

global variables

Posted: October 2nd, 2011, 3:47 am
by bSun Lynx
i'm not completely sure on how the global variables work on cod, but from what i've seen it's something like;

Code: Select all

self.name = false or true;
where self = player, name = global variable name and false/true = state.
i have no clue if state can be checked like the example below:

Code: Select all

if(!self.name)
	return false;

else
	return true;
then i'm assuming must need to have it like this:

Code: Select all

if(self.name == false)
	return false;

else
	return true;
am i correct? if so, is the example given below correct aswell?

Code: Select all

get_playerscount(team)
{
	num = 0;

	for(x = 0; x < level.players.size; x++)
	{
		player = level.players[x];

		if(player.pers["team"] != "spectator")
			if(team == 1 && player.zombie == false || team == 2 && player.zombie == true)
				num++;
	}

	return num;
}
nevermind, found it myself. isDefined(); will do the trick.
also i've noticed theres no false but undefined state for bools.

Code: Select all

get_playerscount(team)
{
	num = 0;

	for(x = 0; x < level.players.size; x++)
	{
		player = level.players[x];

		if(player.pers["team"] != "spectator")
			if(team == 1 && !isDefined(player.zomb) || team == 2 && isDefined(player.zomb))
				num++;
	}

	return num;
}

Re: global variables

Posted: October 2nd, 2011, 11:17 am
by IzNoGoD
bSun Lynx wrote:i'm not completely sure on how the global variables work on cod, but from what i've seen it's something like;
self.name = false or true;
Nope, self.name is a string, like self.name="IzNoGoD"

where self = player, name = global variable name and false/true = state.
i have no clue if state can be checked like the example below:
if(!self.name)This does the same as if(self.name==false). As self.name is a string, this wont work.
return false;If you wanted to check a var that can either be true or false, just return x==y; instead of the true/false returns

else
return true;
then i'm assuming must need to have it like this:
if(self.name == false)Again, name is a string
return false;

else
return true;
am i correct? if so, is the example given below correct aswell?
get_playerscount(team)
{
num = 0;

for(x = 0; x < level.players.size; x++)Not sure about cod4, but in cod2 you have to manually get the players array by getentarray("player","classname");
{
player = level.players[x];

if(player.pers["team"] != "spectator")
if(team == 1 && player.zombie == false || team == 2 && player.zombie == true)Just check if player.pers["team"]=="allies" or "axis" instead of difficult stuff with 1/2. Also, put some brackets like this:
if((team == 1 && player.zombie == false )|| (team == 2 && player.zombie == true))
And plz, never, ever, do if(something==true), just use if(something) instead.
num++;
}

return num;
}
nevermind, found it myself. isDefined(); will do the trick.
also i've noticed theres no false but undefined state for bools.Bools are either false or true. Not setting a var as bool leaves it in the undefined state.
get_playerscount(team)
{
num = 0;

for(x = 0; x < level.players.size; x++)level.players might not be defined.
{
player = level.players[x];

if(player.pers["team"] != "spectator")
if(team == 1 && !isDefined(player.zomb) || team == 2 && isDefined(player.zomb))
num++;Same as before, just check the rest of your mod.
}

return num;
}

Re: global variables

Posted: October 2nd, 2011, 8:37 pm
by bSun Lynx
thanks for your reply, i'm glad you went step by step but with my final example given i think i got it right, except for the array of players that may be undefined at the time of the call but i don't think so, assuming i'm calling it straight from __globallogic.gsc.

Re: global variables

Posted: October 2nd, 2011, 9:48 pm
by IzNoGoD
Im not sure, but you better check the teams, instead of some shady .iszom var....

Re: global variables

Posted: October 3rd, 2011, 1:43 am
by Drofder2004
"level.players" is fine to use in CoD4, it is a hard-coded list of current players.