+ 2
How to set and get a value on multiple reruns of a script.
I am trying to store a value in a variable, so that on multiple reruns of my script, I can be able to retrieve the last set value rather than reset it to the same value everytime. Except I override it again with another value in the variable in the storage part of my code. I tried using localStorage.setItem(), but Sololearn seems to have blocked(limited) the usage for users. How can I achieve my goal? Appreciate your answers.
4 odpowiedzi
+ 4
Create separate variables that holds the old values. Assign the values from the other variables to it before you assign new values to them. This will allow you to hold onto both the old values and the new values, and then you can use both for whatever your task is.
+ 4
Cookies and web storage (local and session ones) works only in browser context, never in app' context (this is a limitation of android webView, not of Sololearn app specificaly)... you can obtain the expected behaviour only by opening playground in a web browser (the only else workaround would be to send request to a server where you could store your own script handling storage of your variable... however, think about that server could be a local one -- there's such kind of app existing, or even by run some script to have such local web service on phone or tablet)
0
Will this work even when my script(the same script) reruns?
0
Ok, thanks Visph, that cleared some stuff for me a bit. Well, what I'm trying to do is store the high score of a game I'm making, here on Sololearn and display it to any other player playing and change it only when another player passes it.