How do I clear android app data on new update?

Get help using Construct 2

Post » Sat Apr 09, 2016 12:36 am

Here's my issue,

I have an android game which received an update, the app uses a lot of global objects, some have changed since the last version.
Whenever one of my players installs a new update, they don't see certain objects because they were created, moved or deleted on a previous version.
My app saves the state of the game periodically with the system>save option, also saving the position of those global objects.

The only solution I found so far is to manually delete the data of the game in the app settings after installing a new version, but not all users read the updates and/or don't like doing this manually.
Image

Is there a way to do this with events, or have I been too sloppy in my events so this could be avoided in the future?

It's hard to upload a capx because I'm talking about a complete game here.

Thanks
Last edited by Wishy on Sun Apr 10, 2016 11:33 am, edited 1 time in total.
B
25
S
11
G
9
Posts: 136
Reputation: 6,657

Post » Sat Apr 09, 2016 12:37 pm

This is in fact possible via Local Storage. And you don't need to clear the cache, you can just detach the last save file or overwrite it if possible but you cannot delete the save file or clear the cache using html5.

First in your game update project add the "LocalStorage" plugin and add the key named "Version".
Then add this event.

*On start of layout
------> Local Storage.Get key ("Version")

\\*Let's say that the new game update version is "1". If the key "Version" is only available in the update, the key "Version" will be 0 in default**On Item get ("Version")
*If LocalStorage.Item Value < 1
----------> (Detach the save file of connection with your game until it is overwritten by a new one. I don't know how you made your game so it is up to you.)
----------> LocalStorage.Clear
---------> LocalStorage.Set Item value to "1"
Image



The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
55
S
17
G
90
Posts: 1,112
Reputation: 59,147

Post » Sun Apr 10, 2016 11:22 am

@chadorireborn thanks for your reply, believe me, but ofcourse I already tried different approaches of the method you proposed, they sadly do not work.
I have a feeling that global objects behave differently than anything related to LocalStorage and the Savestates.

On a side note, it's actually the data that needs to be deleted, not the cache, gonna change my original question
B
25
S
11
G
9
Posts: 136
Reputation: 6,657

Post » Sun Apr 10, 2016 12:15 pm

@Wishy - Correct me if I am wrong. From my understanding, you said that you have global objects + saved state. And that the global objects were saved in a saved state that was saved periodically. And Global objects are reset when app is closed. Therefore, everything is changed or reset when you re-run the app except if you re-load a saved state. So therefore, you need to overwrite or cut ties with a saved file you made when updated and since when you update an app it is needed to be closed for update so the global objects are reset.

Aren't Global Objects cleared when app is closed and are only recovered when loaded by a saved state. So you need to cut ties or overwrite the saved file. Hope that helps.
Image



The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
55
S
17
G
90
Posts: 1,112
Reputation: 59,147

Post » Sun Apr 10, 2016 1:24 pm

Well the weird thing is, lets say we got v1 and v2.

v2 contains a global object that doesnt even exist in v1.

If a user upgrades to v2, using his savefile from v1, that global object doesnt even load in v2.
even after these events
Image

I assumed, quoting the manual
Savegames don't go there (luckily), they are stored in either WebStorage or IndexedDB

that savegames are stored in the LocalStorage, thus by clearing the LocalStorage, the savegame is cleared too, but that seems not the case.

So, how do I clear a savestate?

At the moment I quickfixed this by using another saveslot.
B
25
S
11
G
9
Posts: 136
Reputation: 6,657

Post » Sun Apr 10, 2016 3:54 pm

I suggest you stop using the system/save option mate, it causes all kinds of problems and is very hard to update games with it.

Luckily a very nice user we have around here @AndreasR , that sometimes takes free requests, who created a save game template a while back when I requested it. It's great, gives you full control over what to save, what not to save, makes it easy to update games, etc.
I've been using it ever since and I am very happy with it!

You can download it by going here it's on page 4, the one called "CONSTRUCT 2 – SAVEGAME FUNCTION (LOCALSTORAGE)".

And if you want to make requests too you can check out his topic over here and if you get lucky/he has time maybe one day he'll do something for you too.

Hope this helps.

P.S. Of course if it's useful to you and you have the funds, I'm sure Andreas would appreciate a small donation on his site. ;)
B
21
S
11
G
6
Posts: 414
Reputation: 5,335

