From Bohemia Interactive Community
Revision as of 22:46, 16 May 2024 by Lou Montana (talk | contribs) (Text replacement - "{{Feature | Warning | " to "{{Feature|warning|")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Hover & click on the images for description


Arma 3
This command is deprecated since the introduction of remoteExec and remoteExecCall.

This event handler will detect if a missionNamespace variable (it is attached to) has been broadcast over network with publicVariable, publicVariableClient or publicVariableServer commands and will execute EH code upon detection. Arguments passed to the code in _this array are:

  • This EH works only in Multiplayer environment
  • There is no way to remove this EH
  • This EH will not fire on the machine that executed broadcast with publicVariable command, only on the machines that receive the broadcast
  • The value of broadcast variable can be exactly the same, it is the actual broadcast that triggers EH not the change in variable
Alt syntax of this command doesn't work as intended.
Broken CommandsEvent HandlersMultiplayerVariables


varName addPublicVariableEventHandler code
varName: String - missionNamespace variable name
code: Code - by default, the code is executed in missionNamespace
Return Value:

Alternative Syntax

varName addPublicVariableEventHandler [target, code]
varName: String - name of the variable set on target with setVariable
target: Object, Group or Team Member
code: Code
Return Value:


Example 1:
"publicThis" addPublicVariableEventHandler { hint format [ "%1 has been updated to: %2", _this select 0, _this select 1 ] };
Example 2:
"'^:)123BURP,+=lol" addPublicVariableEventHandler {hint ("NUTS are " + (_this select 1))};
missionNamespace setVariable ["'^:)123BURP,+=lol", "craZZZZy"]; publicVariable "'^:)123BURP,+=lol";

Additional Information

See also:
publicVariable publicVariableClient publicVariableServer


Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Posted on 22 Dec, 2007
Please note that varName indicates which variable you want to monitor with this eventhandler.
As a result, the example eventhandler on this page will only fire when the variable publicThis has been changed, but not if any other variable was changed by any other client via the publicVariable command.
Posted on 27 Feb, 2014 00:57
Note on using addPublicVariableEventHandler during initialization: If you need a function to call addPublicVariableEventHandler during initialization, you must use postInit. addPublicVariableEventHandler does not work during preInit.
Posted on 27 Feb, 2014 08:40
MulleDK13 note above needs some clarification. You don't "must" use postInit and you absolutely can use preInit function to initialise addPublicVariableEventHandler if you start scheduled script from it.
// script with preInit = 1; in CfgFunctions 0 spawn { "someVar" addPublicVariableEventHandler { // yourcode }; };
Posted on 2015-11-23 - 21:36 (UTC)
While it is true that the event handler will only fire on the machine receiving the broadcast value. Please note that this machine can actually be the same machine broadcasting it in the cases of publicVariableClient and publicVariableServer. Examples:
if (isServer) then { "OnServer" addPublicVariableEventHandler { hint "This event handler still fired!"; }; publicVariableServer "OnServer"; };
// This example assumes the client knows their own client ID // It does also work on the server (when the server ID is used) irrespective of the command name "OnClient" addPublicVariableEventHandler { hint "This event handler still fired!"; }; <client ID> publicVariableClient "OnClient";