addPublicVariableEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(page overhaul)
Line 11: Line 11:
____________________________________________________________________________________________
____________________________________________________________________________________________


| If the EH detects a change via publicVariable on the given variable, code will be executed.
| This event handler will detect if a [[missionNamespace]] variable 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:
<br />
<br />_this select 0: [[String]] - broadcast variable name (same variable name EH is attached to)
<br />_this select 1: [[Anything]] - broadcast variable value
<br />
<br />'''Please note:'''
<br />* EH works only in Multiplayer environment.
<br />* EH will not fire on the machine that executed broadcast command, only on the machines that receive the broadcast.
<br />* The value of broadcast variable can be exactly the same, it is the actual broadcast that triggers EH not the change in variable.


The following arguments are transferred to the code:
_this select 0: variable name
_this select 1: new variable value
|= Description
|= Description
____________________________________________________________________________________________
____________________________________________________________________________________________
Line 23: Line 26:
| varName '''addPublicVariableEventHandler''' code |= Syntax
| varName '''addPublicVariableEventHandler''' code |= Syntax


|p1= varName: [[String]] |= Parameter 1
|p1= varName: [[String]] - [[missionNamespace]] variable name |= Parameter 1
|p2= code: [[Code]] |= Parameter 2
|p2= code: [[Code]] |= Parameter 2


Line 29: Line 32:
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <code>"publicThis" '''addPublicVariableEventHandler''' {hint ((_this select 0) + " has been updated to: " + str (_this select 1))}</code> |= Example 1
|x1= <code>"publicThis" [[addPublicVariableEventHandler]] {
[[hint]] [[format]] [
"%1 has been updated to: %2",
_this [[select]] 0,
_this [[select]] 1
]
};</code> |= Example 1
 
|x2= Client:<code>"'^:)123BURP,+=lol" [[addPublicVariableEventHandler]] {[[hint]] "NUTS are " + _this [[select]] 1};</code>
Server:<code>[[missionNamespace]] [[setVariable]] ["'^:)123BURP,+=lol", "craZZZZy"];
[[publicVariable]] "'^:)123BURP,+=lol";</code> |= Example 2
____________________________________________________________________________________________
____________________________________________________________________________________________


| [[publicVariable]] |= See also
| [[publicVariable]], [[publicVariableClient]], [[publicVariableServer]] |= See also
| mp= Note that the EH is <i>only</i> fired on clients where the [[publicVariable]] command has not been executed, as publicVariable does not change the variable where it has been executed. |=
 
}}
}}


Line 48: Line 61:


<!--
<!--
<dt class="note">'''[[User:Anunnaki|Anunnaki]]'''
<dd class="note">
Very important !
addPublicVariableEventHandler does NOT WORK on dedicated server or player server! This is probaly bug in 1.09beta.


<dt class="note">'''[[User:Dennis|Dennis]]'''
<dt class="note">'''[[User:Dennis|Dennis]]'''

Revision as of 19:20, 22 September 2013

-wrong parameter ("Arma") defined!-1.09
Hover & click on the images for description

Description

Description:
This event handler will detect if a missionNamespace variable 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

Please note:
* EH works only in Multiplayer environment.
* EH will not fire on the machine that executed broadcast 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.
Groups:
Uncategorised

Syntax

Syntax:
varName addPublicVariableEventHandler code
Parameters:
varName: String - missionNamespace variable name
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:
publicVariablepublicVariableClientpublicVariableServer

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

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.

Bottom Section