{"name":"publicVariable","operator":null,"title":"publicVariable","type":"command","url":"https://community.bistudio.com/wiki/publicVariable","revid":343848,"updated":"2023-07-26T14:57:01Z","groups":["Multiplayer","Variables"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.34"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.34"},"arma3_since":"0.50","branch":null,"locality":{"argument":"local","effect":"global","server_exec":false},"exec":null,"description":"Reliably broadcasts missionNamespace variable and its **current** value to all computers (server/client).\n\nVariables broadcast with publicVariable during a mission will be available to JIP clients with the value they held at the time.\n\nSuch variables are persistent and sent to the JIP client before the first batch of client-side Event Scripts (such as init.sqf) is run.\n\n> [!IMPORTANT]\n> Using publicVariable too frequently and/or with a lot of data can cause other aspects of the game to experience bandwidth problems.\n\nThe following Data Types are supported:\n\n|  |  |  |  |  |  |  |  |  |  |  |\n|---|---|---|---|---|---|---|---|---|---|---|\n| Type | Number | Boolean | Object | Group | String | Text | Array | Code | Nothing (nil) | HashMap |\n| Since | Operation Flashpoint v1.34 | Armed Assault v1.00 | Armed Assault v1.09 | Arma 3 v1.26 | Arma 3 v2.02 |  |  |  |  |  |\n\n> [!IMPORTANT]\n> It is not possible (and illogical) to transfer a local entity reference, such as scripts, displays or local objects.\n>\n> Also, note that Team Member is not supported.","syntaxes":[{"syntax":"publicVariable varName","since":null,"effect":null,"exec":null,"params":[{"name":"varName","type":"String","optional":false,"default":null,"description":"the global variable's Identifier","types":["String"],"since":null,"text":"varName: String - the global variable's Identifier"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"unary","operator":null,"left":null,"right":{"text":"varName","types":["String"]}}],"examples":[{"text":"```sqf\nTAG_MyPublicVariable = 0;\nTAG_MyPublicVariable = 1;\npublicVariable \"TAG_MyPublicVariable\";    // other clients will receive the \"TAG_MyPublicVariable\" variable with a 1 value\n\nTAG_MyPublicVariable = 2;                // needs to be broadcast again - synchronisation is not automatic\n```","code":["TAG_MyPublicVariable = 0;\nTAG_MyPublicVariable = 1;\npublicVariable \"TAG_MyPublicVariable\";\t// other clients will receive the \"TAG_MyPublicVariable\" variable with a 1 value\n\nTAG_MyPublicVariable = 2;\t\t\t\t// needs to be broadcast again - synchronisation is not automatic"]},{"text":"JIP example:\n\n```sqf\nif (isNil \"TAG_CurrentTarget\") then    // has the variable already been set and broadcast?\n{\n    TAG_CurrentTarget = objNull;    // if not, set it on the local machine\n};\n\nplayer doTarget TAG_CurrentTarget;\n```","code":["if (isNil \"TAG_CurrentTarget\") then\t// has the variable already been set and broadcast?\n{\n\tTAG_CurrentTarget = objNull;\t// if not, set it on the local machine\n};\n\nplayer doTarget TAG_CurrentTarget;"]},{"text":"```sqf\nTAG_BossName = \"EvilBigBoss\";\n\npublicVariable TAG_BossName;    // wrong - will try to publicVariable \"EvilBigBoss\" variable, that does not exist\npublicVariable \"TAG_BossName\";    // correct - important, do not forget the QUOTES\n```","code":["TAG_BossName = \"EvilBigBoss\";\n\npublicVariable TAG_BossName;\t// wrong - will try to publicVariable \"EvilBigBoss\" variable, that does not exist\npublicVariable \"TAG_BossName\";\t// correct - important, do not forget the QUOTES"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["Multiplayer Scripting","Initialisation Order","addPublicVariableEventHandler","publicVariableClient","publicVariableServer","Variables","Event Scripts"],"notes":[],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Multiplayer","Command Group: Variables","Introduced with Operation Flashpoint version 1.34","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Scripting Commands: Global Effect","Take On Helicopters: Scripting Commands"]}