Vadym Mazur 5 Posted October 24, 2023 Good evening. I'm trying to call execVM for the players. Where is the mistake? fn_init.sqf { if(isPlayer _x) then { [_x] execVM "script.sqf"; }; } forEach allUnits; script.sqf _unit = (_this select 0); _unit createDiarySubject ["Hello","Everybody"]; Share this post Link to post Share on other sites
Vadym Mazur 5 Posted October 24, 2023 Don't offer to do it: { if(isPlayer _x) then { _x createDiarySubject ["Hello","Everybody"]; }; } forEach allUnits; The script run to the players upon certain players actions Share this post Link to post Share on other sites
Schatten 290 Posted October 24, 2023 3 hours ago, Vadym Mazur said: Where is the mistake? The mistake is that createDiarySubject requires local argument, therefore you need to execute this command using remoteExec. 1 Share this post Link to post Share on other sites
mrcurry 508 Posted October 24, 2023 2 hours ago, Vadym Mazur said: Good evening. I'm trying to call execVM for the players. Where is the mistake? fn_init.sqf { if(isPlayer _x) then { [_x] execVM "script.sqf"; }; } forEach allUnits; script.sqf _unit = (_this select 0); _unit createDiarySubject ["Hello","Everybody"]; 1 minute ago, Schatten said: The mistake is that createDiarySubject requires local argument, therefore you need to execute this command using remoteExec. To expand on Schatten's answer a little: A good read for understanding locality can be found in the follow link but you can save that for later: https://community.bistudio.com/wiki/Multiplayer_Scripting#Locality The main takeaway is that any multiplayer session works by multiple machines essentially running their own "version" of the events of the game. The server is master and there's a fair amount of synching for every computer to share the same state. At the same time we don't want the entire state of the game to be shared e.g. pressing Escape on one player's computer should not open the pause menu on all other players' computers. This is why script commands can have local/global arguments (denoted LA/GA respectively) and local/global effect (LE/GE). So createDiarySubject is an LE command, you can see this on the BIKI: https://community.bistudio.com/wiki/createDiarySubject That means what you are currently doing is adding the diary subject on to all players but only on the computer that executes the code, this is not synced to other computers. To send code to other computers we use remoteExec. // fn_init.sqf if( isServer ) // To avoid duplicates we make sure only machine executes the code, in this example the server { // Instead of looping and sending the request in multiple messages we send them in 1 call, more efficient use of network resorces ["Hello", "Evertbody"] remoteExec ["TAG_fnc_addDiarySubject"]; } // Instead of script.sqf make it a function, avoids compiling during runtime. // fn_addDiarySubject.sqf if( hasInterface ) then { // Filter out dedicated server and headless clients params ["_subject", "_displayName", ["_picture", ""]]; player createDiarySubject [ _subject, _displayName, _picture ]; // You could also just pass the parameters directly in but that is less readable: // player createDiarySubject _this; }; 1 Share this post Link to post Share on other sites
Vadym Mazur 5 Posted October 24, 2023 29 minutes ago, Schatten said: The mistake is that createDiarySubject requires local argument, therefore you need to execute this command using remoteExec. "script.sqf" remoteExec ["execVM",2]; ? Share this post Link to post Share on other sites
Schatten 290 Posted October 24, 2023 5 minutes ago, Vadym Mazur said: "script.sqf" remoteExec ["execVM",2]; ? No. If script.sqf is available for players, then "script.sqf" remoteExec ["execVM", allUnits select { isPlayer _x }]; 1 Share this post Link to post Share on other sites
Vadym Mazur 5 Posted October 24, 2023 16 minutes ago, mrcurry said: To expand on Schatten's answer a little: A good read for understanding locality can be found in the follow link but you can save that for later: https://community.bistudio.com/wiki/Multiplayer_Scripting#Locality The main takeaway is that any multiplayer session works by multiple machines essentially running their own "version" of the events of the game. The server is master and there's a fair amount of synching for every computer to share the same state. At the same time we don't want the entire state of the game to be shared e.g. pressing Escape on one player's computer should not open the pause menu on all other players' computers. This is why script commands can have local/global arguments (denoted LA/GA respectively) and local/global effect (LE/GE). So createDiarySubject is an LE command, you can see this on the BIKI: https://community.bistudio.com/wiki/createDiarySubject That means what you are currently doing is adding the diary subject on to all players but only on the computer that executes the code, this is not synced to other computers. To send code to other computers we use remoteExec. // fn_init.sqf if( isServer ) // To avoid duplicates we make sure only machine executes the code, in this example the server { // Instead of looping and sending the request in multiple messages we send them in 1 call, more efficient use of network resorces ["Hello", "Evertbody"] remoteExec ["TAG_fnc_addDiarySubject"]; } // Instead of script.sqf make it a function, avoids compiling during runtime. // fn_addDiarySubject.sqf if( hasInterface ) then { // Filter out dedicated server and headless clients params ["_subject", "_displayName", ["_picture", ""]]; player createDiarySubject [ _subject, _displayName, _picture ]; // You could also just pass the parameters directly in but that is less readable: // player createDiarySubject _this; }; Thank you for detailed reply Share this post Link to post Share on other sites