The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Having trouble with Save and Load Game Function, I have save game code but the load code isnt showing the amounts Of so
Rating  4
AngusmcFangus
post Jan 4 2017, 03:31 PM
Post #1


Unregistered









I have a save and load function with a button.

here are the functions for the save and load

function Save() {
localStorage.setItem("cash", cash);
localStorage.setItem("god", god);

}

function Load() {
cash = localStorage.getItem("cash", cash);
cash = parseInt(cash);
god = localStorage.getItem("god", god);
god = parseInt(god);
document.getElementById('text').value = god;
document.getElementById('text').value = cash;
}



The Load is the one I am having a problem with.

It works in the sense that it recognizes that it saved the item, but it doesn't update the amount it has
Ex
Buy God
God Cost 1000000
God's 0

yet even when it says that It knows there is something there. When I buy another god it does this

Buy God
God Cost 1440000
God's 2


Here is the God Function and button

Button

<a href="#"><button style="background-color: transparent;color: white"button onclick="buygod()">Buy Candy God</button><span style="font-size:12px;cursor:pointer"><br /><p3> There Can only be one god... Right?<p3>
<br />
Candy God's: <span id="god">0</span>
<br />
Candy God Cost: $ <span id="godCost">1000000</span>
<br /></a>

Function

var god = 0;

function buygod(){
var godCost = Math.floor(1000000 * Math.pow(1.2,god)); //works out the cost of this cursor
if(cash >= godCost){ //checks that the player can afford the cursor
god = god + 1; //increases number of cursors
cash = cash - godCost; //removes the cookies spent
document.getElementById('god').innerHTML = god; //updates the number of cursors for the user
document.getElementById('cash').innerHTML = cash; //updates the number of cookies for the user
};
var nextCost = Math.floor(1000000 * Math.pow(1.2,god)); //works out the cost of the next cursor
document.getElementById('godCost').innerHTML = nextCost; //updates the cursor cost for the user
};

window.setInterval(function(){

candyClick(god);

}, .000000000000001);


Before the save

Attached Image

after saving, rerunning the code, and loading

Attached Image

I ran out of space for another screen shot, but after buying one more upgrade it jumps up to two.



Any Suggestions and or answers would be very helpful!

This post has been edited by AngusmcFangus: Jan 4 2017, 03:44 PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 30th May 2024 - 05:57 PM