How do I use the LocalStorage Plugin?

Get help using Construct 2

Post » Thu Sep 10, 2015 8:39 am

irina wrote:@AndreasR

can you help me out please!?

i was used to webstorage (wich was fine by mine opinion) and now its gone and im stuch with this LocalStorage that i just dont get... :(

I have numerical value stored under key "X"
and i want to compare it and see if that value is equal or under "9" and than ad zero infront of it so that value looks like "09"
Websorage had "compare key value" and that worked excellent for me... but no im stuck with this crapy LocalStorage and dont know how to proceed... :(

HELP!!!!


Hello @Irina

I worked out an example for you ;)
https://www.dropbox.com/s/qa48otm534p8k ... .capx?dl=0

This should work for you.

Regards
Andreas
Image Image iTunes: Match3 | Google Play: Match3
B
106
S
39
G
31
Posts: 1,171
Reputation: 29,231

Post » Thu Sep 10, 2015 9:44 am

@AndreasR

Thank you very much!!!
now i see the logic of it.

by the way... i have error in FF when i run your example

Javascript error!
UnknownError
http://192.168.5.2:50002/LocalStorage_plugin.js, line 33 (col 0)

This may be a bug in Construct 2 or a third party plugin or behavior - please report it to the developer following the bug report guidelines. Subsequent errors will be logged to the console.

can you check please?
B
31
S
13
G
2
Posts: 749
Reputation: 5,533

Post » Thu Sep 10, 2015 9:52 am

irina wrote:@AndreasR

Thank you very much!!!
now i see the logic of it.

by the way... i have error in FF when i run your example

Javascript error!
UnknownError
http://192.168.5.2:50002/LocalStorage_plugin.js, line 33 (col 0)

This may be a bug in Construct 2 or a third party plugin or behavior - please report it to the developer following the bug report guidelines. Subsequent errors will be logged to the console.

can you check please?


It works fine on my end. I tested it with Firefox and it works.
But I have the same issue on my MacBook running Windows 10. I'm not sure why this happens only there. I will update C2 and will let you know then.

Regards
Andreas
Image Image iTunes: Match3 | Google Play: Match3
B
106
S
39
G
31
Posts: 1,171
Reputation: 29,231

Post » Thu Sep 10, 2015 10:51 am

@AndreasR

small problem in this logic... :(
this example sucessfuly changes variable but it wont change/correct localstorages value it self (wich is what i need). :(

when i set that global variable from 15 to 9 and set

LS <= 9 | LS set item "example_key" to "0" & str(LocalStorage.ItemValue)

every time i run it adds "0" in front of current value so i end up with value like: 000009

if i add clear storage on start of layout then its allways just "9".....

buhuhuhuhu... i miss my WebStorage... it was so simple and easy... :(


PS: regarding that JS error... i run Latest stabile release 212.2
B
31
S
13
G
2
Posts: 749
Reputation: 5,533

Post » Thu Sep 10, 2015 2:09 pm

irina wrote:@AndreasR

small problem in this logic... :(
this example sucessfuly changes variable but it wont change/correct localstorages value it self (wich is what i need). :(

when i set that global variable from 15 to 9 and set

LS <= 9 | LS set item "example_key" to "0" & str(LocalStorage.ItemValue)

every time i run it adds "0" in front of current value so i end up with value like: 000009

if i add clear storage on start of layout then its allways just "9".....

buhuhuhuhu... i miss my WebStorage... it was so simple and easy... :(


PS: regarding that JS error... i run Latest stabile release 212.2


I'm not quite sure what you want to achieve. If you save the key like "09" it must be a string. But then you cannot compare it with less or equal 9. You must converte it back to an integer first in order to do that.

I updated the example, please check it.
https://www.dropbox.com/s/qa48otm534p8k ... .capx?dl=0
Image Image iTunes: Match3 | Google Play: Match3
B
106
S
39
G
31
Posts: 1,171
Reputation: 29,231

Post » Thu Sep 10, 2015 5:22 pm

@AndreasR
Thank you.
I must say that WebStorage is far better in this particular task.
This was all i needed to write for this to work:
WebStorage local key "x" <= 9 | WebStorage set local key "x" to "0"&WebStorage.LocalValue("x") and that was it, i turned my number "9" to "09".

With LocalStorage for the same task one must use external variables, write functions and write dozen lines of code (not to mention errors that popup in both these examples).
Thas in my book total rubbish... but if @Ashley thinks that this is better who am i to argue? :)

Anyway thank you for all your help.
B
31
S
13
G
2
Posts: 749
Reputation: 5,533

Post » Fri Sep 11, 2015 6:29 am

irina wrote:@AndreasR
Thank you.
I must say that WebStorage is far better in this particular task.
This was all i needed to write for this to work:
WebStorage local key "x" <= 9 | WebStorage set local key "x" to "0"&WebStorage.LocalValue("x") and that was it, i turned my number "9" to "09".

With LocalStorage for the same task one must use external variables, write functions and write dozen lines of code (not to mention errors that popup in both these examples).
Thas in my book total rubbish... but if @Ashley thinks that this is better who am i to argue? :)

Anyway thank you for all your help.


You're welcome ;) Maybe there is an easier way that the one I used, I don't know. Never have needed such a function ;)
LocalStorage isn't much more complicated then WebStorage. It's just diffrent ;)

Let me know if you have further questions, I'm glad to help!

Regards
Andreas
Image Image iTunes: Match3 | Google Play: Match3
B
106
S
39
G
31
Posts: 1,171
Reputation: 29,231

Post » Tue Sep 22, 2015 11:08 am

I just want to add a High Score to my game so if the last score was higher it changes to that new high score and saves it and shows it. If it's not then it stays the same. I could do that easily with Web store but I'm a little lost doing it with local Storage.

Thank you in advance for your help.

AllMark
Check out my latest game RAPID-TAPIT. Get your Fingercise on with this one. A steady Tap is all you need to score points. Lift a finger and see what you can do...

Image

ALLMarkMade Designs
B
41
S
20
G
6
Posts: 367
Reputation: 7,541

Post » Tue Sep 22, 2015 2:28 pm

ALLMarkMade wrote:I just want to add a High Score to my game so if the last score was higher it changes to that new high score and saves it and shows it. If it's not then it stays the same. I could do that easily with Web store but I'm a little lost doing it with local Storage.

Thank you in advance for your help.

AllMark


Hi,

I have a HighScore example in my dropbox folder, just check it out here ;)
https://www.dropbox.com/sh/7afzvo1w0mro ... l--Za?dl=0

Regards
Image Image iTunes: Match3 | Google Play: Match3
B
106
S
39
G
31
Posts: 1,171
Reputation: 29,231

Post » Tue Sep 22, 2015 4:33 pm

Oh yes, thank you, I did see this and take a look at it. Yours is saying web storage and mine only has local storage is there a difference?. Also the button set up is a little confusing because I don't need those so I'm not sure how to work around then.

Damn you guys are good at this stuff...

Thank you
Check out my latest game RAPID-TAPIT. Get your Fingercise on with this one. A steady Tap is all you need to score points. Lift a finger and see what you can do...

Image

ALLMarkMade Designs
B
41
S
20
G
6
Posts: 367
Reputation: 7,541

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests