Jump to content

[TUTORIAL] How to use Public Variables


Recommended Posts

just for shits and giggles, can you declare a clientside PVEH just to spit out some text?

// Clientside PVEH (init this in your mission.pbo)
if (!isDedicated) then {
	// expects []
	"PVEH_PlaySoundClient" addPublicVariableEventHandler {
		systemChat "We got our PVEH";
	};
};

try placing that in your init.sqf along with your server side one.  maybe declare this one first.

Link to comment
Share on other sites

Late to the party as usual but just a couple of suggestions on the code.

 

In the _playersToSend loop, count is faster than forEach if you don't need to use the _forEachIndex special variable in the loop code.

 

nearentities is also faster than nearestObjects.

 

if (isPlayer _x) then {}; will detect if the player is a human player.

 

Hope this helps.

Link to comment
Share on other sites

Doesn't count only give a number, where as foreach allows code to be run on each?

 

Nope.

 

Both iterate through an array and use _x as the current array element inside the loop.

 

forEach allows a second special variable called _forEachIndex which contains the index of the current array element in the loop.  Count does not have this special vairiable but runs faster.  If you do not use this second special variable then they are both interchangable.

Link to comment
Share on other sites

  • 10 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...