Jump to content
Sign in to follow this  
mikie boy

gloabalvariables updating and JIP

Recommended Posts

Having problems with JIP and multiplayer in relation to globalvariables.

In short I have the globalvariable of terrorcontrol that I wish to add to and subtract from in order for certain things to happen. I want to have the same value for everyone in game and JIP.

This is set in init.sqf to

terrorcontrol = o;

So on joining mp game – this is set to 0.

I then carry out an action which spawns (using addPublicVariableEventHandler) a marker and creates 8 civs.

During the spawning of the 8 civs I add 1 to the terrorcontrol globalvariable.

this is done by

terrorcontrol = terrorcontrol + 1;

Thus at this point

terrorcontrol = 8;

When I leave the game and come back in obviously the init.sqf is executed and terrorcontrol is set back to 0. And when I call the action to spawn the 8 civs it should say they are already spawned, but instead it spawns 8 more – most likely due to init setting it to 0.

Ive looked at http://community.bistudio.com/wiki/publicVariable but not sure how this works with variables as above.

If changed init to…

If (isserver) then 
{
terrorcontrol = 0;
};

But this will not activate the script – as the script cant find a value for terrorcontrol.

And ive tried adding 1 to terrorcontrol within the script via the if isserver line again doesn’t work

My question therefore is how do I get terrorcontrol to stay the same across the board for everyone.

Ive tried using addPublicVariableEventHandler for adding 1 to the globalvariable, but to behonest I couldn’t work it out.

I looked at http://forums.bistudio.com/showthread.php?t=119114&highlight=globalvariable and the last comment is useful but again not sure how to go about that.

That’s it im stuck – any help would be appreciated – any further explanation of my waffling i will be happy to update.

Share this post


Link to post
Share on other sites

It is hard to diagnose without seeing more of your code. In addition to the pv eventhandler, are you also using thr publicVariable command to broadcast it to all machines?

Share this post


Link to post
Share on other sites

How would i broadcast

terrorcontrol = terrorcontrol + 1;

or

terrorcontrol = terrorcontrol - 1;

when i tried it - it was calling an array. - shown below - which seems right for an array - not sure how i would call it for the variable addition and subtraction.

this is the initial script i ran to create the 8 civs and this is what i added.

loop creates 8 civs and each time adding 1 to terrorcontrol as shown below.



_addterrorcontrol = "terrorcontrol";
	if (isServer) then 
			{						
			terrorcontrol = terrorcontrol + 1; 
			} 	
			else 
			{
			terrorcontrol = [_addterrorcontrol, 1];publicVariable "terrorcontrol"; 
			};

init.sqf

if (isServer) then 
{
"terrorcontrol" addPublicVariableEventHandler 
{
	((_this select 1) select 0) + ((_this select 1) select 1);
};
};

if this doesnt help i can post the scripts

cheers

Share this post


Link to post
Share on other sites

//init.sqf
if (isNil "terrorcontrol") then
{
terrorcontrol = 0;
};

Exactly as suggested above and when you create the civs

terrorcontrol = terrorcontrol + 1;
publicVariable "terrorcontrol";

Share this post


Link to post
Share on other sites

right - sort of got my head round it,

thanks chaps for the help - ill test it in the morning

Share this post


Link to post
Share on other sites

yeah worked well - cheers for that chaps - appears the below code works well

terrorcontrol = terrorcontrol + 1; 
publicVariable "terrorcontrol";  

handy tool to understand in MP - found several other things that require its assistance.

Share this post


Link to post
Share on other sites
yeah worked well - cheers for that chaps

no worries fella - and make sure you check out that link sickboy posted its a great starting place for working out multiplayer locality.

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  

×