Jump to content

screen.push is not a function


Choeeey
 Share

Recommended Posts

Hi all,

 

At the line '  screen.push(newRow);' it says this is not a function, adding var screen in front of it fixes this, however then at the bottom it doesn't know what screen is,

 

Could anyone help please? :)

 

Here is my code:

 
myGame.randomMaze = function(game1) {
    game = game1;
    };
 
var ROWS = 10;
        var COLS = 10;
 
        var screen;
        // font size
        var FONT = 32;
        var map;
 
    myGame.randomMaze.prototype = {
        
        
        create: function() {
             this.initMap();
            
            // initialize screen
        
        screen = [];
        for (var y = 0; y < ROWS; y++) {
                var newRow = [];
                screen.push(newRow);
                for (var x = 0; x < COLS; x++)
                        newRow.push( this.initCell('', x, y) );
        }
        this.drawMap();
 
        
        initCell: function(chr, x, y) {
        // add a single cell in a given position to the ascii display
        var style = { font: FONT + "px monospace", fill:"#fff"};
        return game.add.text(FONT*0.6*x, FONT*y, chr, style);
        },
 
        update:function(){
        },
 
 
        
     
        
        initMap: function() {
        // create a new random map
        map = [];
        for (var y = 0; y < ROWS; y++) {
                var newRow = [];
                for (var x = 0; x < COLS; x++) {
                     if (Math.random() > 0.8)
                        newRow.push('#');
                    else
                        newRow.push('.');
                }
                map.push(newRow);
        }
        },
        
        drawMap: function() {
    for (var y = 0; y < ROWS; y++)
        for (var x = 0; x < COLS; x++)
            screen[y][x].content = map[y][x];
}
};
        
        
  
Link to comment
Share on other sites

I don't think that using a push() inside a for() loop wil create this problem. I also tried :
 

var screen;screen = [];for (var i=1;i<5;i++){    var newRow = [];    screen.push(newRow);}

and there is still no error... the problem can't be the push() method, it has to be the screen variable.

Could you show us all of your code, or a demo page ? And/or copy-paste the full Javascript error that happens ?

Also, about which '0' are you talking about in your last question ?
 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...