As best I can, I'm going to try to provide code that should work correctly..
I realized that I was missing a variable that would be rather required and how to load and spawn; here's the best way to do it that I can think of:
Use the variable menu to create two new array variables (Whatever size you want, as long as the size is big enough for the amount of clones). Preferably named clone_x and clone_y (The names I will use for my example code..). Make sure you've set these variables to save (something is under save groups).
Alongside these variables, create a variable called "
clone_c". (short for clone count)
e.g.:

First you will, again, need to place Feral's cloneID() function into global code.:
- Code: Select all
char buffer[50];
char * cloneID(const char *cname, short unsigned int cindex)
{
sprintf(buffer, "%s.%d", cname, cindex);
return buffer;
}

Now, on the save action, use this code (or a modification of this code) to store the clones x/y values in the two arrays:
Just as a note, this code cannot be used if any actors of this clone have been destroyed by any means, e.g. DestroyActor().
The reason for this is that GE doesn't re-arrange the clone ID's of the actors, leaving holes which breaks the for loop when it attempts to pull the x/y value from the clone actor that doesn't exist anymore.
- Code: Select all
int i;
clone_c = ActorCount("MyClones")-1; // This is saved so we can record the number of actors to spawn on load.
// Replace MyClones with the actor name of your cloned actor.
// "-1" because the actor array starts at 0, while ActorCount starts at 1.
for(i=0; i<ActorCount("MyClones")-1; i++)
{
// Grabs the X/Y value from the clone based on the current iteration of the for() loop.
code_x[i] = getclone(cloneID("MyClones", i))->x;
code_y[i] = getclone(cloneID("MyClones", i))->y;
}
saveVars("Clones.sv", "CloneVars"); // Replace CloneVars with whatever save group you feel like using..
Now, as for loading the clones positions and created them, there is a limitation:
This code can be used at any time, but it will not rid you of any already-existing clones.
- Code: Select all
loadVars("Clones.sv", "CloneVars");
int i;
for(i=0; i<clone_c; i++)
{
CreateActor("testactor", "icon", "(none)", "(none)", clone_x[i], clone_y[i], false);
}
This code of course, is
untested like the previous codes, but should still work.