Little question about Object property with array

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,615
Reaction score
1,417
First Language
French
Primarily Uses
RMMV
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

$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 [

$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
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,695
Reaction score
928
First Language
English
Primarily Uses
N/A
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.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,615
Reaction score
1,417
First Language
French
Primarily Uses
RMMV
@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 ?
 
Last edited by a moderator:

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
454
Reaction score
209
First Language
English
Primarily Uses
RMMV
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'
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,695
Reaction score
928
First Language
English
Primarily Uses
N/A
$dataArmors[1].meta.Quest = {
SubQ:
[
{
title: 'Title 1',
},
{
title: 'Title 2',
}
]
}




this is how you use an array in JSON, @Jonforum
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,615
Reaction score
1,417
First Language
French
Primarily Uses
RMMV
@Zalerinian @Sarlecc @nio kasgami


NICE NICE NICE  :D
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:

Captdsfsfure.JPG



VS


JS formating

adfaf.JPG





And I do not yet know the language used.


Maybe study it soon :)
 

LTN Games

Veteran
Veteran
Joined
Jun 25, 2015
Messages
648
Reaction score
510
First Language
English
Primarily Uses
RMMV
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.
 

Kino

EIS Game Dev
Veteran
Joined
Nov 27, 2015
Messages
515
Reaction score
682
First Language
English
Primarily Uses
RMMV
You can use JSON.stringify (data, null, '\t') to format it better. I use it with my own plugins.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Imagine after all this time, its RPG Maker MV Ace?:p Even if it has huge improvements, that would just be disappointing somehow xD
Kes
Came up with a good name for something. Checked on internet - device trademark filed in India 2017. Back to the drawing board.
I want to see the Features of the new RPG Maker.. NOW!!
Can't wait for it!
KDS
Check out some gameplay of a game iam working on :)
Me : "Wearing glasses is annoying."
*put out glasses*
Also me : "Keep mistaking 0, 6 and 8."

Forum statistics

Threads
98,126
Messages
949,503
Members
129,410
Latest member
Charles_Chandra
Top