Problem with JS classes

i am currently defining the variables for a game i’m making. there is a Life class that i use to define various types of life, from each of which tons of life forms can be generated.
for example, the Plant object uses the Life class as a template to generate different forms of plants. I’m using a class template for various features of the game so that later, i can make the game moddable with a text file.

so with the object i’m containing the various types of life, i believe i made a mistake. i can’t find out what’s wrong with it, but every line of code before the object works, and every line after does not. safari IOS does not support Glitch’s debugger, and when i pasted the code into an online IDE, it said that the Life object did not exist.

i am losing my mind over this, someone help me find out what’s wrong so i can actually start *making * the game. i have pretty much every detail planned and pseudocoded, and this is the one thing holding me back.

(both those links lead to the game)

here’s what I’m seeing in my browser console

Uncaught TypeError: life is undefined
https://novemportgame.glitch.me/variables.js:415

var life = { // line 342
...
life: [life.microbe(), life.animal()], // line 415
...
}; // line 459

see how on line 415 it tries to access life to get life.microbe() and life.animal()? although that’s lower in the source code than the var life = ..., it runs before setting up a scope entry for the variable name life. It has to finish creating the object (including running all of these expressions) before creating that life variable.

1 Like

so it would be better to use strings instead, and then later use the strings to refer to the objects in a getKeys() type function.

okay… i look into it, and i’ll use getOwnPropertyNames in the future. thanks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.