user372671
user372671

Reputation: 35

Grabbing a variable from another js file

example :

original file code:

var drawMap = function() {
    for(i=0;i<map.length;i++){
        for(j=0;j<map[i].length;j++){
            var drawTile= map[i][j];
            var xpos = (i-j)*tileH + mapX;
            var ypos = (i+j)*tileH/2+ mapY;
            ctx.drawImage(tileImg[drawTile],xpos,ypos);
        }
    }   
    return {
        xpos: xpos,
        ypos: ypos
    }
}

new code file:

var draw = function(ctx) {
    alert(map.drawMap.xpos);
};

the value for xpos in the new code file always comes up undefined... help?

Upvotes: 0

Views: 152

Answers (1)

laurent
laurent

Reputation: 90736

That should be:

var draw = function(ctx) {
    alert(map.drawMap().xpos);
};

Upvotes: 1

Related Questions