Runtime Vector Serialization

This forum is currently in read-only mode.
From the Asset Store
User Interface element to build 2D mobile game - Vector Game UI Elements
  • I have a vector and I don't know how to set it up for runtime serialization. I need this so that quicksave and quickload can be used without emptying the vector in the process. Any way to do this?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Normally you'd just save the size then iterate each element saving them. When loading do the reverse - load the number of elements then for that number of times, load an element and add it to the vector.

  • Well, I attempted something like that, but I really don't know how it would work. What's really complicating this is the fact that it's a vector that contains different instances of a struct I created. It's something like this:

    struct c_T
        crapload of variables...
    vector<c_T> cV;
    Whenever I need another instance of this struct, I increase the size of the vector, so I'm not really adding an object to it.  Is there some way to serialize everything inside the struct and then put it all back in again?
  • Yeah, add a serialize() to the struct that does ar << a << b << c etc, and the same for loading (ar >> a >> b >> c). Then to save the whole vector, save the size, then for each element, call its serialize(). To load it, load the size, clear the vector, then for each element serialize() it in to a temporary struct and push it back to the vector.

  • Any more information on how the Serialize() function works? For example, how do I set it up in the struct. Something like this?

    struct c_T
        float a;
        float b;
        float c;
        void Serialize(bin& ar);
    Or is it different?
    Also, how do I use the function in the actual serialization file?  It takes an argument, but I don't know what said argument should be.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)