addPublicVariableEventHandler: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - ">Posted on November ([0-9]{2})[ a-zA-Z]*, ([0-9]{4})" to ">Posted on $2-11-$1") |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 28: | Line 28: | ||
|gr4= Variables | |gr4= Variables | ||
|descr= {{Feature|arma3 | This command is deprecated since the introduction of [[remoteExec]] and [[remoteExecCall]].}} | |descr= {{Feature|arma3|This command is deprecated since {{GVI|arma3|1.52}} and 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 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 0: [[String]] - broadcast variable name (same variable name EH is attached to) | ||
* _this select 1: [[Anything]] - broadcast variable value | * _this select 1: [[Anything]] - broadcast variable value | ||
* _this select 2: [[Object]], [[Group]] - target the variable got set on with [[setVariable]] | * _this select 2: [[Object]], [[Group]] - target the variable got set on with [[setVariable]] (see {{Link|#Alternative Syntax}}) | ||
{{Feature | | {{Feature|informative| | ||
* This EH works '''only''' in Multiplayer environment | * This EH works '''only''' in Multiplayer environment | ||
* There is '''no way to remove''' this EH | * There is '''no way to remove''' this EH | ||
Line 40: | Line 40: | ||
* The value of broadcast variable can be exactly the same, it is the actual broadcast that triggers EH not the change in variable}} | * The value of broadcast variable can be exactly the same, it is the actual broadcast that triggers EH not the change in variable}} | ||
|pr= {{Feature | | |pr= {{Feature|warning|The {{Link|#Alternative Syntax}} does not work as intended.}} | ||
|s1= varName [[addPublicVariableEventHandler]] | |s1= varName [[addPublicVariableEventHandler]] code | ||
|p1= varName: [[String]] - [[missionNamespace]] variable name | |p1= varName: [[String]] - [[missionNamespace]] variable name | ||
|p2= code: [[Code]] - | |p2= code: [[Code]] - by default, the code is executed in [[missionNamespace]] | ||
|r1= [[Nothing]] | |r1= [[Nothing]] | ||
|s2= varName [[addPublicVariableEventHandler]] | |s2= varName [[addPublicVariableEventHandler]] [target, code] | ||
|s2since= arma3 1.46 | |s2since= arma3 1.46 | ||
Line 62: | Line 62: | ||
|r2= [[Nothing]] | |r2= [[Nothing]] | ||
|x1= <sqf>"publicThis" addPublicVariableEventHandler { | |x1= <sqf> | ||
"publicThis" addPublicVariableEventHandler { | |||
hint format [ | hint format [ | ||
"%1 has been updated to: %2", | "%1 has been updated to: %2", | ||
Line 68: | Line 69: | ||
_this select 1 | _this select 1 | ||
] | ] | ||
};</sqf> | }; | ||
</sqf> | |||
|x2= Client: | |x2= Client: | ||
<sqf>"'^:)123BURP,+=lol" addPublicVariableEventHandler {hint ("NUTS are " + (_this select 1))};</sqf> | <sqf>"'^:)123BURP,+=lol" addPublicVariableEventHandler {hint ("NUTS are " + (_this select 1))};</sqf> | ||
Server: | Server: | ||
<sqf>missionNamespace setVariable ["'^:)123BURP,+=lol", "craZZZZy"]; | <sqf> | ||
publicVariable "'^:)123BURP,+=lol";</sqf> | missionNamespace setVariable ["'^:)123BURP,+=lol", "craZZZZy"]; | ||
publicVariable "'^:)123BURP,+=lol"; | |||
</sqf> | |||
|seealso= [[publicVariable]] [[publicVariableClient]] [[publicVariableServer]] | |seealso= [[publicVariable]] [[publicVariableClient]] [[publicVariableServer]] | ||
}} | }} | ||
{{Note | |||
|user= TeRp | |||
|timestamp= 20071222133000 | |||
|text= Please note that varName indicates which variable you want to monitor with this eventhandler.<br> | |||
Please note that varName indicates which variable you want to monitor with this eventhandler.<br> | |||
As a result, the example eventhandler on this page will only fire when the variable publicThis has been changed, | 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. | but not if any other variable was changed by any other client via the publicVariable command. | ||
}} | |||
{{Note | |||
|user= MulleDK13 | |||
|timestamp= 20140227005700 | |||
|text= 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. | |||
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. | }} | ||
{{Note | |||
|user= Killzone_Kid | |||
|timestamp= 20140227084000 | |||
|text= {{User|MulleDK13}}'s note above needs some clarification. You don't "must" use postInit and you absolutely can use preInit function to initialise [[addPublicVariableEventHandler]] if you start [[Scheduler#Scheduled_Environment|scheduled]] script from it.<br> | |||
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 [[Scheduler#Scheduled_Environment|scheduled]] script from it. <br> | <sqf> | ||
<sqf>// script with preInit = 1; in CfgFunctions | // script with preInit = 1; in CfgFunctions | ||
0 spawn { | 0 spawn { | ||
"someVar" addPublicVariableEventHandler { | "someVar" addPublicVariableEventHandler { | ||
// yourcode | // yourcode | ||
}; | }; | ||
};</sqf> | }; | ||
</sqf> | |||
}} | |||
{{Note | |||
|user= SilentSpike | |||
|timestamp= 20151123213600 | |||
|text= 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]]. | |||
While it is true that the event handler will only fire on the machine receiving the broadcast value | |||
Examples: | Examples: | ||
<sqf> | <sqf> | ||
if (isServer) then { | if (isServer) then | ||
{ | |||
"OnServer" addPublicVariableEventHandler { hint "This event handler still fired!"; }; | "OnServer" addPublicVariableEventHandler { hint "This event handler still fired!"; }; | ||
publicVariableServer "OnServer"; | publicVariableServer "OnServer"; | ||
Line 128: | Line 129: | ||
"OnClient" addPublicVariableEventHandler { hint "This event handler still fired!"; }; | "OnClient" addPublicVariableEventHandler { hint "This event handler still fired!"; }; | ||
clientID publicVariableClient "OnClient"; | |||
</sqf> | </sqf> | ||
}} | |||
Latest revision as of 21:49, 2 September 2024
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)
- Problems:
- Groups:
- Broken CommandsEvent HandlersMultiplayerVariables
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]
- Parameters:
- varName: String - name of the variable set on target with setVariable
- target: Object, Group or Team Member
- code: Code
- Return Value:
- Nothing
Examples
- Example 1:
- Example 2:
- Client:
Server:
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
- Posted on Dec 22, 2007 - 13:30 (UTC)
-
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 Feb 27, 2014 - 00:57 (UTC)
- 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 Feb 27, 2014 - 08:40 (UTC)
-
MulleDK13's 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 Nov 23, 2015 - 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!"; }; clientID publicVariableClient "OnClient";
Categories:
- Scripting Commands
- Introduced with Armed Assault version 1.09
- ArmA: Armed Assault: New Scripting Commands
- ArmA: Armed Assault: Scripting Commands
- Arma 2: Scripting Commands
- Arma 2: Operation Arrowhead: Scripting Commands
- Take On Helicopters: Scripting Commands
- Arma 3: Scripting Commands
- Command Group: Broken Commands
- Command Group: Event Handlers
- Command Group: Multiplayer
- Command Group: Variables
- Scripting Commands: Local Effect