Cannot read property '__createLifeIcons' of undefined?

why am I getting 'Cannot read property '__createLifeIcons' of undefined' even though I clearly define it as a class function?

/**
 * A class that extends Phaser.Scene & wraps up 
 * the core logic for the Life Meter
 */

var LifeMeter = new Phaser.Class ( {

	Extends : Phaser.Scene, 

	initialize : 

	function LifeMeter ( ) {

		Phaser.Scene.call ( this, {

			key : 'LifeMeter', 
			active : false, 

		} );

	}, 

	LifeIcons : function ( ) {

		__createLifeIcons = function ( __objData, __debug ) {

			__debug = __debug || 0;

			__add = __objData.add;
			__x = __objData.x || 0;
			__y = __objData.y || 0;
			__iconName = __objData.iconName || 'lifeicon';
			__lifeCounter = __objData.lifeCounter || 5;
			__lifeCounterRows = __objData.lifeCounterRows || 2;
			__lifeCounterCols = __objData.lifeCounterCols || 1;
			__scrollFactor = __objData.scrollFactor || 0;
			__zOrder = __objData.zOrder || 999;

			let __y2 = 0;
			let __x2 = 0;

			for ( __i = 0; __i < __lifeCount; __i++ ) {

				if ( __i % __lifeCounter === 0 ) {
					__y2 += __lifeCounterRows;
					__x2 = 0;
					console.log ( 'end of line' );
				} else {
					__x2 += __lifeCounterCols;
				}

				__lifeIcon [ __i ] = __add.image (
					( ( __x * __x2 * 2 ) + ( __x ) ), 
					( __y * __y ), 
					__iconName
				).setScrollFactor ( __scrollFactor ).setDepth ( __zOrder );
				
				__lifeIcons.push ( __lifeIcon );

			}

			return __lifeIcons;

		}

	}, 

});

__lifeMeter = new LifeMeter ( ).LifeIcons ( );

var __lifeMeters = [ ];

__lifeMeters [ 0 ] = __lifeMeter.__createLifeIcons ( );

Any help as always is GREATLY appreciated!

Thank You! <3

Hi,
Active: false to true perhaps???
The only scene i use with active is set to true, but honestly i don’t know…

@BlunT76 : That did not work.

If you console.log(__lifemeter)
Is it created correctly?

@BlunT76 : 'console.log ( __lifeMeter );' returns : 'LifeMeter {sys: Systems}'

Hmm, you extends a scene, you are supposed to get a scene in the console.log

@BlunT76 : Should I remove 'extends Phaser.Scene' ?

@BlunT76 : this is what

console.log ( __lifeMeter );

returns :

LifeMeter {}

This is how I restructured it, but still I get :

'__lifeMeter.__createLifeIcons is not a function'
var LifeMeter = function ( ) {

	LifeIcons = function ( ) {

		__createLifeIcons = function ( __objData, __debug ) {

			__debug = __debug || 0;

			__add = __objData.add;
			__x = __objData.x || 0;
			__y = __objData.y || 0;
			__iconName = __objData.iconName || 'lifeicon';
			__lifeCounter = __objData.lifeCounter || 5;
			__lifeCounterRows = __objData.lifeCounterRows || 2;
			__lifeCounterCols = __objData.lifeCounterCols || 1;
			__scrollFactor = __objData.scrollFactor || 0;
			__zOrder = __objData.zOrder || 999;

			let __y2 = 0;
			let __x2 = 0;

			for ( __i = 0; __i < __lifeCount; __i++ ) {

				if ( __i % __lifeCounter === 0 ) {
					__y2 += __lifeCounterRows;
					__x2 = 0;
					console.log ( 'end of line' );
				} else {
					__x2 += __lifeCounterCols;
				}

				__lifeIcon [ __i ] = __add.image (
					( ( __x * __x2 * 2 ) + ( __x ) ), 
					( __y * __y ), 
					__iconName
				).setScrollFactor ( __scrollFactor ).setDepth ( __zOrder );
				
				__lifeIcons.push ( __lifeIcon );

			}

			return __lifeIcons;

		}

	}

	__Hearts = function ( ) {

		drawQuarterHeart = function ( ) {

		}, 

		drawHalfHeart = function ( ) {

		}, 

		drawThreeQuarterHeart = function ( ) {

		}, 

		createLifeMeters = function ( __restHeart ) {

			if ( restHeart === 1 ) { drawQuarterHeart ( ); }
			if ( restHeart === 2 ) { drawHalfHeart ( ); }
			if ( restHeart === 3 ) { drawThreeQuartersHeart ( ); }

		}, 

		updateLifeMeter = function ( amount ) {

			// updates current life
			this.life -= amount;

			// How many whole hearts should render
			const amountOfWholeHearts = Math.floor ( this.life / 4 );

			// How much life is left to display after displaying all the whole hearts
			const restHeart = this.life % 4;

			// Draw the whole hearts
			this.drawHearts ( amountOfWholeHearts );

			// Draw `Life Meter{s}`
			this.drawLifeMeters ( restHeart );

		}

	} 

}

In the last example, you are using closure, function inside a function is only accessible within the function.

What do you want to do exactly in the game?

@BlunT76 I want to be able to call either :

__lives = [ ];
__healthType = [ ];

__lifeMeter = new LifeMeter ( );

__lives[ 0 ] = __lifeMeter.LifeIcons ( );
__lives[ 1 ] = __lifeMeter.Hearts ( );

__healthType [ 0 ] = __lives [ 0 ].createLifeIcons ({
    add : this.add, 
    x : 0, 
    y : 0, 
    iconName : 'lifeicon', 
    lifeCounter : 5, 
    lifeCounterRows : 2, 
    lifeCounterCols : 1, 
    scrollFactor : 0, 
    zOrder : 999, 
});

__healthType [ 1 ] = __lives [ 1 ].createLifeMeters ( 1 );

So basically I want to have 2 health systems to choose from. 1 called 'LifeIcons' & the other called 'Hearts'. I then want to be able to call the create / update functions from either 1.

@Thundros
In a separate scene from the game scene?

@BlunT76 : Yes. I want it to be it’s own class. It is a small library.

A class and a scene isn’t the same thing, a scene is a already made phaser class containing many game objects.
A class is just… a class :slight_smile:
Here’s how i use class in es6

class LifeIcons  {
  constructor() {
  }
		__createLifeIcons ( __objData, __debug ) {
      // you code here
      return 'test ok'
    }
}

var test = new LifeIcons();
console.log(test.__createLifeIcons())