Use setTimeout not setInterval, change Abs, which inexplicably crashed Opera(!?)

This commit is contained in:
Eric Fredricksen
2010-07-19 15:29:35 -07:00
parent 7efd80f07d
commit 3fdaffbbcd
+45 -7
View File
@@ -10,7 +10,8 @@ function timeGetTime() {
function StartTimer() { function StartTimer() {
if (!timerid) { if (!timerid) {
lasttick = timeGetTime(); lasttick = timeGetTime();
timerid = setInterval(Timer1Timer, 100); //timerid = setInterval(Timer1Timer, 100);
timerid = setTimeout(Timer1Timer, 100);
} }
} }
@@ -567,7 +568,7 @@ function LPick(list, goal) {
} }
function Abs(x) { function Abs(x) {
return x < 0 ? -x : x; if (x < 0) return -x; else return x;
} }
function WinEquip() { function WinEquip() {
@@ -874,7 +875,10 @@ function Pos(needle, haystack) {
return haystack.indexOf(needle) + 1; return haystack.indexOf(needle) + 1;
} }
var dealing = false;
function Timer1Timer() { function Timer1Timer() {
timerid = null; // Event has fired
if (TaskBar.done()) { if (TaskBar.done()) {
game.tasks += 1; game.tasks += 1;
game.elapsed += TaskBar.Max().div(1000); game.elapsed += TaskBar.Max().div(1000);
@@ -917,7 +921,8 @@ function Timer1Timer() {
if (elapsed < 0) elapsed = 0; if (elapsed < 0) elapsed = 0;
TaskBar.increment(elapsed); TaskBar.increment(elapsed);
} }
lasttick = timeGetTime();
StartTimer();
} }
function FormCreate() { function FormCreate() {
@@ -1061,22 +1066,50 @@ function InputBox(message, def) {
return (i !== null) ? i : def; return (i !== null) ? i : def;
} }
function FormKeyDown(e) { function ToDna(s) {
if (e.which == 13) { // ^M s = s + "";
game.motto = InputBox('Declare your motto!', game.motto); var code = {
Brag('motto'); '0': "AT",
'1': "AG",
'2': "AC",
'3': "TA",
'4': "TG",
'5': "TC",
'6': "GA",
'7': "GT",
'8': "GC",
'9': "CA",
',': "CT",
'.': "CG"
};
var r = "";
for (var i = 0; i < s.length; ++i) {
r += code[s[i]];
if (i && (i % 4) == 0) r += " ";
} }
return r;
}
function FormKeyDown(e) {
if (e.which == 2) { // ^B if (e.which == 2) { // ^B
Brag('brag'); Brag('brag');
//Navigate(GetHostAddr() + 'name=' + UrlEncode(Get(Traits,'Name'))); //Navigate(GetHostAddr() + 'name=' + UrlEncode(Get(Traits,'Name')));
} }
if (e.which == 4) { // ^D
alert("Your character's genome is " + ToDna(game.dna + ""));
}
if (e.which == 7) { // ^G if (e.which == 7) { // ^G
game.guild = InputBox('Choose a guild.\r\rMake sure you undestand the guild rules before you join one. To learn more about guilds, visit http://progressquest.com/guilds.php', game.guild); game.guild = InputBox('Choose a guild.\r\rMake sure you undestand the guild rules before you join one. To learn more about guilds, visit http://progressquest.com/guilds.php', game.guild);
Brag("guild"); Brag("guild");
} }
if (e.which == 13) { // ^M
game.motto = InputBox('Declare your motto!', game.motto);
Brag('motto');
}
if (e.which == 16) { // ^P if (e.which == 16) { // ^P
if (timerid) if (timerid)
StopTimer(); StopTimer();
@@ -1088,6 +1121,11 @@ function FormKeyDown(e) {
quit(); quit();
} }
/*
if (e.which == 20) { // ^T
TaskBar.reposition(TaskBar.Max());
}
*/
} }
function Navigate(url) { function Navigate(url) {