Jump to content

Javascript End Bracket Issue.


Ang3l0fDeath

Recommended Posts

Alright well i got alot of .js files, one for each big function.

 

My problem im having is 2 files that have no-javascript errors will stop excuting code at the end of a function/page.  This prevents additional functions that run connectively afterwards to continue running.

 

Example:

function start_1(){
     start_2();
     start_4();
     start_5();}

function start_2(){
for (just a loop that works){if(document.getid('whatever'==='found')){

}}
     start_3();
}

 

alright really crappy example but thats simple example of my code, trust me its over 500 lines total with way more functions.  But im running into this problem where start_3(); wont excute, nor start_4(); & start_5();.  There is no errors in any of those.  In fact i can get my script to run the way it should by simply moving start_3(); up into the loop function where the IF found statement is.  But if i move it to excute at the end of the start_2(); it just wont.  Its like running into a deadzone at the end of the script, and once you run into that deadzone it stops all code from running in that section.  So where start_3(); is a dead zone near the end of the function, toward the end of the brackets.  This has happened to 2 of my functions, working around the issue is easy, but it prevents me from getting the desired actions i want.

 

Cause i want start_3(); to run weather or not the Loop finds what it is looking for or not.

Link to comment
Share on other sites

Thats it, nothing shows up.  Script runs just fine all the way down to the last action which is to write a setcookie.  After that i either have the start_3(); behind the setcookie.

 

like so.

 

setCookie('user_server_info',build_server_userbar,365);if(document.getElementById("header_sub")){start_timer();}
}
}
// This is where i want to place if(document.getElementById("header_sub")){start_timer();} but it wont work here. but it works just fine where its at currently, seriously WTF
}


Link to comment
Share on other sites

Well hopefully you understand the whole thing, but ya good luck understanding it.

 

function get_user_info(){

for (i=0; i<(document.getElementsByTagName("table").length); i++){var table_temp=document.getElementsByTagName("table")[i];
/* PM SECTION - START - Includes MP3 AUDIO ALERT IF MESSAGE*/
if(table_temp.rows[0].cells.length==2){
    if(document.getElementsByTagName("table")[i+1].rows[0].cells[0].innerHTML.search("Income")>0
    && document.getElementsByTagName("table")[i+1].rows[0].cells[2].innerHTML.search("Private Messages")>0){
    if(table_temp.rows[0].cells[0].innerHTML.search("i/w/blink.gif")>0){
    /*  CREATING DIV  */ var newdiv = document.createElement('div');
    /*  CREATING DIV  */ newdiv.setAttribute("ID","mp3_mail"); newdiv.style.visibility="hidden";
    /*  CREATING DIV  */ newdiv.style.position="absolute"; /*absolute//relative*/ newdiv.style.left=0; newdiv.style.top=0;
    /*   FINISH DIV   */document.body.appendChild(newdiv);/*   FINISH DIV   */
document.getElementById("mp3_mail").innerHTML="<embed width=0 height=0 hidden='true' autostart='true' volume='100' loop='false' src='"+mp3_mail+"'>";}
/* PM SECTION - END */
/* USER BAR INFO - START */
//alert(document.getElementsByTagName("table")[i+2].rows[0].cells[0].innerHTML);
var user_money  = document.getElementsByTagName("table")[i+2].rows[0].cells[0].innerHTML.replace(/^\s+|\s+$|,/g,"").replace(" $","");
var user_food   = document.getElementsByTagName("table")[i+2].rows[0].cells[2].innerHTML.replace(/^\s+|\s+$|,/g,"").replace(" F","");
var user_power  = document.getElementsByTagName("table")[i+2].rows[0].cells[4].innerHTML.replace(/^\s+|\s+$|,/g,"").replace(" P","");
var user_turns  = document.getElementsByTagName("table")[i+2].rows[0].cells[6].innerHTML.replace(/^\s+|\s+$|,/g,"").replace(" T","");
var user_server = document.getElementsByTagName("table")[i+2].rows[0].cells[8].innerHTML.replace(/^\s+|\s+$|,/g,"");
var user_name   = document.getElementsByTagName("table")[i+2].rows[0].cells[10].innerHTML.replace(/^\s+|\s+$|,/g,"");
//  7  -            - 
;if(document.getElementById("current_turns")){document.getElementById("current_turns").innerHTML=user_turns;}
    if(user_server==='RT'){    var server_speed=8;   var server_max_turns=30;}
    if(user_server==='Ultra'){ var server_speed=120; var server_max_turns=100;}
    if(user_server==='Fast'){  var server_speed=300; var server_max_turns=150;}
    if(user_server==='Normal'){var server_speed=900; var server_max_turns=180;}
    if(user_server==='Slow'){  var server_speed=1800;var server_max_turns=250;}
    user_turns = current_time('U')-(user_turns*server_speed);
///////////////////////////
var build_server_userbar = 'username|'+user_name
                          +'[#]money|'+user_money
                          +'[#]food|'+user_food
                          +'[#]power|'+user_power
                          +'[#]turns|'+user_turns
                          +'[#]server|'+user_server
                          +'[#]server_speed|'+server_speed
                          +'[#]server_max_turns|'+server_max_turns;
setCookie('user_server_info',build_server_userbar,365);if(document.getElementById("header_sub")){start_timer();}

//document.getElementById("header_sub").innerHTML=getCookie('user/server_info');
}
}
}


}

