Icaruk 14 Posted April 25, 2014 (edited) Hi, I have a problem about variables and multiplayer, here is my example: init.sqf publicVariable "A","points"; _null = [] execVM "engine.sqf"; engine.sqf if (isServer) then { A = 0; publicVariable "A"; points = 0; publicVariable "points"; }; if (isServer) then { while {true} do { if (A == 1) then { points = points +1; sleep 1; } Okay, the problem is when player1 has points = 10, maybe player2 has points = 8 Any solutions to this? Thanks Edited April 26, 2014 by Icaruk Share this post Link to post Share on other sites
Johnson11B2P 3 Posted April 26, 2014 Question are the players on the server at the same time? Share this post Link to post Share on other sites
Icaruk 14 Posted April 26, 2014 Question are the players on the server at the same time? Yes, imagine a sector control, with players capturing the base A, and getting points each seconds for it. Share this post Link to post Share on other sites
champ-1 40 Posted April 26, 2014 Are you trying to make different variables with the same name? You can use setVariable command on player or some other objects. Share this post Link to post Share on other sites
Icaruk 14 Posted April 26, 2014 Are you trying to make different variables with the same name?You can use setVariable command on player or some other objects. When a player captures a base via trigger, A = 1. So, if A == 1, points will get a +1 each second. There are 2 different variables. Share this post Link to post Share on other sites
champ-1 40 Posted April 26, 2014 if (A == 1) then { points = points +1; publicVariable "points"; sleep 1; } I think you need to broadcast this value over network every time. Share this post Link to post Share on other sites
Icaruk 14 Posted April 26, 2014 if (A == 1) then { points = points +1; publicVariable "points"; sleep 1; } I think you need to broadcast this value over network every time. This: if (isServer) then { while {true} do { if (A == 1) then { points = points +1; sleep 1; } works nice, the problem is that at some point of the game, some players will have 1000 points, and others will have 1200 others 800 others 1100... Share this post Link to post Share on other sites
champ-1 40 Posted April 26, 2014 Command "publicVariable" broadcasts current value of given variable over the network. In this loop you get variable "points" and add 1 point to it. But this variable has old value and haven't been synced with other players. That's why you need to broadcast it every time or at least sometimes. Share this post Link to post Share on other sites
Icaruk 14 Posted April 26, 2014 Command "publicVariable" broadcasts current value of given variable over the network. In this loop you get variable "points" and add 1 point to it. But this variable has old value and haven't been synced with other players. That's why you need to broadcast it every time or at least sometimes. So It would be like this? init.sqf publicVariable "A","points"; _null = [] execVM "engine.sqf"; engine.sqf if (isServer) then { while {true} do { if (A == 1) then { points = points +1; publicVariable "points"; sleep 1; } What about this? init.sqf publicVariableServer "A","points"; _null = [] execVM "engine.sqf"; Share this post Link to post Share on other sites
Johnson11B2P 3 Posted April 28, 2014 Using publicVariableServer you are telling the server to keep track of the updates for the variable and no client will receive the updated variable information. Using publicVariable after the variable on the server has been updated is the right way to go. But caution must be used when using the publicVariable frequently. It can severely lag other parts of the game. How often is A going to be 1? Maybe a point for every 3 seconds a player is in the sector? Share this post Link to post Share on other sites
Icaruk 14 Posted April 28, 2014 Using publicVariableServer you are telling the server to keep track of the updates for the variable and no client will receive the updated variable information. Using publicVariable after the variable on the server has been updated is the right way to go. But caution must be used when using the publicVariable frequently. It can severely lag other parts of the game. How often is A going to be 1? Maybe a point for every 3 seconds a player is in the sector? This is my script atm: if (isServer) then { A = 0; publicVariable "A"; B = 0; publicVariable "B"; pointsBLU = 0; publicVariable "pointsBLU"; pointsRED = 0; publicVariable "pointsRED"; }; while {true} do { call compile preprocessFileLineNumbers "scripts\hud\hud_update.sqf"; if (A == 1) then { pointsBLU = pointsBLU + 1; publicVariable "pointsBLU"; "amrk" setMarkerColor "ColorBlue"; }; if (A == 2) then { pointsRED = pointsBLU + 1; publicVariable "pointsRED"; "amrk" setMarkerColor "ColorRed"; }; if (B == 1) then { pointsBLU = pointsBLU + 1; publicVariable "pointsBLU"; "bmrk" setMarkerColor "ColorBlue"; }; if (B == 2) then { pointsRED = pointsBLU + 1; publicVariable "pointsRED"; "bmrk" setMarkerColor "ColorRed"; }; }; sleep 1; }; A = 1 means that this base is blue, A = 2 means that this base is red, same with B. So they will just change when a team can capture the base. BTW is possible to put just the end of the script like this? }; }; publicVariable "pointsBLU"; publicVariable "pointsRED"; sleep 1; }; Share this post Link to post Share on other sites