body onload="" cannot find function

10,040

This line:

        colors: [[0.5,0.5,1,1],[0.5,0.5,1,1]],[0.5,0.5,1,1]

is syntactically incorrect: a closing "]" is in the wrong place. Thus the function definition "failed", so to speak, and the function doesn't really exist.

I literally just woke up so I'm not sure what's wrong with me that I could spot that.

Share:
10,040
gkaykck
Author by

gkaykck

Updated on June 09, 2022

Comments

  • gkaykck
    gkaykck almost 2 years

    i am trying stuff with philogl library, and when i wrote,

    <!DOCTYPE html>
    
    <html>
    <head>
        <title>PGL2</title>
        <script type="text/javascript" src="PhiloGL.js"></script>
        <script type="text/javascript">
        function webGLStart(){
            alert('I m alive');
        }
    </script>
    </head>
    
    <body onload="webGLStart();">
    <canvas id="c" style="width:500px; height:500px;"></canvas>
    
    
    </body>
    </html>
    

    everything works fine, but if i write some philogl in it like,

    <!DOCTYPE html>
    
    <html>
    <head>
        <title>PGL2</title>
        <script type="text/javascript" src="PhiloGL.js"></script>
        <script type="text/javascript">
        function webGLStart(){
            var triangle = new PhiloGL.O3D.Model({
                vertices: [[0,1,0],[-1,-1,0],[1,-1,0]],
                colors: [[1,0,0,1],[0,1,0,1],[0,0,1,1]]
                });
            var square = new PhiloGL.O3D.Model({
                vertices: [[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0]],
                colors: [[0.5,0.5,1,1],[0.5,0.5,1,1]],[0.5,0.5,1,1]
                });
        }
    </script>
    </head>
    
    <body onload="webGLStart();">
    <canvas id="c" style="width:500px; height:500px;"></canvas>
    
    
    </body>
    </html>
    

    chrome and firefox gives me an error that says webGLStart() is not defined. What is wrong with my code?

  • gkaykck
    gkaykck about 13 years
    yes this workds, but what suprised me is, only one line of the code is wrong and i am getting an error about "function is not defined", what is the best way of getting real error messages?
  • Albireo
    Albireo about 13 years
    Try with Firebug (see my comment to your question), it says at which line of your code the error happened.
  • Pointy
    Pointy about 13 years
    @gkaykck Firefox is really bad about reporting parse problems like that, but the errors usually show up in the Firebug console. An error encountered when parsing a function definition will result in the function being undefined; the runtime just doesn't have anything to work with in a case like that. Generally the entire <script> block is aborted!
  • gkaykck
    gkaykck about 13 years
    sorry but the main problem is i have to use chrome for now because firefox is right now lacks support of webGL, and even v4b11 does gives me errors on every webgl demo's website, if there were any good standalone app for this...
  • Pointy
    Pointy about 13 years
    Ah well Chrome has its own debugger, and it reports such errors as faithfully as Firefox does in my experience. Yet if you don't have the debug console open, you don't see them. That's one thing I appreciate about IE, even though it can be annoying: those "Error on page" warnings are useful. (Of course I realize you definitely can't use IE here :-)
  • Paolo Tedesco
    Paolo Tedesco about 12 years
    +1 and standing ovation for this answer. I read it and immediately spotted my problem.