Link to comment
Share on other sites

Exactly i want start_timer to start regardless.  I want to add it at the end of the function as before the last bracket in the function which closes the function.  But it just doesnt want to work there.  I got another function where i have a similar problem with the End Brackets being an issue.

Link to comment
Share on other sites

A pretty classic example of why indentation is so useful:

 

  function get_user_info() {
        for (i = 0; i < document.getElementsByTagName("table").length; i++) {
            var table_temp = document.getElementsByTagName("table")[i];
            if (table_temp.rows[0].cells.length == 2) {
                if (document.getElementsByTagName("table")[i + 1].rows[0].cells[0].innerHTML.search("Income") > 0 &&
                    document.getElementsByTagName("table")[i + 1].rows[0].cells[2].innerHTML.search("Private Messages") > 0) {
                    if (table_temp.rows[0].cells[0].innerHTML.search("i/w/blink.gif") > 0) {
                        var newdiv = document.createElement("div");
                        newdiv.setAttribute("ID", "mp3_mail");
                        newdiv.style.visibility = "hidden";
                        newdiv.style.position = "absolute";
                        newdiv.style.left = 0;
                        newdiv.style.top = 0;
                        document.body.appendChild(newdiv);
                        document.getElementById("mp3_mail").innerHTML = "<embed width=0 height=0 hidden='true' autostart='true' volume='100' loop='false' src='" + mp3_mail + "'>";
                    }
                    var user_money = document.getElementsByTagName("table")[i + 2].rows[0].cells[0].innerHTML.replace(/^\s+|\s+$|,/g, "").replace(" $", "");
                    var user_food = document.getElementsByTagName("table")[i + 2].rows[0].cells[2].innerHTML.replace(/^\s+|\s+$|,/g, "").replace(" F", "");
                    var user_power = document.getElementsByTagName("table")[i + 2].rows[0].cells[4].innerHTML.replace(/^\s+|\s+$|,/g, "").replace(" P", "");
                    var user_turns = document.getElementsByTagName("table")[i + 2].rows[0].cells[6].innerHTML.replace(/^\s+|\s+$|,/g, "").replace(" T", "");
                    var user_server = document.getElementsByTagName("table")[i + 2].rows[0].cells[8].innerHTML.replace(/^\s+|\s+$|,/g, "");
                    var user_name = document.getElementsByTagName("table")[i + 2].rows[0].cells[10].innerHTML.replace(/^\s+|\s+$|,/g, "");
                    if (document.getElementById("current_turns")) {
                        document.getElementById("current_turns").innerHTML = user_turns;
                    }
                    if (user_server === "RT") {
                        var server_speed = 8;
                        var server_max_turns = 30;
                    }
                    if (user_server === "Ultra") {
                        var server_speed = 120;
                        var server_max_turns = 100;
                    }
                    if (user_server === "Fast") {
                        var server_speed = 300;
                        var server_max_turns = 150;
                    }
                    if (user_server === "Normal") {
                        var server_speed = 900;
                        var server_max_turns = 180;
                    }
                    if (user_server === "Slow") {
                        var server_speed = 1800;
                        var server_max_turns = 250;
                    }
                    user_turns = current_time("U") - user_turns * server_speed;
                    var build_server_userbar = "username|" + user_name + "[#]money|" + user_money + "[#]food|" + user_food + "[#]power|" + user_power + "[#]turns|" + user_turns + "[#]server|" + user_server + "[#]server_speed|" + server_speed + "[#]server_max_turns|" + server_max_turns;
                    setCookie("user_server_info", build_server_userbar, 365);
                }
            }
        }
        if (document.getElementById("header_sub")) {
            start_timer();
        }
    }

 

Edit: By the way I just used the first online JavaScript tidier I could fine, think you've lost your comments.

Link to comment
Share on other sites

Try add this else statement:

 

        if (document.getElementById("header_sub")) {
            start_timer();
        } else {
            alert("element doesn't exist!");
        }

Link to comment
Share on other sites

Not a darn thing, however i think it has something to do with the cookie, or the loop.

 

Maybe i should individually test each by itself maybe.  But thanks for the help, you can see why im having a slight problem, its not an easy fix and makes no-sense at all.  Mean time im going to have lunch then play cards with the family so i'll be back later.  If you come up with any other ideas i'm all ears, hopefully someone else gots an insight to why this magical error happens without an error being present.

Link to comment
Share on other sites

Well theoretically that condition should be run no matter what; given that there's no syntax errors reported and not a single "return" within the preceding code. Are you sure the function is actually being called?

 

Try adding an alert at the start of the function:

 

  function get_user_info() {
        alert('foo');

Link to comment
Share on other sites

Trust me the function is running. just fine.  it starts and runs just fine.  All it does is collect data, put that into a cookie, the cookie is used in Start_Timer(); and start_timer works just fine, it counts up or down.  So ya it works.  Just moving that small piece of code i want is impossible.

 

like i said this is an oddball problem that shouldnt exist.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.