...

View Full Version : Timer Problems in Javascript



Stevesparty
08-19-2007, 08:00 PM
I have a series of timers I am using for an online game and when I try to add another timer I cannot get it to work. All the other timers seem to work fine but not the new one.





<head>
</head>
<body bgcolor="black">








<a class="one" href="javascript:maReset(2)"><font color="#ff0000" size="2">90</font></a><font color="#ffffff" size="2"> - </font>
<a class="one" href="javascript:maReset(12)"><font color="#ff0000" size="2">60</font></a><font color="#ffffff" size="2"> - </font>
<a class="one" href="javascript:maReset(13)"><font color="#ff0000" size="2">45</font></a>
<a class="one" href="javascript:setFlight()"><span id="airtim"><font color="#ffffff">Travel Time!</font></span></a></td>




<a class="one" href="javascript:maReset(4)"><font color="#ff0000" size="2">Whack</font></a>
<a class="one" href="javascript:setWhack()"><span id="watim"><font color="#ffffff">Whack Time!</font></span></a>

</td>


<a class="one" href="javascript:maReset(5)"><font color="#ff0000" size="2">Aggravated</font></a></font><font size="1"><font color="#ffffff" size="2"> - </font>
</font>
<a class="one" href="javascript:maReset(6)"><font color="#ff0000" size="2"> Study / Train</font></a><font color="#ffffff" size="2"> - </font>
<a class="one" href="javascript:maReset(10)"><font color="#ff0000" size="2">Work DH</font></a>
<a class="one" href="javascript:maReset(10)"><font color="#ff0000" size="2"></font></a>
<a class="one" href="javascript:setAgg()"><span id="aggtim"><font color="#ffffff">Aggravated Time!</font></span></a> </td></tr><tr>


<a class="one" href="javascript:maReset(1)"><font color="#ff0000" size="2">Earn</font></a>
<a class="one" href="javascript:setEarn()"><span id="earntim"><font color="#ffffff">Earn Time!</font></span></a>


<a class="one" href="javascript:maReset(9)"><font color="#ff0000" size="2">Case</font></a>
<a class="one" href="javascript:setCase()"><span id="castim"><font color="#ffffff">Case Time!</font></span></a>




<a class="one" href="javascript:maReset(7)"><font color="#ff0000" size="2">Launder</font></a>
<a class="one" href="javascript:setLaunder()"><span id="lautim"><font color="#ffffff">Launder Time!</font></span></a>

</td>



<a class="one" href="javascript:maReset(8)"><font color="#ff0000" size="2">Push Drugs</font></a><font color="#ffffff" size="2"> - </font>
<a class="one" href="javascript:maReset(11)"><font color="#ff0000" size="2">BM</font>
<a class="one" href="javascript:setDrugs()"><span id="drgtim"><font color="#ffffff">Drugs/BM Time!</font></span></a>
<br>

<a class="one" href="javascript:maReset(14)"><font color="#ff0000" size="2">LogOut</font>
<a class="one" href="javascript:setlogout()"><span id="logouttim"><font color="#ffffff">Time to Logout</font></span></a>

<a class="one" href="javascript:maReset(15)"><font color="#ff0000" size="2">Train</font>
<a class="one" href="javascript:settrain()"><span id="Traintim"><font color="#ffffff">Time to Train</font></span></a>


</td>

</tr>






<script language="JavaScript">
<!--



var maEarn=(0); var maFly=(0); var maWhack=(0); var maAgg=(0); var maLaunder=(0); var maDrugs=(0); var maCase=(0); var malogout=(0); var matrain=(0);
refreshID=setInterval("maRefresh()",1000);

function maInitialize() {
warning.innerHTML=maHeader;
main.style.visibility="visible";
maRefresh();
}


function maReset(mType) {
if (mType==1) { maEarn=(2.1*60); };

if (mType==2) { maFly=(90*60) };
if (mType==12) { maFly=(60*60) };
if (mType==13) { maFly=(45*60) };

if (mType==4) { maWhack=(60*60); };

if (mType==5) { maAgg=(30*60); };
if (mType==6) { maAgg=(20*60); };
if (mType==10) { maAgg=(15*60); };

if (mType==7) { maLaunder=(20*60); };

if (mType==8) { maDrugs=(60*60); };
if (mType==11) { maDrugs=(15*60); };

if (mType==9) { maCase=(3*60); };

if (mType==14) { malogout=(60*60); };

if (mType==15) { matrain=(20*60); };
}

function maRefresh() {

maEarn=maEarn-1; maFly=maFly-1; maWhack=maWhack-1; maAgg=maAgg-1; maLaunder=maLaunder-1; maDrugs=maDrugs-1; maCase=maCase-1; malogout=malogout-1; matrain=matrain-1;



var mTm=parseInt(maFly/60);
var mTh=parseInt(mTm/60);
var mTs=parseInt(maFly-(mTm*60));
mTm=parseInt(mTm-(mTh*60));

if(maFly <=0){
document.getElementById("airtim").innerHTML="<FONT COLOR='FFFFFF'>Travel Time!</FONT>";}else{
document.getElementById("airtim").innerHTML = "<FONT COLOR='gold'>"+mTh+"hrs"+mTm+"min,"+mTs+"sec</FONT>";
}

if(maFly ==0){
alert("Travel Time!");}





var mWm=parseInt(maWhack/60);
var mWs=parseInt(maWhack-(parseInt(maWhack/60)*60));

if(maWhack <=0){
document.getElementById("watim").innerHTML="<FONT COLOR='FFFFFF'>Whack Time!</FONT>";}else{
document.getElementById("watim").innerHTML = "<FONT COLOR='gold'>"+mWm+"min,"+mWs+"sec</FONT>";
}
if(maWhack ==0){
alert("Whack Time!");
}



var mPm=parseInt(maEarn/60);
var mPs=parseInt(maEarn-(parseInt(maEarn/60)*60))

if(maEarn <=0){
document.getElementById("earntim").innerHTML="<FONT COLOR='FFFFFF'>Earn Time!</FONT>";}else{
document.getElementById("earntim").innerHTML = "<FONT COLOR='gold'>"+mPm+"min,"+mPs+"sec</FONT>";
}

if(maEarn ==0){alert("Earn Time!")
}



var mFm=parseInt(maAgg/60);
var mFs=parseInt(maAgg-(parseInt(maAgg/60)*60));

if(maAgg <=0){
document.getElementById("aggtim").innerHTML="<FONT COLOR='FFFFFF'>Aggravated Time!</FONT>";}else{
document.getElementById("aggtim").innerHTML = "<FONT COLOR='gold'>"+mFm+"min,"+mFs+"sec</FONT>";
}
if (maAgg ==0){
alert("Aggravated Time!")
;}



var mLm=parseInt(maLaunder/60);
var mLs=parseInt(maLaunder-(parseInt(maLaunder/60)*60));

if(maLaunder <=0){
document.getElementById("lautim").innerHTML="<FONT COLOR='FFFFFF'>Launder Time!</FONT>";}else{
document.getElementById("lautim").innerHTML = "<FONT COLOR='gold'>"+mLm+"min,"+mLs+"sec</FONT>";
}
if (maLaunder ==0){
alert("Launder Time!");}




var mDm=parseInt(maDrugs/60);
var mDs=parseInt(maDrugs-(parseInt(maDrugs/60)*60));

if(maDrugs <=0){
document.getElementById("drgtim").innerHTML="<FONT COLOR='FFFFFF'>Drugs/BM Time!</FONT>";}else{
document.getElementById("drgtim").innerHTML = "<FONT COLOR='gold'>"+mDm+"min,"+mDs+"sec</FONT>";
}
if (maDrugs ==0){
alert("Time to push drugs/BM goods!");}


var mFm=parseInt(malogout/60);
var mFs=parseInt(malogout-(parseInt(malogout/60)*60));

if(malogout <=0){
document.getElementById("logouttim").innerHTML="<FONT COLOR='FFFFFF'>Time to Logout</FONT>";}else{
document.getElementById("logouttim").innerHTML = "<FONT COLOR='gold'>"+mFm+"min,"+mFs+"sec</FONT>";
}
if (malogout ==0){alert("Time to Logout!")}


var mPm=parseInt(maCase/60);
var mPs=parseInt(maCase-(parseInt(maCase/60)*60))

if(maCase <=0){
document.getElementById("castim").innerHTML="<FONT COLOR='FFFFFF'>Case Time!</FONT>";}else{
document.getElementById("castim").innerHTML = "<FONT COLOR='gold'>"+mPm+"min,"+mPs+"sec</FONT>";
}
if(maCase ==0){alert=("Case Time!");}

var mLm=parseInt(matrain/60);
var mLs=parseInt(matrain-(parseInt(matrain/60)*60))

if(matrain <=0){
document.getElementById("traintim").innerHTML="<FONT COLOR='FFFFFF'>Train Time!</FONT>";}else{
document.getElementById("traintim").innerHTML = "<FONT COLOR='gold'>"+mBm+"min,"+mBs+"sec</FONT>";
}
if(matrain ==0){alert("Train Time!");}
}
//close refresh




