addPublicVariableEventHandler: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "\<dt class\=\"note\"\>\'\'\'\[\[(.*)\]\]\'\'\'" to "<dt class="note">$1") |
Lou Montana (talk | contribs) m (Text replacement - "[[Category:Scripting Commands ArmA|" to "[[Category:Scripting Commands Armed Assault|") |
||
Line 87: | Line 87: | ||
[[Category:Command_Group:_Multiplayer|{{uc:{{PAGENAME}}}}]] | [[Category:Command_Group:_Multiplayer|{{uc:{{PAGENAME}}}}]] | ||
[[Category:Scripting Commands|ADDPUBLICVARIABLEEVENTHANDLER]] | [[Category:Scripting Commands|ADDPUBLICVARIABLEEVENTHANDLER]] | ||
[[Category:Scripting Commands | [[Category:Scripting Commands Armed Assault|ADDPUBLICVARIABLEEVENTHANDLER]] | ||
[[Category:Scripting Commands Arma 2|{{uc:{{PAGENAME}}}}]] | [[Category:Scripting Commands Arma 2|{{uc:{{PAGENAME}}}}]] | ||
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]] | [[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]] |
Revision as of 16:43, 3 June 2020
Description
- Description:
- 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 select 0: String - broadcast variable name (same variable name EH is attached to)
_this select 1: Anything - broadcast variable value
_this select 2: Object, Group - target the variable got set on with setVariable (see: alternative syntax)
- Groups:
- Uncategorised
Syntax
- Syntax:
- varName addPublicVariableEventHandler code
- Parameters:
- varName: String - missionNamespace variable name
- code: Code - By default, the code is executed in missionNamespace
- Return Value:
- Nothing
Alternative Syntax
- Syntax:
- varName addPublicVariableEventHandler [target, code] (since A3 1.46)
- Parameters:
- varName: String - name of the variable set on target with setVariable
- [target, code]: Array
- target: Object, Group or Team Member
- code: Code
- Return Value:
- Nothing
Examples
- Example 1:
"publicThis" addPublicVariableEventHandler { hint format [ "%1 has been updated to: %2", _this select 0, _this select 1 ] };
- Example 2:
- Client:
"'^:)123BURP,+=lol" addPublicVariableEventHandler {hint ("NUTS are " + (_this select 1))};
Server:missionNamespace setVariable ["'^:)123BURP,+=lol", "craZZZZy"]; publicVariable "'^:)123BURP,+=lol";
Additional Information
Notes
-
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
Notes
- Posted on 22 Dec, 2007
- TeRp
-
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
- MulleDK13
- 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
- Killzone_Kid
-
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 = 0 spawn { "someVar" addPublicVariableEventHandler { //yourcode }; };
Bottom Section
- Posted on November 23, 2015 - 21:36 (UTC)
- SilentSpike
-
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";
Categories:
- Scripting Commands
- Introduced with Arma version 1.09
- Arma: New Scripting Commands
- Arma: Scripting Commands
- Command Group: Uncategorised
- Scripting Commands: Local Effect
- Command Group: Multiplayer
- Scripting Commands Armed Assault
- Scripting Commands Arma 2
- Scripting Commands Arma 3
- Scripting Commands Take On Helicopters
- Broken Scripting Commands