+ 1
Why doesn't the click me button work correct
If you buy one the money buttons, nothing happens, can anyone find whats wrong in my code? https://code.sololearn.com/WuU3yGBHAGLO/?ref=app
34 ответов
+ 1
Roel You forgot the # to tell jquery that its an id. so it is looking for tags named mb1 mb2 ect instead of an tag with an id mb1 mb2 ect.
+ 1
I don't know nearly enough jQuery to answer your question, but thats a really nice website you've made! Props to you!
+ 1
Good job! One question, did you come up with all of the design on your own or were you inspired from somewhere else?
0
Just A Rather Ridiculously Long Username thanks very much, its my first real project
0
Just A Rather Ridiculously Long Username The idea of making a clicker game was "stolen" from Cookie Clicker, but to make it look totally grey and let the style be buyable was my idea. I totally designed it from my head, even though it did look a bit different than in my head
0
but i still want to learn how to add storage, because now if you are very far in my game, and you clicking on html/css/js once, you have to start from 0 again
0
Roel Unfortunately on sololearn you cannot use localStorage, indexedDB, or webSQL because they are running the webview in the about:blank context. I can try create an work around if you want to do it or you can host your game which would provide you with a context you can use.
0
Nommer101 but, in case i put it in a html file on my pc, could it use localStorage then, or do i have to host it
0
Roel It works on file://. Its simple:
localStorage.setItem ('money',100);
localStorage.getItem ('money');
0
so if i do that and send it to a friend, he can save it on his pc too?
0
Yes, it will save on the browser so if you use the same browser. Meaning if he plays the game on chrome and then closes it and open it on chrome again on the same pc then he can load the data.
0
Nommer101 is it possible to dont save a pre defined number, something like this: localStorage.setItem('cash',money); to set the value of storage 'cash' to the current amount of money?
0
Roel Yes, thats how it works.
0
Nommer101 thank you very much, that will help a lot in all of my upcoming gaming projects and other projects that need to be saved
0
Nommer101 and i guess its possible to do all the localStorage.getItem's in the window.onload and all the localStorage.setItem's in a save progress button
0
Roel Yes, however you want to use it. You can even have a load button or you could save every minute or second.
0
tnx
0
Nommer101 how does it work with defining variables, if i do this:
window.onload=function(){
localStorage.getItem('money');
}
var money = 0;
vat t = setInterval(save, 1);
function save(t){
localStorage.setItem('money',money);
}
does var money = 0; overwrite the localStorage? Hope there'll come more advanced storage lessons in javascript
0
money = localStorage.getItem ('money');
0
thx