I am having a problem with saving/loading scene state
I have “Blocks” that you can place in a 50x50 grid, i need to save:
X position of the blocks
Y position of the blocks
Block current animation frame (Block texture)
I was hoping for a way to store data in variable list (if these exist, and if they do then answer please)
I can code you a little Js snippet. If all the blocks have the same object name it should be easy. Is there anything else/any object that should also be saved? What is the objects name?
in this moment there isn’t arrays in GDevelop. but you can simulate its function with variable structures. you sholud learn how they work, and you have to adapt to it.
For all who wins how to use arrays use Js, if you can’t use Js then wait that somebody (maybe me ) codes an extension for it. In the meantime here are my snippets (untested just wrote out of memory) to save and load an array with all the instances x and y position and their current animation:
Saving:
function save(runtimeScene, objectName){
let save = [];
let objects = runtimeScene.getObjects(objectName);
for(let object of objects){
objData = [
object.getX(),
object.getY(),
object.getAnimationName()
];
save.push(objData);
}
localstorage.setItem(
"gameSave/grid",
JSON.stringify(
{
"save":save,
"name": objectName
}
)
);
}
save(runtimeScene, "Blocks");
For loading:
function load(runtimeScene){
let save = localstorage.getItem("gameSave/grid");
let objects = runtimeScene.getObjects(objectName);
for(let object of objects){
object.deleteFromScene(runtimeScene);
}
for (let o of save.save){
let object = runtimeScene.createObject(save.name);
object.setX(o[0]);
object.setY(o[1]);
object.setAnimationName(o[2]);
}
}
load(runtimeScene);
Sorry if it is not clean I wrote it quickly in an app that wasn’t thought for writing code (word mobile) and because of a bug I had to rewrite it 3 times because it deleted itself.
An example is included with GDevelop called “Level editor”. Do exactly what you asking. Have a look.
I can see you are closing topics as soon you consider it “answered”, could it be possible to wait at least 48 hours regardless of the result of the discussion?
If there is no activity for 48 hours then close it