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ã