How do I create a cookie or local storage that lasts 1 day?

lightwriter
Using Javascript again... I know (this is becoming more complicated then I thought it would be :P)
So in my game shops restock every day but I need to make it know that the script has run for the day already.
So I assume the only solution is a cookie that expires at midnight...
how would I go about doing this?
I tried this:

var localVal = localStorage.getItem('textcraftday');

if(localVal == null){
alert("Hey!")
// execute the function
}else{
var tempd = new Date();
var str = tempd.getDay() + tempd.getMonth() + tempd.getFullYear();
if(localVal.localeCompare(str) == -1){
//execute function
localStorage.setItem('textcraftday',str);
}
}

The Pixie
I have no idea if cookies work with Quest.

An alternative is to store the date the shop was last restocked. When the player goes into the shop, check the stored date against the current date; if different, restock.

XanMag
I love seeing what people are doing with Quest and their games! I find these forums (this particularly) very interesting. Lightwriter and others are doing things I couldn't imagine making work but I learn a bit with each of these questions. Just an FYI... and it's awesome that the people here are as knowledgable and helpful as they are. Thanks!
Not that my input here is anyway helpful, but, I would have (and thankfully I'm not) tried setting a "day" = x number of turns and then flagged each day (set flag day 1, day 2, day 3, etc) followed by an 'if/then' script that restocks. Ugly for sure!! Lol

Good luck Lightwriter!

lightwriter
XanMag, thanks for the compliment!
However, your method won't work because my game is using a real time clock so 1 day literally is equivalent to 1 day in the real world.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums