Sign In Register

How can we help you today?

Start a new topic
Answered

Accessing Insides of object object

Hey, 


So I'm quite new to JS and I'm having an issue grabbing the insides of an object. 

Currently the insides are the same but the name of the container is different.

Example:

"Loot": [

   {

    "Head": {

     "LowMelee": 1,

     "MaxMelee": 5,

     "LowMagic": 1,

     "MaxMagic": 5

    }

   },

   {

    "Chest": {

     "LowMelee": 1,

     "MaxMelee": 5,

     "LowMagic": 1,

     "MaxMagic": 5

    }

   },

   {

    "Pants": {

     "LowMelee": 1,

     "MaxMelee": 5,

     "LowMagic": 1,

     "MaxMagic": 5

    }

   }

  ]


So, what I'm doing in code is Grabbing the Loot container and then grabbing one of the inside objects. 

The problem seems to be knowing what object I grabbed and then getting the inside properties.


What I need to do is be able to I guess figure out what is in the object, whether it's a Pants or a Chest. Right now the data inside is the same but later I want to have certain stats only on certain equipment.


I don't mind having some exta checks or a switch to do custom stuff like

switch (name)

{

   case "Pants": 

break;

   case "Chest":

break;

}


for example. 


Thanks for any help/pointing in the right direction.


PS. I have also debated putting the Helm/Chest/Pants etc part inside as a "slot" and just having Equipment but I still haven't been able to get the inside of whatever object I got right now.


Best Answer

Decided to just change the data so it is now something like


"Gains Goblin": {

  "Stats": {

   "Melee": 1,

   "Magic": 1,

   "Magic Res": 0,

   "Melee Res": 0

  },

  "Loot": [

   {

    "Slot": "Head",

    "LowMelee": 1,

    "MaxMelee": 5,

    "LowMagic": 1,

    "MaxMagic": 5

   },

   {

    "Slot": "Chest",

    "LowMelee": 1,

    "MaxMelee": 5,

    "LowMagic": 1,

    "MaxMagic": 5

   },

   {

    "Slot": "Pants",

    "LowMelee": 1,

    "MaxMelee": 5,

    "LowMagic": 1,

    "MaxMagic": 5

   }

  ]

 },


As that actually lets me access things nicely.

1 Comment

Answer

Decided to just change the data so it is now something like


"Gains Goblin": {

  "Stats": {

   "Melee": 1,

   "Magic": 1,

   "Magic Res": 0,

   "Melee Res": 0

  },

  "Loot": [

   {

    "Slot": "Head",

    "LowMelee": 1,

    "MaxMelee": 5,

    "LowMagic": 1,

    "MaxMagic": 5

   },

   {

    "Slot": "Chest",

    "LowMelee": 1,

    "MaxMelee": 5,

    "LowMagic": 1,

    "MaxMagic": 5

   },

   {

    "Slot": "Pants",

    "LowMelee": 1,

    "MaxMelee": 5,

    "LowMagic": 1,

    "MaxMagic": 5

   }

  ]

 },


As that actually lets me access things nicely.

Login to post a comment