Undefined ctx variable
<p>I have a script which keeps telling me ctx is undefined but yet a different variable is still set in the script which was made at the same place... so im confused why one variable is set and not the other.</p>

<p>The error is:
Uncaught ReferenceError: ctx is not defined on line 32 (i commented line 32)</p>

<p>Yet var canvas is defined =/</p>

<p>This is my script:</p>

<pre><code>var tiles = Array("1.png","0.png"); 
var loaded = 0; 
var loadTimer; 


function loadimg(){
 var tileImg = new Array();
for(var i=0;i&lt;tiles.length;i++){
    tileImg[i] = new Image();
    tileImg[i].src = tiles[i]; 
    tileImg[i].onload = function(){ 
        loaded++;
    }
  }
}

function loadall(){ 
if(loaded == tiles.length){
    clearInterval(loadTimer);
    loadTimer = setInterval(gameUpdate,100); 
 }
} 

function gameUpdate(){ 
ctx.clearRect(0,0,canvas.width,canvas.height); //line 32
draw();
}

function init(){
var canvas = document.getElementById("canvas");  
var ctx = canvas.getContext("2d"); 
loadimg(); 
loadTimer = setInterval(loadall,100);
}
</code></pre>

<p>Hope you can help explain my mistake.</p>
