Przemek_kondor 13 Posted June 17, 2008 hi how to send some values to server by every players? i tried something: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ptr_ranking = compile preprocessFile "ranking.sqf"; <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _myName = name player; _time_str = "..." variable = someNumber; _code = { [variable, _myName, _time_str] spawn ptr_ranking; }; PublicVariable "_code"; but script ranking.sqf isn't executed. where is the bug? Share this post Link to post Share on other sites
sickboy 13 Posted June 17, 2008 1. _code is a local variable, a public variable can only be a global variable (one without _) 2. After you publicVariable the code, you still must execute it.. 3. You use inexistend local variables in the _code scope. Whenever you send them over the network they will be lost I don't have much time ATM, but I just wanted to tell you about addPublicVariableEventHandler: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">ptr_ranking = compile preprocessFile "ranking.sqf"; "TST_SOMEPV" addPublicVariableEventHandler { Â _ar = (_this select 1); Â (_ar select 0) call (_ar select 1); }; <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_myName = name player; _time_str = "..." variable = someNumber; TST_SOMEPV = [ Â [variable, _myName, _time_str], Â { Â Â Â _this spawn ptr_ranking; Â }; ]; publicVariable "TST_SOMEPV"; I guess this should get you under way a lil Share this post Link to post Share on other sites
xeno 234 Posted June 17, 2008 Quote from the wiki: Quote[/b] ]The only limitation is you cannot transfer references to entities which are local, like scripts, displays, or local objects. A script handle is local on each client and on the server. A better way is it to send an array and let a publicVariable eventhandler react to it. Receiver part: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> "my_array" addPublicVariableEventhandler { my_array spawn ptr_ranking; }; Sender: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> my_var = [someNumber,name player,_time_str]; publicVariable "my_var"; Xeno Share this post Link to post Share on other sites
sickboy 13 Posted June 17, 2008 "my_array" addPublicVariableEventhandler { Â my_array spawn ptr_ranking; }; I would recommend always using (_this select 1) Â instead of the variable name, inside the publicVariableEventHandler. Because it will contain the value that my_array was at the moment of triggering the PVEH. Not that i've seen it happen, but My_array could actually have been changed between the PV Trigger, and the Execution. However, the implementation is done better than mine, as mine is more a general remote execution handler, and yours is a specific one for this situation Share this post Link to post Share on other sites
Przemek_kondor 13 Posted June 17, 2008 thnx, I havent noticed that publicVariable can publics arrays too. but addPublicVariableEventhandler seems not works (tested on dedicated server 1.14), when init.sqf: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ... ptr_ranking = compile preprocessFile "ranking.sqf"; RankingUpdater = []; RankingUpdater addPublicVariableEventHandler { ( _this select 1 ) spawn ptr_ranking; }; ... moment of the updating: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ... while(...)do{ ... num_of_laps = ... _player_and_time_string = ... RankingUpdater = [num_of_laps, _player_and_time_string]; PublicVariable "RankingUpdater"; ... }; ... and script ranking.sqf isn't called Share this post Link to post Share on other sites
5133p39 14 Posted June 17, 2008 thnx, I havent noticed that publicVariable can publics arrays too.but addPublicVariableEventhandler seems not works (tested on dedicated server 1.14) because <span style='color:blue'>RankingUpdater addPublicVariableEventHandler</span> is not the same like <span style='color:blue'>"RankingUpdater" addPublicVariableEventHandler</span>. And one more thing - the event handler will NOT be executed on computers where you executed the <span style='color:blue'>publicVariable</span> command. So if you are testing this by playing singleplayer mission, or by playing MP mission but in local network and hosting the mission on your own computer (your computer is the server, but also one and only client), it will not work for you. You still need to execute the SQF script manually on the computer where you are using the <span style='color:blue'>publicVariable</span> command. Share this post Link to post Share on other sites
Przemek_kondor 13 Posted June 17, 2008 thanx 5133p39. I found 2 minute ago this bug too I will test it soon [edit:]it works Share this post Link to post Share on other sites