function setFlight() {
var petim=prompt("Minutes Until You Can Travel Again:",parseInt(90));
maFly=petim*60;
}

function setWhack() {
var petim=prompt("Minutes Until You Can Whack Again:",parseInt(60));
maWhack=petim*60;
}


function setEarn() {
var petim=prompt("Minutes Until You Can Earn Again:",parseInt(.20));
maEarn=petim*60;
}



function setAgg() {
var petim=prompt("Minutes Until You Can Commit An Aggravated Crime Again:",parseInt(30));
maAgg=petim*60;
}


function setLaunder() {
var petim=prompt("Minutes Until You Can Launder Again:",parseInt(20));
maLaunder=petim*60;
}


function setDrugs() {
var petim=prompt("Minutes Until You Can Push Drugs/BM Goods Again:",parseInt(60));
maDrugs=petim*60;
}

function setCase() {
var petim=prompt("Minutes Until You Can Do Another Case:",parseInt(3));
maCase=petim*60;
}
function setlogout() {
var petim=prompt("Minutes till you logout:",parseInt(60));
malogout=petim*60;
}
function settrain() {
var petim=prompt("Minutes till you can Train:",parseInt(20));
matrain=petim*60;
}
// -->

</script>
</body>

The timer which isn't working is the "settrain" timer. I must have made a mistake somewhere in that mess but I honestly can't find where I messed up. Any help would be appreciated, Thanks!

rwedge
08-19-2007, 09:36 PM
'mBm' and 'mBs' are not defined

document.getElementById("traintim").innerHTML = "<FONT COLOR='gold'>"+mBm+"min,"+mBs+"sec</FONT>";

Stevesparty
08-19-2007, 09:49 PM
I think I changed it so that it is defined:

var mBm=parseInt(matrain/60);
var mBs=parseInt(matrain-(parseInt(matrain/60)*60))

if(matrain <=0){
document.getElementById("traintim").innerHTML="<FONT COLOR='FFFFFF'>Train Time!</FONT>";}else{
document.getElementById("traintim").innerHTML = "<FONT COLOR='gold'>"+mBm+"min,"+mBs+"sec</FONT>";
}
if(matrain ==0){alert("Train Time!");}
It, however, still doesn't work. Is there anything else I have to do to define them?

rwedge
08-19-2007, 10:12 PM
matrain counts for me

Stevesparty
08-20-2007, 12:46 AM
Thats weird because it definitely doesn't count for me. Can you post a copy of the code that works for you?

rwedge
08-20-2007, 02:56 AM
<head>
</head>
<body bgcolor="black">

<table>
<tr>
<td>
<a class="one" href="javascript:maReset(2)"><font color="#ff0000" size="2">90</font></a><font color="#ffffff" size="2"> - </font>
<a class="one" href="javascript:maReset(12)"><font color="#ff0000" size="2">60</font></a><font color="#ffffff" size="2"> - </font>
<a class="one" href="javascript:maReset(13)"><font color="#ff0000" size="2">45</font></a>
<a class="one" href="javascript:setFlight()"><span id="airtim"><font color="#ffffff">Travel Time!</font></span></a>
<a class="one" href="javascript:maReset(4)"><font color="#ff0000" size="2">Whack</font></a>
<a class="one" href="javascript:setWhack()"><span id="watim"><font color="#ffffff">Whack Time!</font></span></a>
<a class="one" href="javascript:maReset(5)"><font color="#ff0000" size="2">Aggravated</font></a></font><font color="#ffffff" size="2"> - </font>
<a class="one" href="javascript:maReset(6)"><font color="#ff0000" size="2"> Study / Train</font></a><font color="#ffffff" size="2"> - </font>
<a class="one" href="javascript:maReset(10)"><font color="#ff0000" size="2">Work DH</font></a>
<a class="one" href="javascript:maReset(10)"><font color="#ff0000" size="2"></font></a>
<a class="one" href="javascript:setAgg()"><span id="aggtim"><font color="#ffffff">Aggravated Time!</font></span></a>
<a class="one" href="javascript:maReset(1)"><font color="#ff0000" size="2">Earn</font></a>
<a class="one" href="javascript:setEarn()"><span id="earntim"><font color="#ffffff">Earn Time!</font></span></a>
</td>
</tr>
<tr>
<td>
<a class="one" href="javascript:maReset(9)"><font color="#ff0000" size="2">Case</font></a>
<a class="one" href="javascript:setCase()"><span id="castim"><font color="#ffffff">Case Time!</font></span></a>
<a class="one" href="javascript:maReset(7)"><font color="#ff0000" size="2">Launder</font></a>
<a class="one" href="javascript:setLaunder()"><span id="lautim"><font color="#ffffff">Launder Time!</font></span></a>
<a class="one" href="javascript:maReset(8)"><font color="#ff0000" size="2">Push Drugs</font></a><font color="#ffffff" size="2"> - </font>
<a class="one" href="javascript:maReset(11)"><font color="#ff0000" size="2">BM</font>
<a class="one" href="javascript:setDrugs()"><span id="drgtim"><font color="#ffffff">Drugs/BM Time!</font></span></a>
<a class="one" href="javascript:maReset(14)"><font color="#ff0000" size="2">LogOut</font>
<a class="one" href="javascript:setlogout()"><span id="logouttim"><font color="#ffffff">Time to Logout</font></span></a>
<a class="one" href="javascript:maReset(15)"><font color="#ff0000" size="2">Train</font>
<a class="one" href="javascript:settrain()"><span id="traintim"><font color="#ffffff">Time to Train</font></span></a>
</td>
</tr>
<table>

