Little question about Object property with array

Hi


I am building my quest system.
I use for Quests the Rmmv Armors Items, $dataArmors[], because I do not use this DB in my project.
At the beginning of the game, I inject all in $dataArmors [?].meta my individually properties for Quest.
I write them in a .js file, because the comment window in the software is too difficult to manage.


My question is about my access to my SubQuests.
To access it, I currently use this, 'is work good but i dont like the way to acces'


$dataArmors[1].meta.Quest['SubQ'+0].title  // return the title from meta.Quest.SubQ0
$dataArmors[1].meta.Quest['SubQ'+0].Desc[0]  // return the Desc LV1 from meta.Quest.SubQ0


Here a example of the builder when the project boot,
You can see the SubQ0: { , he define all what are the SubQ0

Spoiler
$dataArmors[1].meta.Quest = {
SubType:['recipe', ' Item', 'switch'],// type et total number of subquest in Quest1
Status:false,
IsFinish: function check() {},//need to make a function to check all SubQ // .meta.Quest['SubQ'+id]
//SubQuest Custom edit for $dataArmors[1]
SubQ0: {
isfinish: CheckRecipe(154);
title:'title',
Desc:['description lv1 int ',
'more description lv2 int ',
'more more more description lv3 int '],
}
SubQ1: { } // ....
SubQ3: { } // ....

};



*But I would like to know if it would be possible to access , like this way.
I find this way a cleaner way to manage.



$dataArmors[1].meta.Quest.SubQ[0].title   // return the title from meta.Quest.SubQ[0]
$dataArmors[1].meta.Quest.SubQ[0].Desc[0]  // return the Desc LV1 from meta.Quest.SubQ0


So i build my attribut like thas , but i get  Uncaught SyntaxError: Unexpected token [

Spoiler
$dataArmors[1].meta.Quest = {
SubType:['recipe', ' Item', 'switch'],// type et total number of subquest in Quest1
Status:false,
IsFinish: function check() {},//need to make a function to check all SubQ // .meta.Quest['SubQ'+id]
//SubQuest Custom edit for $dataArmors[1]
SubQ: {
[//SubQ0
isfinish: CheckRecipe(154);
title:'title',
Desc:['description lv1 int ',
'more description lv2 int ',
'more more more description lv3 int ']
]
[],//SubQ1
[]//SubQ2....

}

};



Is that I put it wrong syntax, or simply not possible to build this way.
I'm not an expert in javascript but I'm wondering about this.
Have you some suggestion , am do a mistake ??


Tell me if I am not clear in my explanation, I did my best.
Thank you
Well without seeing any information on the error, it's a bit hard to debug it, but just by looking at it, I'm 95% sure your format is wrong. SubQ is an object that you try to cram an array into, but you didn't give that array a key to access it with. This is almost definitely invalid.
@Zalerinian


ok to be more clean.
I want something like this.
A array dynamic property object


var SubQ =[]; // now work Uncaught SyntaxError: Unexpected token [
$dataArmors[1].meta.Quest = {
SubQ[0]: {
title:'Title ',
}
SubQ[1]: {
title:'Title ',
}
}




This no work but ideally i want a easy access similar to this. 🙂


var i = 0;
$dataArmors[1].meta.Quest.SubQ.title  // return me title SubQ[0]
var i = 1;
$dataArmors[1].meta.Quest.SubQ.title  // return me title SubQ[1]




is my SyntaxError or is not possible to use named array for define a property like this in a object constructor ?
you can't edit manually the native json
Believe it should be more like the following as an example:


var Quest = {
SubQ: [{title: 'A Title'}, {title: 'Another Title'}]
};


Then you can call the way you want:

Code:
Quest.SubQ[0].title; // 'A Title'
$dataArmors[1].meta.Quest = {
SubQ:
[
{
title: 'Title 1',
},
{
title: 'Title 2',
}
]
}




this is how you use an array in JSON, @Jonforum
@Zalerinian @Sarlecc @nio kasgami


NICE NICE NICE  😀
Thank you very much everyone, I am very happy now and I learned something new.
You are all super


USE directly the JSON, This is a very good idea, but I gave up when I saw the formatting.
I find the syntax and formatting difficult to read.


JSON formating  :headshake:

Spoiler
Captdsfsfure.JPG



VS


JS formating

Spoiler
adfaf.JPG





And I do not yet know the language used.


Maybe study it soon 🙂
USE directly the JSON, This is a very good idea, but I gave up when I saw the formatting.
I find the syntax and formatting difficult to read.


JSON formating  :headshake:






 

The formatting is not usually like that but because it's stringified before it's saved it shows up lke this. If you want to read the json, use a beautify extension in your editor or the native code formatting tool to get the original format back. Using my editor I was able to get the format to look like this.


Screenshot_1.png


The way you're doing things is fine but don't be scared of using a JSON file because of the way it looked, hopefully, this helps you become less worried about JSON.
You can use JSON.stringify (data, null, '\t') to format it better. I use it with my own plugins.

Original thread: https://forums.rpgmakerweb.com/threads/little-question-about-object-property-with-array.72414/