Save global variables (score) in an array

Get help using Construct 2

Post » Thu Jan 30, 2014 5:29 pm

Hey there,

I use some global varibles for my score. I wanna save all my global variables in account of the score into an array at the end of my level and load it on level starts.

So if i quit the game and start it new, it should load the value storing in the array.

Can anyone help me?

I want to save all my global variables into an array. And i also want to save the array with the webstorage function. But i don't know exactly how :( I tried the Load/Save function but this causes issues on CocoonJS.

Thanks for helping out!
Last edited by AndreasR on Thu Mar 27, 2014 1:03 pm, edited 1 time in total.
Image Image iTunes: Match3 | Google Play: Match3
B
93
S
32
G
30
Posts: 1,095
Reputation: 27,512

Post » Thu Mar 27, 2014 12:50 pm

Can nobody tell me how i can save my global variables in an array and webstorage?
Image Image iTunes: Match3 | Google Play: Match3
B
93
S
32
G
30
Posts: 1,095
Reputation: 27,512

Post » Thu Mar 27, 2014 5:55 pm

To save the global vars to an array you can set the value for each index in the array, like that:
Array.SetValue at X (0) = var1;
Array.SetValue at X (1) = var 2;
etc.....
WebStorage only save strings(text), so you can do something like that:
for(0 , array.length-1)
Webstorage.SetKey > "key"+loopindex > array[loopindex] //I'm not sure what's the correct action..use the one for saving..I'm on a mac now, can't check it.
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Thu Mar 27, 2014 6:19 pm

Thanks for your input. I'll try it as soon as possible ;)
Image Image iTunes: Match3 | Google Play: Match3
B
93
S
32
G
30
Posts: 1,095
Reputation: 27,512

Post » Thu Mar 27, 2014 7:11 pm

You can convert the array to JSON format, which should then be able to be stored in WebStorage as a string without any problem.

So for the value box of the WebStorage Set Local Value command, you'd just use "[YourArray].asJSON"

Then when you start up your project you just tell [YourArray] to load up the JSON formatted string from your webstorage.

So for the load action on [YourArray] you just put in: WebStorage.LocalValue([ChosenKeyName])
B
4
G
1
Posts: 10
Reputation: 547

Post » Fri Mar 28, 2014 2:33 pm

Hi,
Thanks. I've already have red about this option. But i don't know how to use it.

I usea global text variable "game" with three stats.
  • start
  • play
  • finish

On start of Layout it will be set to "start". Here the game should load the variables stored in the webstorage and array (as far the exist). If the player starts the game with the play button the value will be set to "play". If he dies the value will be set to "finish". Here the game should safe the values of all global variables.

Do you know how to handle this? I currently use the save and load function but this causes many "problems".

Thanks a lot!
Image Image iTunes: Match3 | Google Play: Match3
B
93
S
32
G
30
Posts: 1,095
Reputation: 27,512

Post » Fri Mar 28, 2014 3:24 pm

A few weeks ago I have the same problem. I also don't know how to use the webstorage correctly. There is a lack of examples on this :?
Anyway, here is my capx were I am able to save and retrieve data from the array.

Run the capx, click on some buttons and do save, refresh browser, click load. Voila, data is back!
These are event based, so you can use it for On layout load to do the trick instead of having to push the load button.

ikkez
You do not have the required permissions to view the files attached to this post.
It's time for me to return the favor :)
B
32
S
9
G
8
Posts: 132
Reputation: 4,870

Post » Fri Mar 28, 2014 3:35 pm

Thanks ikke2902,

Great job, but i want to save numbers like scores in an array. Do you also know how to do this??

:)
Image Image iTunes: Match3 | Google Play: Match3
B
93
S
32
G
30
Posts: 1,095
Reputation: 27,512

Post » Fri Mar 28, 2014 3:47 pm

Take a look at this link at the last post https://www.scirra.com/forum/viewtopic.php?f=147&t=98171. Baodingball made a capx for saving scores.
Hope that helps :)
It's time for me to return the favor :)
B
32
S
9
G
8
Posts: 132
Reputation: 4,870

Post » Fri Mar 28, 2014 6:39 pm

Thanks :) I'll look into this :)
Image Image iTunes: Match3 | Google Play: Match3
B
93
S
32
G
30
Posts: 1,095
Reputation: 27,512

Next

Return to How do I....?

Who is online

Users browsing this forum: Lancifer, NyxoGe and 7 guests