OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: DMarkwick on 08 Jul 2009, 03:00:27

Title: Variable serialization?
Post by: DMarkwick on 08 Jul 2009, 03:00:27
While importing & testing my old trusty addons from ArmA1 (which mostly work just fine thanks to the new EEH release :)) one of them threw up this error:
Quote
Warning Message: Variable '_jtd_slowdown' does not support serialization. Call 'disableSerialization' in the current script (maybe 'JTD_TimeWarp\Scripts\JTD_TimeWarp_init.sqf') if you need to use it.

So I just added the disableSerialization command & it fixed it.

My question: what is serialization and what are the consequences of me adding that command to the addon? It seems to work fine BTW, and I have not seen it break anything else.
Title: Re: Variable serialization?
Post by: Spooner on 08 Jul 2009, 04:07:26
Nobody knows what it is for, which doesn't help. Might be something to do with MP savegames, but it is anyone's guess...

The correct way to fix it, since disableSerialization is a backwards compatibility feature, is though ensuring that uiNamespace is used for globals that reference UI handles (control/display values) and not storing these in local variables.

Compatibility mode:
Code: [Select]
disableSerialization; // Allow UI handles in regular mission namespace.
nameOfMyCat = "fred";
myDisplay = findDisplay 45;

_text = "frogger";
(mydisplay displayCtrl 98) ctrlSetText _text;
(mydisplay displayCtrl 99) ctrlSetText _text;

Fixed:
Code: [Select]
nameOfMyCat = "fred"; // Non-UI globals still work the same
with uiNamespace { mydisplay = findDisplay 45 };

_text = "frogger"; // Locals cross the namespaces, but cannot contain UI handles.
with uiNamespace {
   (mydisplay displayCtrl 98) ctrlSetText _text;
   (mydisplay displayCtrl 99) ctrlSetText _text;
};

Note: I strongly recommend the use of with over the alternative, which is to use of set/getVariable on the namespace.

Anyway, plenty of information on this if you look around. I'd not worry about it and stick to disableSerialization for any ported stuff, though it might be worth writing any new dialog stuff "properly". No point rewriting your existing code until you know if you really need to.
Title: Re: Variable serialization?
Post by: DMarkwick on 08 Jul 2009, 12:03:22
OK thanks for the writeup :) I think I'll probably fix it rather than use the fudge, seems a small enough fix.

Although I have to say I don't really understand the whole "namespace" thing :D

*edit*
For some reason, this code throws a "missing ;" error although it seems identical in form to your example:
Code: [Select]
//disableSerialization;
JTD_TimeWarp = 1;
JTD_TimeWarp_SQF = compile preprocessFile "\JTD_TimeWarp\Scripts\JTD_TimeWarp.sqf";
with uiNamespace
{
_JTD_SlowDown = findDisplay 46;
_JTD_SlowDown displaySetEventHandler ["KeyDown", "_this call JTD_TimeWarp_SQF"];
};
Title: Re: Variable serialization?
Post by: Spooner on 10 Jul 2009, 23:58:39
_JTD_SlowDown is a local. Locals can't store UI handles, only globals. You may believe that putting your tag at the front makes it a global, but it doesn't (and you shouldn't use a tag for locals).

Me being an idiot again. Dodododododododo. Sorry:
Code: [Select]
with uiNamespace do { ...do stuff... };
Title: Re: Variable serialization?
Post by: DMarkwick on 11 Jul 2009, 00:56:13
No, I don't believe placing my tag at the beginning makes it a global :) The reason it's local is that it didn't work at all as a global.

I'll make that minor change though & see what happens :)

Thanks for the info.

*edit*
Seems to work, AFTER making those variables back into globals :D

Go figure :)