Advertisement:

Author Topic: javascript help  (Read 3767 times)

Offline SA™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,954
  • (T)ogether (E)veryone (A)chieves (M)ore
    • DenotsNiaga on Facebook
    • SAChatBar
javascript help
« on: September 05, 2009, 02:01:36 AM »
im using this to countdown till whe user gets gold

Code: [Select]
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
Quote
My allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,614
    • StoryBB/StoryBB on GitHub
Re: javascript help
« Reply #1 on: September 05, 2009, 07:19:20 AM »
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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline SA™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,954
  • (T)ogether (E)veryone (A)chieves (M)ore
    • DenotsNiaga on Facebook
    • SAChatBar
Re: javascript help
« Reply #2 on: September 05, 2009, 09:17:01 PM »
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
Quote
My allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,614
    • StoryBB/StoryBB on GitHub
Re: javascript help
« Reply #3 on: September 05, 2009, 09:18:49 PM »
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?
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline SA™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,954
  • (T)ogether (E)veryone (A)chieves (M)ore
    • DenotsNiaga on Facebook
    • SAChatBar
Re: javascript help
« Reply #4 on: September 05, 2009, 09:22:02 PM »
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
Quote
My allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,614
    • StoryBB/StoryBB on GitHub
Re: javascript help
« Reply #5 on: September 05, 2009, 09:39:24 PM »
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?
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline SA™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,954
  • (T)ogether (E)veryone (A)chieves (M)ore
    • DenotsNiaga on Facebook
    • SAChatBar
Re: javascript help
« Reply #6 on: September 06, 2009, 01:50:32 PM »
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
Quote
My allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,614
    • StoryBB/StoryBB on GitHub
Re: javascript help
« Reply #7 on: September 06, 2009, 01:55:55 PM »
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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline SA™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,954
  • (T)ogether (E)veryone (A)chieves (M)ore
    • DenotsNiaga on Facebook
    • SAChatBar
Re: javascript help
« Reply #8 on: September 06, 2009, 02:00:30 PM »
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
Quote
My allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,614
    • StoryBB/StoryBB on GitHub
Re: javascript help
« Reply #9 on: September 20, 2009, 12:48:06 PM »
Do you require any further support on this?
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline SA™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,954
  • (T)ogether (E)veryone (A)chieves (M)ore
    • DenotsNiaga on Facebook
    • SAChatBar
Re: javascript help
« Reply #10 on: September 22, 2009, 12:18:19 PM »
na i give up with this
http://samods.github.io/SAChatBar/

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