Jump to content
56Curious

getVariable for first time connecting players [Solved]

Recommended Posts

Hello,

 

I have a question about the getVariable command.

when a player first connects, they need to run a welcome-esque script before being assigned a variable for them to skip this for future connects. So I have it working if you assign the variable to profileNamespace, obviously, but then comparing it to something that isn't there means it doesn't work. I understand this, it makes sense.

However how am I supposed to detect if a player has has a variable there or not? (I'm probably missing something here).

 

So for example (quick mockup)

inside say, the initPlayerLocal I could have...

	switch (profileNamespace getVariable "ReturningPlayer") do {

		case true:		{
		0 = execVM "someFileForReturningPlayers";
		};
		case false:		{
		scopeName "Failsafe";
		0 = execVM "someFileForNewPlayers";
	    profileNamespace setVariable ["ReturningPlayer",true];
	    saveProfileNamespace;
		};
		default {breakTo "Failsafe"; hint "Breaking to failsafe";};
	};

using default as the fallthrough as it's ran if nothing is there, however this wont work. Tried If else as well but I couldn't get this working.


Help is appreciated :)

 

Fixed with a isNil inside the condition.

Share this post


Link to post
Share on other sites
10 hours ago, 56Curious said:

switch (profileNamespace getVariable "ReturningPlayer") do {

Even though it works, this kind of scripting is not good practice. The variable name is way too general and might get overwritten by another mission or mod. Simply solve this by butting a tag before your global and persistent variables, eg TAG_returningPlayer.

Also I, personally, am not a big fan of the profileNamespace variables as it crowds the user's namespace (try count allVariables profileNamespace and see what I mean...). IMHO the better solution would work something like this:

// initPlayerServer.sqf
params["_player","_didJIP"];
_playerServerHistory = profileNamespace getVariable ["TAG_playerServerHistory",[]]; //get variable from the server/hosting client
_playerUID = getPlayerUID _player;// get the unique player ID
if (_playerUID in _playerServerHistory) then { //is player in the UID array?
	// already joined the server at least once
	0 = execVM "someFileForReturningPlayers";
} else {
	0 = execVM "someFileForNewPlayers";
	_playerServerHistory pushBackUnique _playerUID;// add the uid to the local array
    profileNamespace setVariable ["TAG_playerServerHistory",_playerServerHistory];// update the persistent array
};

The main advantage is that you won't have to rely on the client to keep his profileNamespace (in case he wipes it with eg ({profileNamespace setVariable [_x,nil];} forEach (allVariables profileNamespace);). With this script you are also able to wipe the server history if needed so everyone gets to see the intro again. The only place where the varaible is stored is the server's/host's profileNamespace. Be aware that the script is running locally to the server/host so any client sided commands will have to be remoteExec'ed.

On the other hand the array will not be transferred to other hosts or servers so if your mission is running on multiple servers then the intro will be played each time you join a new server.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you for the information!

I completly forgot about Tags on my global stuff ahah, silly me.

I also see what you mean about crowding the profileNamespace too lol.

 

Will integrate this as it seems to run smoother anyhow and less work for the client, would you like a credit and such or...?

  • Like 1

Share this post


Link to post
Share on other sites

Oh no need to credit me ;) I am happy to help ^^

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

No credit, just send the money... :rofl::happy:

  • Haha 3

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

×