Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-17-2011, 10:49 PM   PM User | #1
lengman
New to the CF scene

 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
lengman is an unknown quantity at this point
Help with Javascript countdown..

Hi all,

This is my first post on a forum regarding help so I'm sorry in advance.

I currently have a text based MMORPG.

I am trying to create a countdown timer for my functions(Crime, Car Steal and so on)

Code:
    window.setTimeout("Tick()", 1000);

    function Tick() {
        window.setTimeout("Tick()", 1000);
    }
	var Timer;
var TotalSeconds;


function CreateTimer(TimerID, Time) {
    Timer = document.getElementById(TimerID);
    TotalSeconds = Time;
    
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function Tick() {
    TotalSeconds -= 1;
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function UpdateTimer() {
    Timer.innerHTML = TotalSeconds;
}

function Tick() {
    if (TotalSeconds <= 0) {
        alert("Available")
        return;
    }

    TotalSeconds -= 1;
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function UpdateTimer() {
    var Seconds = TotalSeconds;
    
	var Days = Math.floor(Seconds / 86400);
    Seconds -= Days * 86400;
	
    var Hours = Math.floor(Seconds / 3600);
    Seconds -= Hours * (3600);

    var Minutes = Math.floor(Seconds / 60);
    Seconds -= Minutes * (60);


    var TimeStr = ((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds)


    Timer.innerHTML = TimeStr + "Organised Robbery!";
}


function LeadingZero(Time) {

    return (Time < 10) ? "0" + Time : + Time;

}
Any help with regards to this would be greatly appreciated.

Thanks in advance
lengman is offline   Reply With Quote
Old 12-18-2011, 12:18 AM   PM User | #2
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
Most importantly, you can't have multiple functions with the same name in the same scope. Change that, so the code is sensible enough for us to see what you're trying to do.

Once you've done that, you might also want to tell us what you expect your code to do vs. what it's actually doing.
__________________
.My new Javascript tutorial site: http://reallifejs.com/
.Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
.Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback
venegal is offline   Reply With Quote
Old 12-18-2011, 12:50 AM   PM User | #3
lengman
New to the CF scene

 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
lengman is an unknown quantity at this point
Thanks for the reply, my knowledge of Javascript = 0.

Basically I was guided through this by a friend who knows very little.

There is a crime timer on my rightmenu. I want that to physically tick down instead of only ever changing when the page is refreshed.
lengman is offline   Reply With Quote
Reply

Bookmarks

Tags
countdown, game, javascript, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:24 AM.


Advertisement
Log in to turn off these ads.