Problem pushing args into a array

through plugin command i send : the command | the id (args 0) Int | clothing1 (args 1) string | clothing2 (args 2) string

Code:
this._clothingGloves = [null];

var clothingactorid = args[0];
var x = 1;
var y = 1;
for (var i = 0; i < args.length-1; i++) {
//$gameActors._data[clothingactorid]._clothingGloves[x]=args[y];
$gameActors._data[clothingactorid]._clothingGloves.push({ name: args[y], enabled: true});
x=x+1
y=y+1
}

Should return;
0: null
1: Object
enabled: true
name: "a1b3b"
2: Object
enabled: true
name: "a1b3d"

When using console.log($gameActors._data[clothingactorid]._clothingGloves
);

then i just call

_clothingGloves[0] is used to load a specific image layer.. so by default i set it to 0..
when i want to display the gloves nbr 1 on that layered image i set the index to 1
when i want to display the gloves nbr 2 on that layered image i set the index to 2
and to remove the gloves from that layer i set index to 0


doing the push line repeats the the args 1 and 2 over and over.. while i only need 2 as the args length = 2

but if i comment it and uncomment the line above... i lose the option to add name: args but it stops at 2 (the number of args i need to add)

Im not sure how to make the push line works.. (as i do need more than just index:args)
Ermm.. with trial error i managed..

swapping: $gameActors._data[clothingactorid]._clothingGloves[x]=args[y];
by : $gameActors._data[clothingactorid]._clothingGloves[x]={ name: args[y], enabled: true};
Just for future reference, please surround your code in CODE tags (press Insert --> Code). If you still need assistance, please edit your original post to the code formatting, it will make everything else more clear to read.

It would help to know more about what you are trying to accomplish, and the data format of the input.
  • For example, is clothing1 a Number or a String?
  • What is the end goal of the _clothingGloves property you added to the Actor (what is the desired data)?

Without knowing what you want to accomplish, some thoughts:
  1. The '_clothingGloves' array is going to have an undefined value at index 0, because you're starting the 'x' value at 1. This might be OK, but it also might give you strange bugs later.
  2. I don't see where you have initialized '_clothingGloves' . Is it an Object literal or an Array? If it is not defined as an Array, then the 'push' function won't work.
  3. I don't understand your second post. Is your issue resolved? If it is, report your first post and ask for the thread to be closed, that way no one will spend more time to try to help you solve the problem. But if you still need assistance, please explain a bit more about your problem and we can help.
Thank you explaining what need to be mentioned

Its not resolved but i managed to obtain similar result using:
$gameActors._data[clothingactorid]._clothingGloves[x]={ name: args[y], enabled: true};

instead of pushing similar things like the code shows in post 1..

I would still be interested on knowing what i did wrong..
Now that you mention it.. maybe i have to set the array in a certain way for it to work..
The push method should be fine the way you have it.

Except for 2 things:

this._clothingGloves = [null];
  • What is "this" here?
    • Are you working in the global scope or within a function?
    • What do you get if you do "console.log(this)" ?

doing the push line repeats the the args 1 and 2 over and over.. while i only need 2 as the args length = 2
  • It doesn't for me when I test an example. Can you show a console.log of this result?


Personally I would have used the "i" iterator instead of making a new iterator "y" but your way is mathematically the same. It's just a suggestion but it doesn't actually cause any issues.
Code:
// Here is an example using the "i" iterator instead of creating another iterator
for (var i = 1; i < args.length; i++) {
    $gameActors._data[clothingactorid]._clothingGloves.push({ name: args[i], enabled: true });
}
// This way you don't need to include a line with "y = y + 1;"
Ohh so you mean the y = y +1 when i use push adds a infinite loop of args ?
No, that's not what I meant at all. Here is what I said about getting rid of the 'y' iterator:
your way is mathematically the same. It's just a suggestion but it doesn't actually cause any issues.


