Jump to content
Sign in to follow this  
alleycat

publicVariableClient confusion

Recommended Posts

Was trying to send data from server to a client and got stuck

On server(happens in OnPlayerConnected):

			_owner = owner _x;
		diag_log format ["owner: %1", _owner];
		Data1 = "lol";


		//Send string to client
		_owner publicVariableClient "Data1";

Client init.sqf

if (local player) then {
diag_log text "1";
Data1 = nil;
diag_log text "2";


while {isNil("Data1")} do {
diag_log text "3";
//wait for the server to send
};	
diag_log text "4";

_datatest = Data1;
diag_log text format["_datatest %1", _datatest];

It never gets out of the while loop. Is there something I need to to do for a client to "catch" that the server actually sent the variable over? I assume the client is notified of this with:

_owner publicVariableClient "Data1";

Share this post


Link to post
Share on other sites

On player connected probably happens a lot earlier than the client's init.sqf. So data1 is actually overwritten in the init.sqf, and goes from "lol" to nothing, not the other way around.

Share this post


Link to post
Share on other sites

I may see your problem. Change onPlayerConnected to:

diag_log format ["::SERV:: Player %1 Connected - SessionID: %2 - PlayerID %3",_name,_id,_uid];
Data1 = "lol";

//Send string to client
_id publicVariableClient "Data1";

onPlayerConnected basically passes three variables.

_id = sessionID

_name = name of the client connected

_uid = his playerID / Unique ID.

Those three variables are what you would use in onPlayerConnected. the _id / sessionID is pretty much the same as what you would get from owner _object. It will return their current sessionID in the game. This is of course in theory.

Share this post


Link to post
Share on other sites

I solved the issue by using CBA eventhandlers inside in the init. The original problem was likely that the variables are sent long before the init started so they got lost.

Basically like this:

Init--->Call CBA eventhandler--->Makes server send the variable--->Wait on client in a while loop until the variable arrives

(Most of this is shown in the example mission of the SQL Plugin made by fire)

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  

×