global variables

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

Post Reply
bSun Lynx
CJ Wannabe
CJ Wannabe
Posts: 10
Joined: October 1st, 2011, 10:10 pm

global variables

Post by bSun Lynx » October 2nd, 2011, 3:47 am

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;
}

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: global variables

Post by IzNoGoD » October 2nd, 2011, 11:17 am

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;
}
LMGTFY!

Its not a glitch... Its the future!

bSun Lynx
CJ Wannabe
CJ Wannabe
Posts: 10
Joined: October 1st, 2011, 10:10 pm

Re: global variables

Post by bSun Lynx » October 2nd, 2011, 8:37 pm

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.

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: global variables

Post by IzNoGoD » October 2nd, 2011, 9:48 pm

Im not sure, but you better check the teams, instead of some shady .iszom var....
LMGTFY!

Its not a glitch... Its the future!

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: global variables

Post by Drofder2004 » October 3rd, 2011, 1:43 am

"level.players" is fine to use in CoD4, it is a hard-coded list of current players.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests