Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Can i save\load the whole scene with json?
Started by sasha.naykus Mar 13 2019 02:32 PM

6 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sasha.naykus

[GLOBAL: userInfoPane.html]
sasha.naykus
  • Observer

  • 4 posts
  • Corona SDK

In my game i cant just save some table, because it ruins all the code. I need the way to save the whole scene and to load it again at the start of the game. It doesn't has to be a json solution, I need anything that can work. Thank you in advance!



[TOPIC: post.html]
#2

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Corona Geek

  • 1,013 posts
  • Corona SDK

I think this has been asked before (please search). I think the answer is no. You can save the model of the view (as string or JSON or whatever) and then reload the model to the same view.



[TOPIC: post.html]
#3

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,712 posts
  • Corona SDK

As agramonte says, you'll need to save the state of each object (type, position, rotation, image filename etc.) and then re-create them all when loading the game.

I am making a real-time strategy game in Unity, and ended up making the 'new game' state just a specific hard-coded saved game. So all my code to create objects requires a saved-game format input rather than making objects and then working out how to save/load them.

[TOPIC: post.html]
#4

sasha.naykus

[GLOBAL: userInfoPane.html]
sasha.naykus
  • Observer

  • 4 posts
  • Corona SDK

I think this has been asked before (please search). I think the answer is no. You can save the model of the view (as string or JSON or whatever) and then reload the model to the same view.

How can i do it?

[TOPIC: post.html]
#5

sasha.naykus

[GLOBAL: userInfoPane.html]
sasha.naykus
  • Observer

  • 4 posts
  • Corona SDK

As agramonte says, you'll need to save the state of each object (type, position, rotation, image filename etc.) and then re-create them all when loading the game.

I am making a real-time strategy game in Unity, and ended up making the 'new game' state just a specific hard-coded saved game. So all my code to create objects requires a saved-game format input rather than making objects and then working out how to save/load them.

I think you're right and if I won't find any other solution, I'll use yours one.

[TOPIC: post.html]
#6

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 583 posts
  • Corona SDK

It'd always help out a lot to know exactly what kind of data you'd need to save, but @agramonte and @nick_sherman have already pointed out the obvious. Part of that obviousness is that your data can most likely be saved in a table, but maybe you just haven't figured out how yet.

The simplest approach to issues like this is to always plan ahead. Think of all of the values/data that you need to store and then just create your game around this idea.

For instance, I worked on a cartoon-ish top-down shooter some time ago where levels consisted of pseudo-randomly generated terrain features as well as units for the player and the AI to control. At the start of development, I thought about all of the information I'd need to store for each terrain feature and for each unit. These were simply x and y coordinates, rotation, scale, terrain/unit type, HP, etc.

So, basically I was dealing with "a large" numbers of tables. My approach was simple: determine if the game is being loaded or if it is a new game, i.e. whether the map should be loaded or generated, etc. In either case, I had a function that looped through every terrain feature and unit. As the function went through the tables (i.e. terrain features or units) one by one, it looked at what the terrain's/unit's type was. This type determined what graphic was used, then HP value was used to create the HP bar (well, duh? :P), rotation, x and y to position each object, etc. etc.

The only difference between starting a new game and loading an existing one was whether the HP, rotation, x, y, etc. entries were filled with default values or stored values. So, whenever I needed to save the game, I simply looped through all existing terrain features and units and created a table with them in it.



[TOPIC: post.html]
#7

sasha.naykus

[GLOBAL: userInfoPane.html]
sasha.naykus
  • Observer

  • 4 posts
  • Corona SDK

It'd always help out a lot to know exactly what kind of data you'd need to save, but @agramonte and @nick_sherman have already pointed out the obvious. Part of that obviousness is that your data can most likely be saved in a table, but maybe you just haven't figured out how yet.

The simplest approach to issues like this is to always plan ahead. Think of all of the values/data that you need to store and then just create your game around this idea.

For instance, I worked on a cartoon-ish top-down shooter some time ago where levels consisted of pseudo-randomly generated terrain features as well as units for the player and the AI to control. At the start of development, I thought about all of the information I'd need to store for each terrain feature and for each unit. These were simply x and y coordinates, rotation, scale, terrain/unit type, HP, etc.

So, basically I was dealing with "a large" numbers of tables. My approach was simple: determine if the game is being loaded or if it is a new game, i.e. whether the map should be loaded or generated, etc. In either case, I had a function that looped through every terrain feature and unit. As the function went through the tables (i.e. terrain features or units) one by one, it looked at what the terrain's/unit's type was. This type determined what graphic was used, then HP value was used to create the HP bar (well, duh? :P), rotation, x and y to position each object, etc. etc.

The only difference between starting a new game and loading an existing one was whether the HP, rotation, x, y, etc. entries were filled with default values or stored values. So, whenever I needed to save the game, I simply looped through all existing terrain features and units and created a table with them in it.

I am creating a kind of a rpg game, and all troubles are starting when I'm trying to load my inventory. Load function can't load images.
Maybe your post has just given me an excellent idea. I'm gonna try it right now.


[topic_controls]
[/topic_controls]