Post » Sun Apr 10, 2016 4:26 pm

@Wishy - Save File is not connected to LocalStorage, Arrays or any plugins. I think I am starting to get your point. What you need is a boolean or variable that tells your game that if your game is updated and overwritten. Actually the event above will actually help and I will modify it below:

-Make a global variable named "Has_SavedFile"- with number value of 0.
-Make a global variable named "Version"- with number value of 0.
-Make a LocalStorage Key named "Version"-
-Make a LocalStorage Key named "Has_SavedFile"-

*On start of layout
------> Local Storage.Check Item Exists ("Version")
------> Local Storage.Check Item Exists ("Has_SavedFile")

*LocalStorage on Item Exists ("Has_SavedFile") or * LocalStorage on Item Set ("Has_SavedFile")
------> Set Global Variable "Has_SavedFile" to LocalStorage.ItemValue

*LocalStorage on Item Exists ("Version") or * LocalStorage on Item Set ("Version")
------> Set Global Variable "Version" to LocalStorage.ItemValue

\\*Let's say that the new game update version is "1". If the key "Version" is only available in the update, the key "Version" will be 0 in default**On Item get ("Version")

*Start of Layout & *If Global Variable "Version" < 1

\\*Detach the save file of connection with your game until it is overwritten by a new one.*\\
----------> Set LocalStorage Key "Has_SavedFile" to 0

\\*Update the values*\ ---------> Set LocalStorage Key "Version" to 1

*If Global Variable "Version" = 1 & On Save
----------->Set Local Storage Key "Has_SavedFile" to 1

*If Global Variable = 1 & *Global Variable "Has_SavedFile" = 1
------------> Enable Load Button

*If Global Variable is not equal to 1 & *Global Variable "Has_SavedFile" is not equal to 1
------------> Disable Load Button


The trick here is to deactivate the load button if the game is updated and not yet overwritten by another saved state. Hope that finally helps.

If my event above isn't clear then I can send you a .capx if you like.
Image



The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
55
S
17
G
90
Posts: 1,112
Reputation: 59,147

Post » Sun Apr 10, 2016 4:47 pm

Sorry for jumping into this topic, not fully aware of your issue @wishy but if you need to check if the game is updated I use following function.

On start of layout
--> LocalStorage - Check Item "version" exists //version is the current project version

if key "version" is missing
--> Set LocalStorage "Key" to "projectversion" // you can access the version with the system expression projectversion

if key "version" exists && LocalStorage.ItemValue != projectversion
--> Call your action you want to do if the version has been changed (on game update)
--> Set LocalStorage Key "versions" to projectversion

Hope this helps!

Thanks @VIKINGS for dragging me into this, I'm glad to help you out, just let me know!

Regards

Andy
Image Image iTunes: Match3 | Google Play: Match3
B
95
S
33
G
30
Posts: 1,099
Reputation: 27,670

Post » Mon Apr 11, 2016 2:13 pm

Thanks for the replies guys.

I already knew how to do everything you guys posted, but I just realised I didn't ask my question correctly.
So my issue was, that I'm unable to use the localstorage to save all progress people made in my game, I got hundreds of persistent object and a load of global objects.
So the only reason to save the state of the game was with the save/load system.

Whenever someone updated the game to a new version, but still used a saved state of the previous version, they had issues with the global objects behaving very weird.

The only solution I found for this is to completely wipe all date from the app, with the downside that they lose all saved data/progress.

Thanks to the replies, I did this through events now, by checking the version and just saving an empty savestate over the previous version's savestate if the version is newer.

HOWEVER, this still doesn't solve my initial issue, I need to find an easy way to store the data of persistent and global objects in the Localstorage. So players don't have to start all over again every major update.

I'm currently testing the "nosave" behavior to see if that might help me, but I'm unsure if that works on objects that didn't exist in a previous version.

I know my problem is perfectly achievable with vars/arrays & localstorage, but I would have to do this for every single object, which makes it almost impossible.
B
25
S
11
G
9
Posts: 136
Reputation: 6,657

Post » Wed Sep 21, 2016 7:55 am

I usually use android data cleaner tool to clear android app data. It can easily clear unwanted data from android phone. Maybe you can also try it, just search it online.
B
2
Posts: 1
Reputation: 152

Next

Return to How do I....?

Who is online

Users browsing this forum: jkmalau, MoscowModder, terence951, vegapomme27 and 9 guests