Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// getNestAnscestorId.js
(function() {
	/*global adventurejs A*/ 
  "use strict";
  var p = adventurejs.Character.prototype;	
  /**
   * @memberOf adventurejs.Character
	 * @method adventurejs.Character#getNestAnscestorId
   * @returns {String}
   */
  p.getNestAnscestorId = function Character_getNestAnscestorId() 
  {
    if( !this.isNested() ) { return ""; }
    var child, parent_asset;
    if(this.getNestAsset) child = this.getNestAsset();
    if(child.getParentAsset) parent_asset = child.getParentAsset();

    // child parent is room
    if( parent_asset && parent_asset instanceof adventurejs.Room ) 
    {
      return child.id;
    }
  
    while ( parent_asset ) 
    {
      child = parent_asset;
      parent_asset = parent_asset.getPlaceAsset(); 
      if( parent_asset && parent_asset instanceof adventurejs.Room ) 
      {
        return child.id;
      }
    }                  
    return "";
  }
}());