Jump to content
Sign in to follow this  
rakowozz

Need Help With define vs. Global Variable vs. JIP

Recommended Posts

Hey, guys. I wasn't even sure what to name this thread! But here goes the dilemma.

I have something like this set up to avoid undefined variables over empty player slots:

{
if (isNil _x) then 
{
	missionNamespace setVariable [_x, objNull];
};
} 
forEach ["player1","player2","player3","player4","player5","player6"];

Which always worked fine, we're not at the problem yet. I often need to differentiate units (which are NOT necessarily in the same groups), which could be done like this:

team1 = [player1,player2,player3];
team2 = [player4,player5,player6];

Having to declare the arrays for all playable units every time would look terrible. Imagine "if [player1,player2,...,player30], etc.,etc." every few lines.

So then I'd use team1/team2 in all sqfs. But when player2, which wasn't there at the beginning and is JIP, joins the mission, team1 will remain:

[player1,<NULL-Object>,player3]

Even though

player2 == player2

everywhere.

So, I started using defines. Having

#define team1 [player1,player2,player3]
#define team2 [player4,player5,player6]

Good. But after a certain condition, the missions requires team1 to become:

[player1,player2,player3,player4,player5,player6]

Which brings me back the convenience of using the global variables. So, I guess the problem here really is about the JIP players remaining as objNull to the server.

So, am I overcomplicating this, or is there a reasonable alternative to avoid using if/then EVERYWHERE to check for that condition, so it'll use one define or another? And without having to update the arrays, as I'd need them to be updated in very short intervals?

Thanks in advance, let me know what part I did overcomplicate :p

Edited by rakowozz

Share this post


Link to post
Share on other sites

I use pretty close to the same code in init.sqf onplayerconnect and disconnect to update my arrays, doing it anywhere else is a waste of time.

Share this post


Link to post
Share on other sites

Hmm, yeah, makes sense. I created a function to update the arrays according to the conditions. Now I'm calling it from a script that runs on JIP players (instead of onPlayerConnected) and from onPlayerDisconnected with BIS_fnc_MP - non-persistent. That should do it, I guess. Off to test it some thousand times now.

Thanks for replying!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×