2D array, i get undefinid ID ?

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
hi why i get error when i delete example DiceSlotBig[3][2 and 3]


i add a conditional if 


if (DiceSlotBig[2]!== null) { 


So, if no found 2d array after de x, y, is suppose to jump the for, and not give me error ?!


the msg error is 


TypeError: Cannot read property 'id' of undefined


Tanks for help guys


 


DiceSlotBig = [
[1206, 571, 'dice-1', 120], // slot 1 [x, y, 'filename', $dataItems[id]] type dice (note: fileName and id are temporly here, need to delete)
[1111, 571, 'dice-2', 121], // slot 2 [x, y, 'filename', $dataItems[id]] type dice
[1013, 571, 'dice-3', 122], // slot 3 [x, y, 'filename', $dataItems[id]] type dice
[917, 571], // slot 4 [x, y, 'filename', $dataItems[id]] type dice ################# this give me error if i delete file name and id like thats ?
[1206, 656, 'dice-5', 124], // slot 5 [x, y, 'filename', $dataItems[id]] type dice
[1111, 656, 'dice-6', 125], // slot 6 [x, y, 'filename', $dataItems[id]] type dice
[1013, 656, 'dice-7', 126], // slot 7 [x, y, 'filename', $dataItems[id]] type dice
[917, 656, 'dice-8', 127], // slot 8 [x, y, 'filename', $dataItems[id]] type dice
[829, 571, 'dice-key-sivler', 128], // slot 9 [x, y, 'filename', $dataItems[id]] type ITEM
[750, 571, 'dice-potion-red', 129], // slot 10 [x, y, 'filename', $dataItems[id]] type ITEM
[829, 656, 'dice-key-gold', 130], // slot 11 [x, y, 'filename', $dataItems[id]] type ITEM
[750, 656, 'dice-potion-blue', 131], // slot 12 [x, y, 'filename', $dataItems[id]] type ITEM
]
var PidDice = 31;
var NBXmargin = 20,
NBYmargin = 20; // marge x y for small Number quantity indicator Dtext
for (i = 0; i <= DiceSlotBig.length - 1; i++) {
console.log(i);
if (DiceSlotBig[2] !== null) {
// check if has item in slot by array ( need filename and dataItems) if null do nothing
//show dice to the X dice to x, y coor slot only if filename exist (fileName will be added in other item menu selector)
//PID start to 31 and max Pid 47
$gameScreen.showPicture(PidDice + i, DiceSlotBig[2], 1, DiceSlotBig[0], DiceSlotBig[1] + 100, 0, 0, 255, 0);
new IAVRA.ANIMATE.Tween($gameScreen.picture(PidDice + i), {
_y: DiceSlotBig[1],
_scaleX: 100,
_scaleY: 100,
_opacity: 255
}).easing(IAVRA.EASING.elastic.out).duration(30).start();
$gameScreen.setDTextPicture('\\OW[5] ' + '\\v[' + $dataItems[DiceSlotBig[3]].id + ']' + ' ', 16); //plugincall dtext
$gameScreen.setFont('GameFont');
$gameScreen.dTextBackColor = 'rgba(0, 0, 0, 0.6)';
$gameScreen.showPicture(PidDice + i + 1, '', 1, DiceSlotBig[0] + NBXmargin, (DiceSlotBig[1] + NBYmargin) + 100, 0, 0, 255, 0);
new IAVRA.ANIMATE.Tween($gameScreen.picture(PidDice + i + 1), {
_y: DiceSlotBig[1] + NBYmargin,
_scaleX: 100,
_scaleY: 100,
_opacity: 255
}).easing(IAVRA.EASING.elastic.out).duration(80).start();
$gameScreen.setPictureCallCommon(PidDice + i, 8, 1); // set able picture to click, bring to CommunEvent 8
PidDice++;
}


}

}


 
 
Last edited by a moderator:

taarna23

Marshmallow Princess
Global Mod
Joined
Jul 20, 2012
Messages
2,402
Reaction score
4,966
First Language
English
Primarily Uses
RMMZ
Okay, I'm going to work with the strings you have in your arrays, as that is the most identifiable part.


At DiceSlotBig[0][2] you have "dice-1"


At DiceSlotBig[1][2] you have "dice-2"


At DiceSlotBig[2][2] you have "dice-3"


At DiceSlotBig[3][2] you have a problem, because you don't have a 2. DiceSlotBig[3][0] = 917 and DiceSlotBig[3][1] = 571 but DiceSlotBig[3][2] is out of the array bounds.


Basically, the fourth row exists (number 3, as we start counting at 0) but the third column of the fourth row does not.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
Okay, I'm going to work with the strings you have in your arrays, as that is the most identifiable part.


At DiceSlotBig[0][2] you have "dice-1"


At DiceSlotBig[1][2] you have "dice-2"


At DiceSlotBig[2][2] you have "dice-3"


At DiceSlotBig[3][2] you have a problem, because you don't have a 2. DiceSlotBig[3][0] = 917 and DiceSlotBig[3][1] = 571 but DiceSlotBig[3][2] is out of the array bounds.


Basically, the fourth row exists (number 3, as we start counting at 0) but the third column of the fourth row does not.
yes i just fixed, am not understant why 


if (DiceSlotBig[3][2] !== null){}


Give return me true !!! , is suppos  return false.


So i remplace this


by this


if (DiceSlotBig.length > 2) {


And is work :)
 

taarna23

Marshmallow Princess
Global Mod
Joined
Jul 20, 2012
Messages
2,402
Reaction score
4,966
First Language
English
Primarily Uses
RMMZ
Well, technically speaking, it's NOT null. It's beyond the bounds of the array (JavaScript has some strange returns like this - this is an entertaining reference for some of the weird things JavaScript does: https://www.destroyallsoftware.com/talks/wat ). Checking the length of the array is more reliable anyway, as checking for a null value attempts to index that position of the array and may result in a crash/null reference error.
 

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

Latest Threads

Latest Profile Posts

I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

A bit of a "sparkle" update to the lower portion of the world map. :LZSexcite:
attack on titan final season is airing tomorrow, I'm excited and scared at the same time!

Forum statistics

Threads
105,882
Messages
1,017,230
Members
137,607
Latest member
Maddo
Top