disableSerialization: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\[\[([a-zA-Z][a-zA-Z0-9_]+)\]\]([^ ]*)<\/code>" to "$1$2</code>")
m (Text replacement - "[] spawn" to "0 spawn")
 
(19 intermediate revisions by 3 users not shown)
Line 16: Line 16:
|gr2= GUI Control
|gr2= GUI Control


|descr= Disable saving of script containing this command. After this, the script can work with data types which do not support serialization (UI types). See [[Namespace#Namespace serialization|Namespace serialization]] for more information.
|descr= Disable saving of script containing this command. After this, the script can work with data types which do not support serialization (UI types).
{{Feature|informative|See [[Namespace#Namespace serialization|Namespace serialization]] for more information.}}


{{Feature | important | '''In {{arma2}}''' and up to a certain version of {{arma3}}, <!--
{{Feature|important|
'''In {{arma2}}''' and up to a certain version of {{arma3}}, <!--
-->giving a [[Display]] or [[Control]] to [[spawn]]ed code would raise an error due to the usage of the then non-serializable {{hl|[[Magic Variables#this|_this]]}} variable. <!--
-->giving a [[Display]] or [[Control]] to [[spawn]]ed code would raise an error due to the usage of the then non-serializable {{hl|[[Magic Variables#this|_this]]}} variable. <!--
-->Using [[disableSerialization]] or [[uiNamespace]] wouldn't help; the trick here is to pass the argument inside an array:
-->Using [[disableSerialization]] or [[uiNamespace]] wouldn't help; the trick here is to pass the argument inside an array:
<code>_display {{=}} [[findDisplay]] 46;<br><!--
<sqf>
-->&nbsp;_display&nbsp; [[spawn]] { [[hint]] [[str]] _this; }; // would raise a serialization error<br><!--
_display = findDisplay 46;
-->[_display] spawn { hint str (_this [[select]] 0); }; // OK</code>}}
_display spawn { hint str _this; }; // would raise a serialization error
[_display] spawn { hint str (_this select 0); }; // OK</sqf>
}}


|s1= [[disableSerialization]]
|s1= [[disableSerialization]]
Line 29: Line 33:
|r1= [[Nothing]]
|r1= [[Nothing]]


|x1= <code>[[disableSerialization]];
|x1= <sqf>
private _display = findDisplay 46;</code>
disableSerialization;
private _display = findDisplay 46;
</sqf>


|seealso= [[Display]] [[displayAddEventHandler]] [[displayRemoveAllEventHandlers]] [[displayRemoveEventHandler]] [[uiSleep]]
|seealso= [[Display]] [[displayAddEventHandler]] [[displayRemoveAllEventHandlers]] [[displayRemoveEventHandler]] [[uiSleep]]
}}
}}


<dl class="command_description">
{{Note
 
|user= Str
<dt></dt>
|timestamp= 20100619102600
<dd class="notedate">Posted on 19 June, 2010 </dd>
|text= Can be used to detecting load. Scope with disabled serialization is discontinued after load, even if there's endless loop inside.
<dt class="note">[[User:Str|Str]]</dt>
<sqf>
<dd class="note">
0 spawn { disableSerialization; waitUntil { false }; hint "Game was loaded!";};
Can be used to detecting load. Scope with disabled serialization is discontinued after load, even if there's endless loop inside.
</sqf>
<code>_loaded = [] [[spawn]] { [[disableSerialization]]; [[waitUntil]] { [[false]] }; };
[[waitUntil]] { [[scriptDone]] _loaded; };
hint "Game was loaded!";</code>
Works for all possible load types - loading user save, loading autosave and resuming mission from main menu.
Works for all possible load types - loading user save, loading autosave and resuming mission from main menu.


Use with caution, as it handles two threads in memory, having impact at overall [[Code_Optimisation#Threads|scripting time]].
Use with caution, as it creates an infinite loop, having impact at overall [[Code_Optimisation#Threads|scripting time]].
<dt><dt>
}}
<dd class="notedate">Posted on 23 October, 2013 </dd>
<dt class="note">[[User:Killzone_Kid|Killzone_Kid]]</dt>
<dd class="note">


If you do not store UI elements ([[Display]], [[Control]]) in variables, you do not need [[disableSerialization]]; UI elements are usually returned by scripting commands such as [[findDisplay]] or passed as params in UI event handler scripts ([[displayAddEventHandler]], [[ctrlAddEventHandler]]).  
{{Note
|user= Killzone_Kid
|timestamp= 20131023025700
|text= If you do not store UI elements ([[Display]], [[Control]]) in variables, you do not need [[disableSerialization]]; UI elements are usually returned by scripting commands such as [[findDisplay]] or passed as params in UI event handler scripts ([[displayAddEventHandler]], [[ctrlAddEventHandler]]).  


This code will require [[disableSerialization]]:
This code will require [[disableSerialization]]:
<code>[[disableSerialization]];
<sqf>
_display = [[findDisplay]] 123;
disableSerialization;
_ctrl = _display [[displayCtrl]] -1;
_display = findDisplay 123;
_ctrl ctrlSetText "LOL";</code>
_ctrl = _display displayCtrl -1;
_ctrl ctrlSetText "LOL";
</sqf>
This code will not:
This code will not:
<code>findDisplay 123 displayCtrl -1 ctrlSetText "LOL";</code>
<sqf>findDisplay 123 displayCtrl -1 ctrlSetText "LOL";</sqf>
<dt><dt>
}}
<dd class="notedate">Posted on July 25, 2017 - 18:15 (UTC)</dd>
 
<dt class="note">[[User:IT07|IT07]]</dt>
{{Note
<dd class="note">
|user= Nelis75733126
In Arma 3 1.74, a scripted FSM does somehow not work with [[disableSerialization]]. As a workaround, store a display inside an array.
|timestamp= 20170625181500
Example:
|text= In {{arma3}} 1.74, a scripted FSM is somehow incompatible with <sqf inline>disableSerialization</sqf>.<br>
<code>_display = <nowiki>[</nowiki>findDisplay idd];</code>
As a workaround, store a display inside an array. Example:
</dl>
<sqf>_display = [findDisplay idd];</sqf>
}}

Latest revision as of 21:24, 2 September 2024

Hover & click on the images for description

Description

Description:
Disable saving of script containing this command. After this, the script can work with data types which do not support serialization (UI types).
See Namespace serialization for more information.
In Arma 2 and up to a certain version of Arma 3, giving a Display or Control to spawned code would raise an error due to the usage of the then non-serializable _this variable. Using disableSerialization or uiNamespace wouldn't help; the trick here is to pass the argument inside an array:
_display = findDisplay 46; _display spawn { hint str _this; }; // would raise a serialization error [_display] spawn { hint str (_this select 0); }; // OK
Groups:
NamespacesGUI Control

Syntax

Syntax:
disableSerialization
Return Value:
Nothing

Examples

Example 1:
disableSerialization; private _display = findDisplay 46;

Additional Information

See also:
Display displayAddEventHandler displayRemoveAllEventHandlers displayRemoveEventHandler uiSleep

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
Str - c
Posted on Jun 19, 2010 - 10:26 (UTC)
Can be used to detecting load. Scope with disabled serialization is discontinued after load, even if there's endless loop inside.
0 spawn { disableSerialization; waitUntil { false }; hint "Game was loaded!";};
Works for all possible load types - loading user save, loading autosave and resuming mission from main menu. Use with caution, as it creates an infinite loop, having impact at overall scripting time.
Killzone_Kid - c
Posted on Oct 23, 2013 - 02:57 (UTC)
If you do not store UI elements (Display, Control) in variables, you do not need disableSerialization; UI elements are usually returned by scripting commands such as findDisplay or passed as params in UI event handler scripts (displayAddEventHandler, ctrlAddEventHandler). This code will require disableSerialization:
disableSerialization; _display = findDisplay 123; _ctrl = _display displayCtrl -1; _ctrl ctrlSetText "LOL";
This code will not:
Nelis75733126 - c
Posted on Jun 25, 2017 - 18:15 (UTC)
In Arma 3 1.74, a scripted FSM is somehow incompatible with disableSerialization.
As a workaround, store a display inside an array. Example:
_display = [findDisplay idd];