<script type="text/javascript">
var maEarn=(0), maFly=(0), maWhack=(0), maAgg=(0), maLaunder=(0), maDrugs=(0), maCase=(0), malogout=(0), matrain=(0);
refreshID=setInterval("maRefresh()",1000);
function maInitialize() {
warning.innerHTML=maHeader;
main.style.visibility="visible";
maRefresh();
}
function maReset(mType) {
if (mType==1) { maEarn=(2.1*60); };
if (mType==2) { maFly=(90*60) };
if (mType==12) { maFly=(60*60) };
if (mType==13) { maFly=(45*60) };
if (mType==4) { maWhack=(60*60); };
if (mType==5) { maAgg=(30*60); };
if (mType==6) { maAgg=(20*60); };
if (mType==10) { maAgg=(15*60); };
if (mType==7) { maLaunder=(20*60); };
if (mType==8) { maDrugs=(60*60); };
if (mType==11) { maDrugs=(15*60); };
if (mType==9) { maCase=(3*60); };
if (mType==14) { malogout=(60*60); };
if (mType==15) { matrain=(20*60); };
}
function maRefresh() {
maEarn=maEarn-1;
maFly=maFly-1;
maWhack=maWhack-1;
maAgg=maAgg-1;
maLaunder=maLaunder-1;
maDrugs=maDrugs-1;
maCase=maCase-1;
malogout=malogout-1;
matrain=matrain-1;
var mTm=parseInt(maFly/60), mTh=parseInt(mTm/60), mTs=parseInt(maFly-(mTm*60));
mTm=parseInt(mTm-(mTh*60));
if(maFly <=0){
document.getElementById("airtim").innerHTML="<font color='FFFFFF'>Travel Time!</font>";
} else {
document.getElementById("airtim").innerHTML = "<font color='gold'>"+mTh+"hrs"+mTm+"min,"+mTs+"sec</font>";
}
if(maFly ==0){
alert("Travel Time!");
}
var mWm=parseInt(maWhack/60);
var mWs=parseInt(maWhack-(parseInt(maWhack/60)*60));
if(maWhack <=0){
document.getElementById("watim").innerHTML="<font color='FFFFFF'>Whack Time!</font>";
} else {
document.getElementById("watim").innerHTML = "<font color='gold'>"+mWm+"min,"+mWs+"sec</font>";
}
if(maWhack ==0){
alert("Whack Time!");
}
var mPm=parseInt(maEarn/60);
var mPs=parseInt(maEarn-(parseInt(maEarn/60)*60))
if(maEarn <=0){
document.getElementById("earntim").innerHTML="<font color='FFFFFF'>Earn Time!</font>";
} else {
document.getElementById("earntim").innerHTML = "<font color='gold'>"+mPm+"min,"+mPs+"sec</font>";
}
if(maEarn ==0){alert("Earn Time!")
}
var mFm=parseInt(maAgg/60);
var mFs=parseInt(maAgg-(parseInt(maAgg/60)*60));
if(maAgg <=0){
document.getElementById("aggtim").innerHTML="<font color='FFFFFF'>Aggravated Time!</font>";
} else {
document.getElementById("aggtim").innerHTML = "<font color='gold'>"+mFm+"min,"+mFs+"sec</font>";
}
if (maAgg ==0){
alert("Aggravated Time!");
}
var mLm=parseInt(maLaunder/60);
var mLs=parseInt(maLaunder-(parseInt(maLaunder/60)*60));
if(maLaunder <=0){
document.getElementById("lautim").innerHTML="<font color='FFFFFF'>Launder Time!</font>";
} else {
document.getElementById("lautim").innerHTML = "<font color='gold'>"+mLm+"min,"+mLs+"sec</font>";
}
if (maLaunder ==0){
alert("Launder Time!");}
var mDm=parseInt(maDrugs/60);
var mDs=parseInt(maDrugs-(parseInt(maDrugs/60)*60));
if(maDrugs <=0){
document.getElementById("drgtim").innerHTML="<font color='FFFFFF'>Drugs/BM Time!</font>";
} else {
document.getElementById("drgtim").innerHTML = "<font color='gold'>"+mDm+"min,"+mDs+"sec</font>";
}
if (maDrugs ==0){
alert("Time to push drugs/BM goods!");
}
var mFm=parseInt(malogout/60);
var mFs=parseInt(malogout-(parseInt(malogout/60)*60));
if(malogout <=0){
document.getElementById("logouttim").innerHTML="<font color='FFFFFF'>Time to Logout</font>";
} else {
document.getElementById("logouttim").innerHTML="<font color='gold'>"+mFm+"min,"+mFs+"sec</font>";
}
if (malogout ==0){alert("Time to Logout!")}
var mPm=parseInt(maCase/60);
var mPs=parseInt(maCase-(parseInt(maCase/60)*60))
if(maCase <=0){
document.getElementById("castim").innerHTML="<font color='FFFFFF'>Case Time!</font>";
} else {
document.getElementById("castim").innerHTML = "<font color='gold'>"+mPm+"min,"+mPs+"sec</font>";
}
if(maCase ==0){
alert("Case Time!");
}
var mLm=parseInt(matrain/60);
var mLs=parseInt(matrain-(parseInt(matrain/60)*60))
var mBm=parseInt(matrain/60);
var mBs=parseInt(matrain-(parseInt(matrain/60)*60))
if(matrain <=0){
document.getElementById("traintim").innerHTML="<font color='FFFFFF'>Train Time!</font>";}else{
document.getElementById("traintim").innerHTML = "<font color='gold'>"+mBm+"min,"+mBs+"sec</font>";
}
if(matrain ==0){
alert("Train Time!");}
} //close refresh
function setFlight() {
var petim=prompt("Minutes Until You Can Travel Again:",parseInt(90));
maFly=petim*60;
}
function setWhack() {
var petim=prompt("Minutes Until You Can Whack Again:",parseInt(60));
maWhack=petim*60;
}
function setEarn() {
var petim=prompt("Minutes Until You Can Earn Again:",parseInt(.20));
maEarn=petim*60;
}
function setAgg() {
var petim=prompt("Minutes Until You Can Commit An Aggravated Crime Again:",parseInt(30));
maAgg=petim*60;
}
function setLaunder() {
var petim=prompt("Minutes Until You Can Launder Again:",parseInt(20));
maLaunder=petim*60;
}
function setDrugs() {
var petim=prompt("Minutes Until You Can Push Drugs/BM Goods Again:",parseInt(60));
maDrugs=petim*60;
}
function setCase() {
var petim=prompt("Minutes Until You Can Do Another Case:",parseInt(3));
maCase=petim*60;
}
function setlogout() {
var petim=prompt("Minutes till you logout:",parseInt(60));
malogout=petim*60;
}
function settrain() {
var petim=prompt("Minutes till you can Train:",parseInt(20));
matrain=petim*60;
}
</script>
</body>

Stevesparty
08-20-2007, 03:38 AM
Still doesn't work... Could there be another problem (browser etc)?

rwedge
08-20-2007, 04:10 AM
It did run in IE until the case alert was called. It did not work for FF because the capital T in traintim.

Stevesparty
08-20-2007, 08:03 AM
It works!! Thank you very much for your help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum