saving data simplified?

Discussion and feedback on Construct 2

Post » Mon Feb 03, 2014 7:26 pm

[quote]If you need access to the files, or want to specify their folder, then I'd suggest creating a manual storage system using the Node-Webkit file management actions and expressions. Be sure to obfuscate the contents in some way, otherwise users will be able to simply edit their own save data.[/quote]

Sadly, I couldn't figure out how to use that object. It didn't seem as simple to use. Are there any tutorials?

I have no clue how to obfuscate, either. In MMF, the contents were automatically obfuscated (only in Named Variable Object, not in ini++). I made one game using ini++ and its save file is editable.DialgaBrite2014-02-03 19:30:42
B
15
S
2
Posts: 103
Reputation: 1,178

Post » Mon Feb 03, 2014 7:32 pm

If the plan is to write the files to the app folder then WebStorage is entirely useless; why are you guys pushing it so much?

You basically want to do this:

>Make a global var called Root

+Is in preview
-Set Root to <Path to write files to>

+Is NOT in preview
-Set Root to NodeWebkit.AppFolder

Then, if using a dictionary to store save data...

+On Function "SaveGame" (or whatever)
-Write file to Root & <File Name> with contents Dictionary.AsJSON


The Root global var is used because, in preview, AppFolder returns the node webkit folder in the C2 install directory. More info here.

(Note all this is from memory so you might want to check out the manual if there are any problems)MadFactory2014-02-03 19:38:55
Image
B
242
S
29
G
13
Posts: 1,787
Reputation: 18,685

Post » Mon Feb 03, 2014 7:34 pm

[QUOTE=MadFactory] If the plan is to write the files to the app folder then WebStorage is entirely useless; why are you guys pushing it so much?

You basically want to do this:

>Make a global var called Root

+Is in preview
-Set Root to <Path to write files to>

+Is NOT in preview
-Set Root to NodeWebkit.AppFolder

Then, if using a dictionary to store save data...

+On Function "SaveGame" (or whatever)
-Write file to Root & <File Name> with contents Dictionary.AsJSON[/QUOTE]

OMG THANK YOU! I am going to try that now. I will let you know how it goes. :)

edit: would you mind giving an equally helpful description of how to load it from the file when the game starts up?DialgaBrite2014-02-03 19:42:40
B
15
S
2
Posts: 103
Reputation: 1,178

Post » Mon Feb 03, 2014 7:48 pm

Very simple! You just use the dictionary's "Load" action, then enter Root & <FileName>. The dictionary will then be exactly as it was when saving.
Image
B
242
S
29
G
13
Posts: 1,787
Reputation: 18,685

Post » Mon Feb 03, 2014 8:02 pm

[QUOTE=MadFactory] Very simple! You just use the dictionary's "Load" action, then enter Root & <FileName>. The dictionary will then be exactly as it was when saving.[/QUOTE]


here's what I have got so far:



either the save or load isn't working, not sure which.

Here's what happens.

1. Press K. sound for key "one" <=0 plays.
2. Press L. sound for saving plays, though I don't know if it actually saved. But it definitely added 1 to the key "one" because <see number 3>.
3. Press K again. Sound for key "one" > 0 plays.
4. Close game and reopen.
5. Press K again. Sound for key one <=0 played, so it either didn't save or it didn't load. or both. :(


edit: just realized that the file itself was not created, so it looks like it didn't save. Do I have to create the file manually?DialgaBrite2014-02-03 20:15:29
B
15
S
2
Posts: 103
Reputation: 1,178

Post » Mon Feb 03, 2014 8:16 pm

Looks like Root is a number variable, but it should be a text variable! Double click it and change that in the drop-down menu.

Also you might want to add more than just "C:\" but it depends...For example, if my project folder was on my desktop I would set Root, in preview, to "C:" & NodeWebkit.UserFolder & "Desktop\Project\"

You might want to set a text object to Root to see exactly what it returns (or check it in the debugger) then look in that path to see if the file was created or not.MadFactory2014-02-03 20:19:12
Image
B
242
S
29
G
13
Posts: 1,787
Reputation: 18,685

Post » Mon Feb 03, 2014 8:26 pm

[QUOTE=MadFactory] Looks like Root is a number variable, but it should be a text variable! Double click it and change that in the drop-down menu.

Also you might want to add more than just "C:\" but it depends...For example, if my project folder was on my desktop I would set Root, in preview, to "C:" & NodeWebkit.UserFolder & "Desktop\Project\"

You might want to set a text object to Root to see exactly what it returns (or check it in the debugger) then look in that path to see if the file was created or not.[/QUOTE]

I just changed the root variable to text. The file is created now, but it still isn't loading properly. In my list above, point number 5 still plays the sound for key "one" <=0. However, when opening the file in notepad, it says this: [quote]{"c2dictionary":true,"data":{"one":2}}[/quote]
So it kinda looks like key "one" is being saved (it probably equals 2 because I pressed L two times), but isn't being loaded.DialgaBrite2014-02-03 20:27:01
B
15
S
2
Posts: 103
Reputation: 1,178

Post » Tue Feb 04, 2014 9:36 pm

bump :(

@madfactory, are you still there?
B
15
S
2
Posts: 103
Reputation: 1,178

Post » Tue Feb 04, 2014 10:57 pm

In event 4 you need to load the JSON from the file with something like
[code]Dictionary: Load from JSON string NodeWebkit.ReadFile(Root & "savefile.cute")[/code]
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,620

Post » Wed Feb 05, 2014 12:20 am

That worked. this topic is completely solved now, thanks so much both of you! <3
B
15
S
2
Posts: 103
Reputation: 1,178

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: htmlgames, jakezinis and 5 guests