• Works in browser, not in Synchronet

    From Kirkman@VERT/GUARDIAN to All on Tuesday, June 02, 2015 14:49:27
    I've been trying to work through a tutorial on making a javascript roguelike game (http://www.codingcookies.com/2013/04/20/building-a-roguelike-in-javascrip t-part-4/).

    The tutorial was written for the web, but with some changes I can make bits of it work for Synchronet.

    Lately I've been running into a brick wall trying to create an array of tile objects (see code below) using a simple loop. The code spits out an array where the first item is the desired object, but all subsequent entries in the array are nulls.

    I tried many variations, but nothing fixed my issue. At last I developed a stripped down bit of test code so that I could compare my results on the BBS with a web browser.

    The code worked perfcetly in the browser, spitting out an array of several objects with no nulls.

    So.... I'm guessing this is an issue with SpiderMonkey 1.8.5? Can anyone suggest a workaround?

    Here's the test code. Should note that I'm using shims/polyfills to add Object.create() and Function.prototype.extend. Also, this code ises console.log() to display the array in a browser, but you'd want to change that to some other logger/debugger with Synchronet.


    // Object.create polyfill
    if (typeof Object.create != 'function') {
    Object.create = (function() {
    function Temp() {}
    var hasOwn = Object.prototype.hasOwnProperty;
    return function (O) {
    if (typeof O != 'object') {
    throw TypeError('Object prototype may only be an Object or null');
    }
    Temp.prototype = O;
    var obj = new Temp();
    Temp.prototype = null; // Let's not keep a stray reference to O...
    if (arguments.length > 1) {
    var Properties = Object(arguments[1]);
    for (var prop in Properties) {
    if (hasOwn.call(Properties, prop)) {
    obj[prop] = Properties[prop];
    }
    }
    }
    return obj;
    };
    })();
    }

    // Function.prototype.extend
    Function.prototype.extend = function(parent) {
    this.prototype = Object.create(parent.prototype);
    this.prototype.constructor = this;
    return this;
    }


    // Game object

    var Game = {
    init: function() {
    var testArray = [];
    for (var i=0; i<10; i++) {
    testArray.push( Game.Tile.nullTile );
    }
    console.log( testArray );
    }
    }


    Game.Glyph = function(properties) {
    properties = properties || {};
    this._char = properties['character'] || ' ';
    this._foreground = properties['foreground'] || 'white';
    this._background = properties['background'] || 'black';
    };

    // Create standard getters for glyphs
    Game.Glyph.prototype.getChar = function(){
    return this._char;
    }
    Game.Glyph.prototype.getBackground = function(){
    return this._background;
    }
    Game.Glyph.prototype.getForeground = function(){
    return this._foreground;
    }



    Game.Tile = function(properties) {
    properties = properties || {};
    Game.Glyph.call(this, properties);
    this._isWalkable = properties['isWalkable'] || false;
    this._isDiggable = properties['isDiggable'] || false;
    };
    // Make tiles inherit all the functionality from glyphs Game.Tile.extend(Game.Glyph);

    // Standard getters
    Game.Tile.prototype.isWalkable = function() {
    return this._isWalkable;
    }
    Game.Tile.prototype.isDiggable = function() {
    return this._isDiggable;
    }

    // Null tile type
    Game.Tile.nullTile = new Game.Tile({});



    // Initialize the game
    Game.init();

    ////--------------------------------------------------
    BiC -=- http://breakintochat.com -=- bbs wiki and blog

    ---
    þ Synchronet
  • From Kirkman@VERT/GUARDIAN to All on Wednesday, June 03, 2015 18:06:23
    Re: Works in browser, not in Synchronet
    By: Kirkman to All on Tue Jun 02 2015 02:49 pm

    Lately I've been running into a brick wall trying to create an array of tile objects (see code below) using a simple loop. The code spits out an array where the first item is the desired object, but all subsequent entries in the array are nulls.

    Okay, ignore this whole thing. The issue was my debugger function replaces circular references with nulls.

    Sorry for the waste of time.

    --Josh

    ////--------------------------------------------------
    BiC -=- http://breakintochat.com -=- bbs wiki and blog

    ---
    þ Synchronet