Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Looking for help writing a script?

somet
Registered User
Quote
2016-02-13 17:04:11

Hi,

Can anyone help me write a script for this game engine that saves and loads the entire game state please?

Many thanks.


niko
Moderator
Quote
2016-02-14 19:15:35

If you need a starting point on how to do something like that: Do something like that:

var root = ccbGetRootSceneNode();
var count = ccbGetSceneNodeChildCount(root);
var s = "";

for(var i=0; i<count; ++i)
{
var child = ccbGetChildSceneNode(root, i);
s += ccbGetSceneNodeProperty(child, "Name") + ';';
}


Which will concatenate the names of all nodes into one string. Then safe that string. Simply also add ID, Position and Rotation, and you should have a basic saved stated already.


somet
Registered User
Quote
2016-02-14 23:11:10

Ok thanks I will look more into this next weekend.


tumira
Registered User
Quote
2016-02-15 00:58:06

@niko

Can you also write out example for load ?

Or maybe you can write a plugin for load and save ? It would really help someone like me.

Thanks


niko
Moderator
Quote
2016-02-17 15:10:47

Load depends heavily on how you are planning to save this. Basically, you probably need to extract whatever you save into the string using String.substring, and parse the names, ids and floats, and set them back. Since the example above only was very rough, it's difficult to say how your final load function should look like exactly.

I've written down to create such a plugin when I have time, but currently such a feature isn't very much requested yet, so it has very low priority right now, sorry.


somet
Registered User
Quote
2016-02-18 00:06:36

Is it possible to create a new javascript function that saves the ENTIRE game state to a data format such as .xml then loads such a ENTIRE game state back from the same .xml file? I know this is quite easy to do in C++ although it is obvious you base this game engine on irrlicht I am not sure if this engine is written in C++ so I know this would be possible in this language but quite lengthy possibly.


seppgirty
Registered User
Quote
2016-02-18 00:34:12

but currently such a feature isn't very much requested yet, so it has very low priority right now, sorry.


Really? I can't believe no one requests this feature. I find the lack of this standard feature puzzling. Every game since the early 90's has a game save. I think you should move this up on the todo list.


niko
Moderator
Quote
2016-02-18 06:02:50

Most people just save a reached level or save point and start from there, because it is also easier to continue. Saving a whole games state is also difficult it you are using extension behaviors, or your own scripts - you can never know what also influences game state, so usually this is up to the game developer.

I think it should be possible to implement this in JavaScript. But I would do it this way: Store the scene you are in, switch to the scene, then load your saved xml with the modified positions and modify all the nodes of the scenes to reflect this. I think it would have some limitations, like you cannot access the internal values of an AI behavior for example, so they would start as if the game just had started. So the game loaded would continue slightly differently, but depending on your game type, this is probably still ok.


tumira
Registered User
Quote
2016-02-18 06:47:07

@niko

I think it would be better if you could provide tutorial or even better an example of simple game contain these features

1)Menu screen (2d Overlay)
2)Game Options screen (AA, etc ?) (2d overlay and simple load and save function)
3)Level1 (maybe simple fps game ?)
-with load and save function
-simple hud (2d overlay)
-Player shoot enemy ?
4)Level2 (this level is loaded after player finishes level1 )
5)Maybe player death and restart level ?
6)Enemy attack player

If you could provide a good example(s) at least someone new like me could at least would not bother you as much


Current examples in coppercube seems like more on just a game engine demo. I hope you can provide us a much better examples.


somet
Registered User
Quote
2016-02-18 13:32:39

I agree with the above post, but a basic example how to load and save game states would be good, bit confused between the difference between save and load from a checkpoint compared to the entire state?? I have no idea how to achieve either.

To do menus should be easy you just create your level in a 2d context rather than 3d and make the camera static.


niko
Moderator
Quote
2016-02-19 04:38:28

Wouldn't making a full example with all the stuff included be a bit complicated? But yes, maybe it could serve as starting point template for creating your own games, didn't think about that. You might be right, could be useful.

Saving just a checkpoint involves saving just one value, like the number of your scene, or the number of the checkpoint. Saving the entire game state is pretty much the opposite. :)

Saving a number can be done with one single action, even with programming, if you like. Just store a value, like the number of the scene or level reached in a variable and use the 'Load or Store a Variable' action.


tumira
Registered User
Quote
2016-02-19 05:55:20

@niko

I think a more advance examples or templates would really help a lot.

At least if anybody would ask you again "Hey how to make a save /load or how to make a checkpoint in games". You could just point to the advance example or maybe use the advance example to explain more.





somet
Registered User
Quote
2016-02-19 15:05:14

I agree an example would be better suited to the explanation as I am still struggling to get my head around it.


54newstar
Registered User
Quote
2016-02-21 03:43:30

wrote:
@niko

I think it would be better if you could provide tutorial or even better an example of simple game contain these features

1)Menu screen (2d Overlay)
2)Game Options screen (AA, etc ?) (2d overlay and simple load and save function)
3)Level1 (maybe simple fps game ?)
-with load and save function
-simple hud (2d overlay)
-Player shoot enemy ?
4)Level2 (this level is loaded after player finishes level1 )
5)Maybe player death and restart level ?
6)Enemy attack player

If you could provide a good example(s) at least someone new like me could at least would not bother you as much


Current examples in coppercube seems like more on just a game engine demo. I hope you can provide us a much better examples.



I can in do these in the next day or so with a written doc and video. I do video tutorials for Scirra/construct (got their YT channel)


I do have some on my YouTube channel but it's kind of hard to link them on my phone.

I do think I have all of the request you asked for though.


54newstar
Registered User
Quote
2016-02-21 15:24:59

just_in_case you don't have to sub, just watch.

Channel; https://www.youtube.com/user/54Newstar

Just search for coppercube or search this play list:

https://www.youtube.com/playlist?list=PLq6aUvz66jtfPn6CLgixPElEMO1z6Ihxo


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "?nternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact