Jump to content

screen.push is not a function


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() {
            // initialize screen
        screen = [];
        for (var y = 0; y < ROWS; y++) {
                var newRow = [];
                for (var x = 0; x < COLS; x++)
                        newRow.push( this.initCell('', x, y) );
        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);
        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)
        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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.


  • Recently Browsing   0 members

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