So far there is one person who had actual insight into the plugin I create for my football manager, and even though everything works, he told me I did a couple things wrong.
Here is an example of what I did:
Okay, I made this piece of code up on the spot, but it is anything but random, this is a simplified version of the much larger code that was commented on. I just picked the stuff that explain my question.
So, what I do here, is I loop a set of code for each en entry in the array. For those who pay attention, you might see my array starts with , and my loop starts at 1, not at zero.
Inside this loop in the example, I gave a few reasons why I start my loop with 1, instead of 0. There is no variable 0, no actor 0, no enemy 0, no event 0...
Now, the person who took a look at my code, he's my nephew btw, he told me that it is wrong to start the loop with 1. He thinks the code should look like this:
Note that
I asked him why, and he told me because that is what he was taught in school. But it works when I do it my way. In my mind "because that is what I was taught" isn't a reason not to do it. I remember math class all to well. My teacher (and in my mind 99% of the math teachers) overcomplicated all the math problems from day 1. So many times I had to take over from the teacher, to show that this complicated stuff was actually real easy. And the teacher had no idea, their mind was blown every time, because they just follow the book. True story. And I assume my nephews teachers are like that too.
With a little piece of code like this, I would be happy to do it his way, but I use it in much, much larger loops, where pretty much every single command would include
Another issue I have with this, is that I don't want my arrays to start with index 0. I use this for things like coordinates for example. So index 1, should contain the coordinates of slot 1, not that of slot 2. If not, I get the same issue the other way around, where I need to use
So... My question is... If I use a code I changed to meet my needs, and it works exactly as I wanted it, than is it better to still do it by the book? And if so, can anyone tell me why it is important to start my loop with 0?
(Edit: I know, I know... I start with saying my nephew seeing my football manager plugin, and then start talking about my card game. Well... Those are more alike than you may think. Those loops and Id's are used in both, but pId actually comes from the football game, and stands for Player Id.)
Here is an example of what I did:
JavaScript:
var array = [,1,2,3,'A','B','C']
for (let pId = 1 ; pId < array.length; pId++) {
var x = array[pId];
var y = $gameVariables.value(pId);
var z = $dataEnemies[pId].dropItems[0].dataId;
var stuff = 'Insert formula using X, Y, Z and many other things depending on pId';
$gameVariables.setValue(pId, stuff)
};
Okay, I made this piece of code up on the spot, but it is anything but random, this is a simplified version of the much larger code that was commented on. I just picked the stuff that explain my question.
So, what I do here, is I loop a set of code for each en entry in the array. For those who pay attention, you might see my array starts with , and my loop starts at 1, not at zero.
Inside this loop in the example, I gave a few reasons why I start my loop with 1, instead of 0. There is no variable 0, no actor 0, no enemy 0, no event 0...
Now, the person who took a look at my code, he's my nephew btw, he told me that it is wrong to start the loop with 1. He thinks the code should look like this:
JavaScript:
var array = [1,2,3,'A','B','C']
for (let pId = 0 ; pId < array.length; pId++) {
var x = array[pId];
var y = $gameVariables.value(pId+1);
var z = $dataEnemies[pId+1].dropItems[0].dataId;
var stuff = 'Insert formula using X, Y, Z and many other things depending on pId';
$gameVariables.setValue(pId+1, stuff)
};
Note that
array.length is still the right moment to end the loop, since the array now starts with 1 instead of ,I asked him why, and he told me because that is what he was taught in school. But it works when I do it my way. In my mind "because that is what I was taught" isn't a reason not to do it. I remember math class all to well. My teacher (and in my mind 99% of the math teachers) overcomplicated all the math problems from day 1. So many times I had to take over from the teacher, to show that this complicated stuff was actually real easy. And the teacher had no idea, their mind was blown every time, because they just follow the book. True story. And I assume my nephews teachers are like that too.
With a little piece of code like this, I would be happy to do it his way, but I use it in much, much larger loops, where pretty much every single command would include
pId. In my card game for example, slot 1 is linked to actor 1, and event 1, and variable 1, and switch 1. The same goes for slot 2, 3, 4 and all the way up to slot 40. So you might see why it is much easier for me, if I could just start my loop with 1.Another issue I have with this, is that I don't want my arrays to start with index 0. I use this for things like coordinates for example. So index 1, should contain the coordinates of slot 1, not that of slot 2. If not, I get the same issue the other way around, where I need to use
array[pId - 1] while my way I can just use array[pId] for example. I have much more arrays like this, which all depend in pId.So... My question is... If I use a code I changed to meet my needs, and it works exactly as I wanted it, than is it better to still do it by the book? And if so, can anyone tell me why it is important to start my loop with 0?
(Edit: I know, I know... I start with saying my nephew seeing my football manager plugin, and then start talking about my card game. Well... Those are more alike than you may think. Those loops and Id's are used in both, but pId actually comes from the football game, and stands for Player Id.)