I think it's more important for us to see a console.log of where you say it pushes the arguments over and over, as well as a console.log of "this", like I asked above.
An maybe for good measure, "console.log(args)" although your args are probably OK.
this is where the this is
Code:
    var Alias_GActor_Setup = Game_Actor.prototype.setup;
    Game_Actor.prototype.setup = function(actorId) {
        Alias_GActor_Setup.call(this, actorId);
        this._clothingGloves = [null];
and the console log from the for..

Code:
Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object…][0 … 99]0: Objectsymbol: ""__proto__: Object1: Objectenabled: trueext: 6name: "a1b3b"symbol: "a1b3b"__proto__: Object2: Objectenabled: trueext: 6name: "a1b3d"symbol: "a1b3d"__proto__: Object3: Object4: Object5: Object6: Object7: Object8: Object9: Object10: Object11: Object12: Object13: Object14: Object15: Object16: Object17: Object18: Object19: Object20: Object21: Object22: Object23: Object24: Object25: Object26: Object27: Object28: Object29: Object30: Object31: Object32: Object33: Object34: Object35: Object36: Object37: Object38: Object39: Object40: Object41: Object42: Object43: Object44: Object45: Object46: Object47: Object48: Object49: Object50: Object51: Object52: Object53: Object54: Object55: Object56: Object57: Object58: Object59: Object60: Object61: Object62: Object63: Object64: Object65: Object66: Object67: Object68: Object69: Object70: Object71: Object72: Object73: Object74: Object75: Object76: Object77: Object78: Object79: Object80: Object81: Object82: Object83: Object84: Object85: Object86: Object87: Object88: Object89: Object90: Object91: Object92: Object93: Object94: Object95: Object96: Object97: Object98: Object99: Object[100 … 184]length: 185__proto__: Array[0]

it does start giving 0:null 1: object 2: object
then repeat object 1 and 2 forever
I was unable to replicate your issue, here is the code that I used to simulate it. I typed this into the console and I got the expected result (array of length 3 where index 0 is null, index 1/2 are objects).
Code:
var args = [6, 'a1b3b', 'a1b3d'];
var clothingactorid = args[0];
$gameActors._data[clothingactorid]._clothingGloves = [null];
var y = 1;
for (var i = 0; i < args.length-1; i++) {
$gameActors._data[clothingactorid]._clothingGloves.push({name: args[y], enabled: true});
y = y + 1;
}
console.log($gameActors._data[clothingactorid]._clothingGloves);
Spoiler
ConsoleScreenshot.png

it does start giving 0:null 1: object 2: object
then repeat object 1 and 2 forever

Are you sure?
Not according to the output which you pasted above.

  1. According to what you pasted, index 0 is an object with only the property of 'symbol' which is equal to "". It is not null.
    • What is 'symbol'? Where are you defining that?
    • There is another property in index 1 and 2 called 'ext'. What is that, where are you defining that?
  2. Can you show index 3 to confirm that it is a repeat of object 1 ? Can you show the 'name' property of index 3 ?
  3. It isn't going on forever.
    • If it went on forever then you wouldn't be able to get a console output
    • According to what you pasted, the length of the array is 185. What is the significance of 185?
Yes sorry.. with the push method even 0 should have the same value as other indexes..

as for symbol its part of what im using on the other method i just forgot to disable it for the results i showed you on the console.log
same for ext.. its the same.. i need extra values to operate what im doing.. (also forgot to remove it)

185 is when repeat stopped as i entered the main menu.. if i access it sooner repeat stops at lower number.. if im fast enough i can get main result + 1 repeat

Now to think about it.. a push like im doing using game interpreter is probably why it repeat itself nonstop.. while the currently working method i have only cycle thru the index i give thru args then stops..
Code:
    var Alias_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        Alias_Game_Interpreter_pluginCommand.call(this, command, args)
        if (command === 'setclothingGloves') this.modifyapp('clothingGloves', args);
    };

    Game_Interpreter.prototype.modifyapp = function(type, args) {
        if (!args) return;
        if (type === 'clothingGloves') {
              (where the push is..)
        }

Maybe using push there causes the nonstop repeat until you enter menu
Just from reading that code, it looks fine, I don't see anything there that would cause it to repeat over and over.

Like you said, it could be something weird going on with Game Interpreter if there are multiple active interpreters (though it still doesn't seem likely).
To test that hypothesis, maybe you could make the 'modifyapp' a function of Game_Actor rather than Game_Interpreter?

It really seems strange though, because as long as the 'for' loop is set up fine, it shouldn't repeat forever...

I'm sorry, but I think I'm out of ideas. I hope that you're able to figure this out, anyways, I think you were able to find a workaround so that's at least good.

EDIT:
@Lamoli40 Can you post a screenshot of the event which is using the plugin command? The entire event, so use Alt+PrintScreen to get the whole window.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/problem-pushing-args-into-a-array.90034/