This page documents the steps to port a script from ScriptVersion 3 to ScriptVersion 4.
If I missed anything, please let me know.
-- Mana
The save file formats have changed, any .dat files saved by the engine should be deleted manually (including LogWindow.dat if you want it to start with all filters on by default)
Arrays are now references, ensure all array usage now takes this into account:
let arrCopy = copy(arr);
let arr2 = arr1;
is a reference to the same arrayarr[index] = value;
will modify all references to the array~
and ~=
operators do not modify the array, they create a new array leaving the original array untouchedStrings are now references to immutable sequences of characters, not arrays. The engine will attempt to de-duplicate simple strings (alphanumeric, underscores, dots, and slashes) during compilation to make comparison between strings faster.
Important points:
~
and ~=
operators still work as expectedstr[index] = value;
will no longer work and will raise a clear error messagearray(str);
can be used to construct a modifiable array containing all of the characters of str
string(value)
can be used to construct a new string from any typeAll collection types (array, string, table) are references and use simple reference counting garbage collection. This means that if you create a reference cycle, the memory can leak.
Strings, despite being a collection type, cannot create reference cycles because they are immutable sequences of char (a non-collection type).
Note: The copy(collection) function can be used to safely store a copy of a collection within itself.
The following are examples of reference cycles that can cause a leak and how to avoid them:
The concatenation operators ~ and ~= always create a deep copy automatically and are therefore always safe to use.
Some new functions are known to have the same names as functions in existing scripts:
Some new keywords that were introduced are likely to potentially have the same names as variables in existing scripts, ensure that no variables are named the following: