Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Can't Save/Load Data

sebastianos
Registered User
Quote
2019-05-23 12:23:54

Before answering this, please read all of this carefully. I'm trying to create a save/load system.

I've noticed that variables created using Execute Java Script ARE NOT compatible with variables used in the Set or Change a Variable action. Here is an example of something I could create in JavaScript and then create a variable, see below.

var a = 1

And then if you were to use the Set or Change a Variable action, and put "Example" (NO quotes around the "Example") in the VariableName section and with the ValueType being set to Variable, I put "a" (NO quotes around the "a") in the Value section so that "Example" equals "a".

I could test this by using the "If a Variable has a value do something" action and the result will be a sofa (that at the start of the scene is invisible) will become visible if "Example" equals "a".

Guess what, I know it wont work! I don't know why the Execute Java Script and the Set or Change a Variable action do not have compatible variables. I mean, how am I supposed to create a save/load system if I can only use Java Script or I can only use the Set or Change Variable action? I am not knowledgeable enough to do it one way or another. I can't even imagine the type of JavaScript I'd have to type to create my own save/load system. And using the Set or Change Variable action, I'm trying to put in the camera's position in the VariableName section as Camera1.Position and have it equal another variable in the Value section so that I can use the "Load or Store a Variable from or to disk" action to save the variable and then load it in. But Camera1.Position doesn't work. Nor does Camera1.Pos and Camera1.PosX. I just don't know anymore. How can I save the position of the player and everything in the scene if I can't even do these simple things?

Please please please help me. Thanks


Robo
Guest
Quote
2019-06-25 05:39:23

you need to transform javascript data into CC variables, save them and reload them and action back into the game.

I use this to save:
var player=ccbGetSceneNodeFromName("Player1");
var curPos=ccbGetSceneNodeProperty(player,"Position");
var curTgt=ccbGetSceneNodeProperty(player,"Target");
var curHth = ccbGetCopperCubeVariable("Player1.health");
ccbSetCopperCubeVariable("savePosition",curPos);
ccbSetCopperCubeVariable("saveTarget",curTgt);
ccbSetCopperCubeVariable("saveHealth",curHth);

var enemy=ccbGetSceneNodeFromName("Enemy1");
var curPos=ccbGetSceneNodeProperty(enemy,"Position");
var curHth = ccbGetCopperCubeVariable("Enemy1.health");
ccbSetCopperCubeVariable("saveE1Position",curPos);
ccbSetCopperCubeVariable("saveE1Health",curHth);

then I save the variables like savePosition etc standard way then load back up and apply back into the game with this:

var player=ccbGetSceneNodeFromName("Player1");
var camera=ccbGetSceneNodeFromName("Menu");
var savePosition =ccbGetCopperCubeVariable("savePosition");
var saveTarget =ccbGetCopperCubeVariable("saveTarget");
var saveFov =ccbGetCopperCubeVariable("saveFov");
var saveVol =ccbGetCopperCubeVariable("saveVol");
ccbSetSceneNodeProperty(player,"Position", savePosition);
ccbSetSceneNodeProperty(camera,"Target", saveTarget);
ccbSetSceneNodeProperty(player,"Target", saveTarget);
ccbSetSceneNodeProperty(player,"FieldOfView_Degrees", saveFov);
ccbSetCopperCubeVariable("system.soundvolume",saveVol)

var enemy1=ccbGetSceneNodeFromName("Enemy1");
var saveE1Position =ccbGetCopperCubeVariable("saveE1Position");
ccbSetSceneNodeProperty(enemy1,"Position", saveE1Position);

I would leave like 50ms min between loading standard variables and updating the internal variables via javascript so it gets done at the right time...


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (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