News:

Wondering if this will always be free?  See why free is better.

Main Menu

javascript help

Started by SA™, September 05, 2009, 02:01:36 AM

Previous topic - Next topic

SA™

im using this to countdown till whe user gets gold

echo'<br /><br />
your Next Gold Update will Be In
<div id="countdown"> </div>
<div id="notifier"></div>

<script type="text/javascript">

  var start = ',$modSettings['battle_time'],'
  Number.prototype.toMinutesAndSeconds = function() {
var nbr = Math.floor(this / 60);
return (nbr+":")+(((nbr=(this-(nbr*60)))<10)?"0"+nbr:nbr);
}

function display(seconds, output) {
output.innerHTML = (--seconds).toMinutesAndSeconds();
if(seconds > 0) {
window.setTimeout(function(){display(seconds, output)}, 1000);
}

if(seconds < 11) {
document.getElementById("notifier").innerHTML = "Just 10 seconds to go";
}

if (seconds == 0) {
document.getElementById("notifier").innerHTML = "Time is up baby";
}
}
display(start, document.getElementById("countdown"));

</script>';


it work exept if the user goes away from the page and come back or just refreshes it resets the counter how can i stop that is there any way at all ? please
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Arantor

Not really because Javascript sits in the browser rather than the server.

You need to be looking at pulling the time remaining from the server as well as the overall time between the two so you know how long there is left before the countdown should end.

E.g. time now is x, time to refresh is y: show countdown between the two.

SA™

i take it this is hard todo if you dont know javascript well?
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Arantor

Indeed.

It would be useful to see what the interaction is meant to be between client and server.

You're pushing battle_time into a JS variable called start. How are you determining the time until the next battle?

SA™

i dont know what you mean by that but battle_time varible is how many seconds till the next gold update
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Arantor

What is battle_time itself? Is it just a number that holds the time until the next battle, or is the actual time of the next battle?

SA™

yes it a number that hold the time in seconds to next gold update
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Arantor

Then since you send that every single page, it will always do precisely the same thing.

You need to calculate the timestamp for the next update before you send it to the user.

SA™

hmm ok im gonna go play see what i can do
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Arantor

Do you require any further support on this?

SA™

http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Advertisement: