Unsigned 16-bit integer, a positive value from 0 - 65535 Signed 8-bit integer, a positive or negative value from -128 to 127 Unsigned 8-bit integer, a positive value from 0 to 255 Please ensure that the value you're serializing matches the datatype in the schema. Elephant does no type checking for scalar values in the interests of speed. Variables defined in a schema can take any of the following datatypes, partially shared with GameMaker's native constants that are used for buffer access. It is very important that you do not ever remove schema versions! If you remove a schema version then any old files that use the old schema version cannot be recovered, which is very likely to break your project. Schema versions must start with a lowercase v and must be followed by a positive integer from 1 to 127 inclusive.
#Gamemaker studio 2 vs construct 3 code#
Versioning is critical for writing robust code that will work as your project develops and changes. Top-level keys in a struct delineate schema versions. Schemas must be defined by setting ELEPHANT_SCHEMA in a constructor e.g. Try to declare a schema whenever you can. This typically leads to large buffers and is much slower to both serialize and deserialize and should generally be avoided. If no schema is defined then all member variables for the struct will be serialized using the generic buffer_any datatype. This struct literal contains schema versions as the top-level keys, and member variables names with associated datatype as second-level keys. Schemas may be defined for constructors by using the macro ELEPHANT_SCHEMA to define a struct literal. This function will recreate constructed structs appropriately and will also correctly duplicate circular references. Unlike ElephantWrite(), this function ignores schemas and will copy all member variables and non-static methods. Makes an identical copy of the target.This string should have been created by ElephantExportString(). As above, but takes a string rather than a buffer.ELEPHANT_SCHEMA_VERSION will contain the constructor schema version that Elephant found in the source data. This function calls ELEPHANT_PRE_READ_METHOD and ELEPHANT_POST_READ_METHOD for constructed structs, and ELEPHANT_IS_DESERIALIZING is set to true. This function uses buffer_read() and will move the buffer head as it reads data. Deserializes Elephant data from a buffer, starting at the buffer_tell() point.This function also performs compression on the buffer. As above, but returns a base64 encoded version of the buffer.ELEPHANT_SCHEMA_VERSION will contain the constructor schema version that Elephant is using to serialize data. This function calls ELEPHANT_PRE_WRITE_METHOD and ELEPHANT_POST_WRITE_METHOD for constructed structs, and ELEPHANT_IS_DESERIALIZING is set to false. If no buffer is provided then a new buffer is created that fits the serialized data. This function uses buffer_write() and will move the buffer head as it writes. Serializes the given target data and writes it to the given buffer, starting at the buffer_tell() position.These are explained in further detail later in the document.Ĭustom datatypes that can be used with Elephant schemas:Įlephant has five public functions that can be used: A non-static method cannot be serialized and will instead be set to undefined upon deserialization.Įlephant introduces a handful of macros that are useful for interacting with the library. When using Elephant it is very important to ensure constructor methods are static. Preferably, constructors should only set default variable values and structs shouldn't alter state outside of their scope on instantiation. Arrays are limited to 65534 elements and structs are limited to 65533 member variablesĪrrays are assumed to have flexible typing, though arrays that are found to have a consistent datatype throughout are optimised automatically when serializing.Upon deserialization, structs are rebuilt by new-ing the constructor with zero arguments.Constructor schemas are shallow without nesting/recursion, and arrays cannot have schemas.Whilst static methods in constructors will persist, non-static methods cannot be serialized.Constructors must be in global scope i.e.When using Elephant, some considerations must be taken into account: Constructed structs can have read/write callbacks.Constructed structs can have schemas to control which variables are serialized and how.Structs made with constructors are recreated using the constructor.Circular references are stored and recreated correctly.Serialization of arrays, structs, and scalar datatypes.Advanced struct/array serialization for GameMaker Studio about Elephant on the Discord serverĮlephant is a struct/array serialization system that offers extended functionality beyond the typical JSON functions: