MZ How do I debug a Plugin?

I am probably easier to frustrate than the common man, but i simply don't know how I can make progress without 1 and a half billion errors thrown at me. Currently, I get the error "
ReferenceError
commonItemDataList is not defined"
Which is obviously completely wrong because it's already defined, as you can see in the row 16.
There is no way I can see what is happening inside the variables I define, since the debugger only shows me the global variables defined with a $, but not the variables inside a method. And every time that happens, it's a complete nightmare to find out what is actually wrong. Why is it so hard to do something that should be not much harder than a Hello World Program?
It's just frustrating and annoying and completely redundant.
I just want to continue with my work without being annoyed by bullshit like this.

Screenshot (1362)_cr.png
If you open the console with F8 and go to the "sources" tab, you can open specific js files and click the line numbers to set a breakpoint that the code will stop at if reached. You can even right click and select "edit breakpoint" to add a condition so the breakpoint will only stop execution if the condition is true.

The other option is to use console.log to add debug statements to your code. In this case, you could have added console.log(commonItemDataList); to output to the console the current value when it hits that line.

"Why is it so hard to do something that should be not much harder than a Hello World Program?"

In the nicest possible way this was entirely caused by you not knowing debug methods, and not realising you'd used a variable out of its defined scope. Neither of these are issues with the language or the engine, it's your knowledge level that led to this. That's not a bad thing, there's always more to learn, but you're only getting frustrated with yourself in this case.
This particular case is a scope problem: commonItemDataList is defined as a local variable in the makeDropItems method, so it is not "seen" in the cleanCommondropList function.
I am probably easier to frustrate than the common man, but i simply don't know how I can make progress without 1 and a half billion errors thrown at me. Currently, I get the error "
ReferenceError
commonItemDataList is not defined"
What line is it giving with that error? That's your vital reference point.

What you need to try to do is understand what causes given errors. If it's telling you that something you think you defined is undefined, then your biggest culprits to check for are:
- You accidentally are referring to it out of scope (you closed the function/loop/whatever prematurely)
- You're referring to a variable like a function or vice versa

For example, doing a quick read through your code I see you referencing commonItemDataList on line 46, which is inside a completely different function from where you declared it on line 16. So...yes, that's undefined. How wouldn't it be?

It's just frustrating and annoying and completely redundant.
I just want to continue with my work without being annoyed by bullshit like this.
I don't know what your coding knowledge/background is, but every language I've worked in would give you an error for that. You should probably try to calm down and focus on your side of it - this isn't like JavaScript is making up things to slow your work down. This is a mistake on your part.
This particular case is a scope problem: commonItemDataList is defined as a local variable in the makeDropItems method, so it is not "seen" in the cleanCommondropList function.
*sigh*

ok, seems plausible.
What you need to try to do is understand what causes given errors. If it's telling you that something you think you defined is undefined, then your biggest culprits to check for are:
- You accidentally are referring to it out of scope (you closed the function/loop/whatever prematurely)
- You're referring to a variable like a function or vice versa

For example, doing a quick read through your code I see you referencing commonItemDataList on line 46, which is inside a completely different function from where you declared it on line 16. So...yes, that's undefined. How wouldn't it be?


I don't know what your coding knowledge/background is, but every language I've worked in would give you an error for that. You should probably try to calm down and focus on your side of it - this isn't like JavaScript is making up things to slow your work down. This is a mistake on your part.
Normally, I am used to getting such an error not during runtime, but during compiling.
And i have to admit that frustration tends to shut down my critical thinking once it starts to reach a certain threshold.
Ok, now the question would be how i could solve this problem. Its a longshot, but probably it could help if i transform the second function into a inner function of the makeDropItems overwrite, which is maybe possible as i can save a function inside a variable, which again can be created inside the function.
One option would be to pass the array in as a function argument, e.g.
JavaScript:
function cleanCommondropList(list) {
  list.forEach(item => {
    // etc
  });
};
One option would be to pass the array in as a function argument, e.g.
JavaScript:
function cleanCommondropList(list) {
  list.forEach(item => {
    // etc
  });
};
The other option is to define the list as a property of the object: this._commonItemList
In the nicest possible way this was entirely caused by you not knowing debug methods, and not realising you'd used a variable out of its defined scope. Neither of these are issues with the language or the engine, it's your knowledge level that led to this. That's not a bad thing, there's always more to learn, but you're only getting frustrated with yourself in this case.
Most of the time I first get frustrated, then I ask someone with more experience, then I notice my mistake, and THEN I am learning.

1673026976843.png
Unfortunately, I usually feel more stupid afterward than before.
Most of the time I first get frustrated, then I ask someone with more experience, then I notice my mistake, and THEN I am learning.

View attachment 249866
Unfortunately, I usually feel more stupid afterward than before.
I understand, but this is not a healthy order in which to do things. What's the point in getting frustrated before you've even checked to see if it's something you need to be frustrated about? Can you honestly say, looking back over this issue, that it was ever that big a thing? It was resolved super quickly and easily and was a fundamental concept we've all messed up by accident at one point or another. If someone who's been coding for over 30 years does this too, it's really not something you need to feel silly for doing.

If your code worked first time more often than it didn't, I'd think you were employing some sort of witchcraft.
I understand, but this is not a healthy order in which to do things. What's the point in getting frustrated before you've even checked to see if it's something you need to be frustrated about? Can you honestly say, looking back over this issue, that it was ever that big a thing? It was resolved super quickly and easily and was a fundamental concept we've all messed up by accident at one point or another. If someone who's been coding for over 30 years does this too, it's really not something you need to feel silly for doing.

If your code worked first time more often than it didn't, I'd think you were employing some sort of witchcraft.
The thing is, i was pretty much aware of that my knowledge of JavaScript is very limited, which is why I asked so much about it here and on discord. And my frustration problems are something that has accompanied me my entire life, so it's not really something new for me. However, if I understood what I was doing, then I am usually pretty good at making a significant progress and the frustration issues are much smaller, especially with my own projects where I understood far better what exactly was happening. This also applies to my RPG Maker project: bugs that were clearly caused by my own misconduct were less frustrating than those caused by some strange interaction of the RPG Maker's plugins/settings.

If you want to see one of my private projects to convince yourself, I worked on a sudokuSolving algorithm which is pretty fast, although still a bit unfinished. I even tried to multithread the thing, but it pretty much turned out that it's just not as fast as my single threaded variant due to the amount of blocking that was required.
The thing is, i was pretty much aware of that my knowledge of JavaScript is very limited, which is why I asked so much about it here and on discord. And my frustration problems are something that has accompanied me my entire life, so it's not really something new for me. However, if I understood what I was doing, then I am usually pretty good at making a significant progress and the frustration issues are much smaller, especially with my own projects where I understood far better what exactly was happening. This also applies to my RPG Maker project: bugs that were clearly caused by my own misconduct were less frustrating than those caused by some strange interaction of the RPG Maker's plugins/settings.

If you want to see one of my private projects to convince yourself, I worked on a sudokuSolving algorithm which is pretty fast, although still a bit unfinished. I even tried to multithread the thing, but it pretty much turned out that it's just not as fast as my single threaded variant due to the amount of blocking that was required.
You don't need to prove anything to me pal, your credentials aren't in doubt here. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-debug-a-plugin.153829/