2

I'm currently working on a tower defense game, and I'm currently in the process of implementing the different towers. And I'm lookin for a way to set up predefined values like a config file which I can extract the different values for the different towers on build time.

I've been searching around a bit and I came across a bit of code that looks like this:

var  building_attributes  =  {
        "Wall" :  {
            Damage :  0 ,
            RANGe :  0
            speed :  0
            bullet_speed :  0
            life :  100 ,
            Shield :  500 ,
            cost :  5
        }
 };

If I implemtented this, how can I then access the different values? Or perhaps someone out there has a good solution to my problem.

All answers are much appreicated. :)

1 Answers1

5

For example, accessing life:

var life = building_attributes.Wall.life;
//live === 100

building_attributes is a variable containing an object, with a Wall property. The Wall property is another object with properties. Properties of objects are accessible via the dot-notation, bracket notation or combination of both.

If you have gone through a data structures course, this structure of organizing data is called a tree. It's when one piece of data has children, which can be data or subtrees. These subtrees can also contain data, or subtrees and so on.

Community
  • 1
  • 1
Joseph
  • 117,725
  • 30
  • 181
  • 234