Quantcast

Jump to content


Photo

What is wrong with this switch case?


  • Please log in to reply
7 replies to this topic

#1 Metigue

Metigue
  • 689 posts

Posted 15 November 2010 - 10:23 AM

function refresh() { switch (GM_getValue('$x', '')) {

case "0": 
if (window.find(":53")) { 
			window.location.reload();
						}
	break;

case "1": 
if (window.find(":10")) {
        window.setTimeout( function() { 
	GM_setValue('$x', '2');
	window.location.reload(); }, 383000);
        }
	break;
case "2":
if (window.find(":53")) {
	GM_setValue('$x', '1');
	window.location.reload(); 
					}
	break;
default:
	GM_setValue('$x', '0');
	go();
	break;
     }
      }

:/ There must be a syntax error because it's not compiling the function, but I can't seem to find it.

Edited by Metigue, 15 November 2010 - 10:29 AM.


#2 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 15 November 2010 - 10:25 AM

If you indent your code properly it would be a lot easier to debug. ;)

#3 Metigue

Metigue
  • 689 posts

Posted 15 November 2010 - 10:28 AM

If you indent your code properly it would be a lot easier to debug. ;)


Shup, it's not that bad. xD there are a lot of people far worse than me at that.

#4 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 15 November 2010 - 10:35 AM

I went through your code, and fixed the tabbing so i could see it easier... but i could not find any syntax errors (i do know javascript)... The only thing i can think of is somewhere in the neopets pages, its finding ":10" and the timeout was engaged...

Fixed Tabs:
Spoiler


~Cody

Shup, it's not that bad. xD there are a lot of people far worse than me at that.


:p to people who program in python indenting is everything due to it being indent sensitive :p So no... anyone who programs in python is much better than you (see above)

#5 Metigue

Metigue
  • 689 posts

Posted 15 November 2010 - 10:37 AM

I went through your code, and fixed the tabbing so i could see it easier... but i could not find any syntax errors (i do know javascript)... The only thing i can think of is somewhere in the neopets pages, its finding ":10" and the timeout was engaged...

Fixed Tabs:

Spoiler


~Cody



:p to people who program in python indenting is everything due to it being indent sensitive :p So no... anyone who programs in python is much better than you (see above)




oooh it looks so neat now! xD

Hm, Yeah, no it's not that the function doesn't work.

It's just straight up now compiling, so when I try and call it later on in the code, it goes "Refresh is undefined"

#6 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 15 November 2010 - 10:42 AM

Lol, see :p its much easier to read now...

Anyways, try renaming the function, maybe the variable gets used somewhere else and then gets deleted...
~Cody

#7 Faval

Faval
  • 637 posts

Posted 15 November 2010 - 11:05 AM

It's just straight up now compiling, so when I try and call it later on in the code, it goes "Refresh is undefined"


Hmm, did you call refresh() and not Refresh() ? functions are case sensitive.

#8 Metigue

Metigue
  • 689 posts

Posted 15 November 2010 - 12:36 PM

Hmm, did you call refresh() and not Refresh() ? functions are case sensitive.


Yeah, no. I found the problem

It was that, in the part of refresh I didn't show you (Just one line)

I had a setTimeout that was calling refresh from within itself, I was using this to loop it with a delay.

I removed it and it compiled fine, so after a lot of brainstorming, I replaced my entire refresh function with this:

function refresh() {

if (GM_getValue('$x') == 2) { 
	window.setInterval(function() {
		if (window.find(":53")) {
			GM_setValue('$x', '1');
			window.location.reload();
			}
        }, 100);
	} else { 
	
	if (GM_getValue('$x') == 1) { 
		window.setInterval(function() {
			if (window.find(":10")) {
				window.setTimeout(function(){ 
					GM_setValue('$x', '2');
					window.location.reload();
				}, 383000);
			}
		} , 100);
	} 
			
	if (GM_getValue('$x') == 0) {
		window.setInterval(function() {
			if (window.find(":53")) {
				window.location.reload(); 
			}
		}, 100);
	}
}

It now works perfectly :)


2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users