addPublicVariableEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<br />" to "<br>")
m (Some wiki formatting)
 
(74 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma |Game name=
|game1= arma1
|version1= 1.09


|1.09|Game version=
|game2= arma2
|version2= 1.00


|arg= global |Multiplayer Arguments=
|game3= arma2oa
|version3= 1.50


|eff= local |Multiplayer Effects=
|game4= tkoh
____________________________________________________________________________________________
|version4= 1.00


| 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:
|game5= arma3
<br>
|version5= 0.50
<br>_this select 0: [[String]] - broadcast variable name (same variable name EH is attached to)
 
<br>_this select 1: [[Anything]] - broadcast variable value  
|arg= global
<br>_this select 2: [[Object]], [[Group]] - target the variable got set on with [[setVariable]] (see: alternative syntax)
 
<br><br>
|eff= local
{{Informative |
 
* This EH works only in Multiplayer environment<br>
|gr1= Broken Commands
* This EH will not fire on the machine that executed broadcast with [[publicVariable]] command, only on the machines that receive the broadcast<br>
 
|gr2= Event Handlers
 
|gr3= Multiplayer
 
|gr4= Variables
 
|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 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 {{Link|#Alternative Syntax}})
{{Feature|informative|
* 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}}
* The value of broadcast variable can be exactly the same, it is the actual broadcast that triggers EH not the change in variable}}
<br>
{{Warning | Alt syntax of this command doesn't work as intended}}|DESCRIPTION=
____________________________________________________________________________________________


| varName '''addPublicVariableEventHandler''' code |SYNTAX=
|pr= {{Feature|warning|The {{Link|#Alternative Syntax}} does not work as intended.}}
 
|s1= varName [[addPublicVariableEventHandler]] code
 
|p1= varName: [[String]] - [[missionNamespace]] variable name
 
|p2= code: [[Code]] - by default, the code is executed in [[missionNamespace]]


|p1= varName: [[String]] - [[missionNamespace]] variable name |PARAMETER1=
|r1= [[Nothing]]
|p2= code: [[Code]] - By default, the code is executed in [[missionNamespace]] |PARAMETER2=


| [[Nothing]] |RETURNVALUE=
|s2= varName [[addPublicVariableEventHandler]] [target, code]


|s2= varName '''addPublicVariableEventHandler''' [target, code] ''(since A3 1.46)''|SYNTAX2=
|s2since= arma3 1.46


|p21= varName: [[String]] - name of the variable set on target with [[setVariable]] |PARAMETER21=
|p21= varName: [[String]] - name of the variable set on target with [[setVariable]]
|p22= [target, code]: [[Array]] |PARAMETER1=
|p23= target: [[Object]], [[Group]] or [[Team Member]]|PARAMETER2=
|p24= code: [[Code]] |PARAMETER2=


|r2= [[Nothing]] |RETURNVALUE2=
|p22= target: [[Object]], [[Group]] or [[Team Member]]
____________________________________________________________________________________________
 
 
|p23= code: [[Code]]
|x1= <code>"publicThis" [[addPublicVariableEventHandler]] {
 
[[hint]] [[format]] [
|r2= [[Nothing]]
 
|x1= <sqf>
"publicThis" addPublicVariableEventHandler {
hint format [
"%1 has been updated to: %2",
"%1 has been updated to: %2",
_this [[select]] 0,
_this select 0,
_this [[select]] 1
_this select 1
]
]
};</code> |EXAMPLE1=
};
 
</sqf>
|x2= Client:<code>"'^:)123BURP,+=lol" [[addPublicVariableEventHandler]] {[[hint]] ("NUTS are " + (_this [[select]] 1))};</code>
Server:<code>[[missionNamespace]] [[setVariable]] ["'^:)123BURP,+=lol", "craZZZZy"];
[[publicVariable]] "'^:)123BURP,+=lol";</code> |EXAMPLE2=
____________________________________________________________________________________________


| [[publicVariable]], [[publicVariableClient]], [[publicVariableServer]] |SEEALSO=
|x2= Client:
<sqf>"'^:)123BURP,+=lol" addPublicVariableEventHandler {hint ("NUTS are " + (_this select 1))};</sqf>
Server:
<sqf>
missionNamespace setVariable ["'^:)123BURP,+=lol", "craZZZZy"];
publicVariable "'^:)123BURP,+=lol";
</sqf>


|seealso= [[publicVariable]] [[publicVariableClient]] [[publicVariableServer]]
}}
}}


<h3 style="display:none">Notes</h3>
{{Note
<dl class="command_description">
|user= TeRp
<!-- Note Section BEGIN -->
|timestamp= 20071222133000
<dd class="notedate">Posted on 22 Dec, 2007
|text= Please note that varName indicates which variable you want to monitor with this eventhandler.<br>
<dt class="note">[[User:TeRp|TeRp]]<dd class="note">
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.  
}}


<dd class="notedate">Posted on 27 Feb, 2014 00:57
{{Note
<dt class="note">[[User:MulleDK13|MulleDK13]]<dd class="note">
|user= 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.
|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.
}}


<dd class="notedate">Posted on 27 Feb, 2014 08:40
{{Note
<dt class="note">'''[[User:Killzone_Kid|Killzone_Kid]]'''<dd class="note">
|user= 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 [[Scheduler#Scheduled_Environment|scheduled]] script from it. <br>
|timestamp= 20140227084000
<code>//script with preInit = 1; in CfgFunctions
|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>
0 = 0 [[spawn]] {
<sqf>
"someVar" [[addPublicVariableEventHandler]] {
// script with preInit = 1; in CfgFunctions
//yourcode
0 spawn {
"someVar" addPublicVariableEventHandler {
// yourcode
};
};
};</code>
};
<!-- Note Section END -->
</sqf>
</dl>
}}


<h3 style="display:none">Bottom Section</h3>
{{Note
[[Category:Command_Group:_Multiplayer|{{uc:{{PAGENAME}}}}]]
|user= SilentSpike
[[Category:Scripting Commands|ADDPUBLICVARIABLEEVENTHANDLER]]
|timestamp= 20151123213600
[[Category:Scripting Commands ArmA|ADDPUBLICVARIABLEEVENTHANDLER]]
|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]].
[[Category:Scripting Commands Arma 2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Broken Scripting Commands|{{uc:{{PAGENAME}}}}]]


<!-- CONTINUE Notes -->
Examples:
<dl class="command_description">
<sqf>
<dd class="notedate">Posted on November 23, 2015 - 21:36 (UTC)</dd>
if (isServer) then
<dt class="note">[[User:SilentSpike|SilentSpike]]</dt>
{
<dd class="note">
"OnServer" addPublicVariableEventHandler { hint "This event handler still fired!"; };
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]].
publicVariableServer "OnServer";
 
};
Examples: <code>if ([[isServer]]) then {
</sqf>
    "OnServer" [[addPublicVariableEventHandler]] { [[hint]] "This event handler still fired!"; };
<sqf>
    [[publicVariableServer]] "OnServer";
// This example assumes the client knows their own client ID
};</code>
<code>// 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
// 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!"; };
"OnClient" addPublicVariableEventHandler { hint "This event handler still fired!"; };
<client ID> [[publicVariableClient]] "OnClient";
clientID publicVariableClient "OnClient";
</code>
</sqf>
</dd>
}}
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 21:49, 2 September 2024

Hover & click on the images for description

Description

Description:
Arma 3
This command is deprecated since Arma 3 logo black.png1.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 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
Problems:
The Alternative Syntax does not work as intended.
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:
"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

See also:
publicVariable publicVariableClient publicVariableServer

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
TeRp - c
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.
MulleDK13 - c
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.
Killzone_Kid - c
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 }; };
SilentSpike - c
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";