How to use "splice" ?

Hi guys,

I'm looking for create a window for delete an item in the scene skill.

But, i don't understand, i try this :

Code:
Scene_Skill.prototype.onForgetOK = function(){
   this.actor().forgetSkill();
   SoundManager.playEquip();
};

Game_Actor.prototype.forgetSkill = function() {
   var item = this.item();
   this._skills.splice(item, 1);   
};

Obviously this don't work...

How to use correctly "splice" ?
Of corse, i looking for removed the last item selected, not a indexID like 1, 2, 3...
Splice cuts out a certain number of items from an array. It takes 2 arguments. The first argument is the starting index and the second argument is the number of items that should be removed.

PHP:
var arr = [1, 2, 3, 4];
// Remove the first 3 items
arr.splice(0, 3);
// arr is now [4]

var arr = [1,2,3];
// Remove the second item
arr.splice(1, 1);
// arr is now [1, 3]

var arr = [1, 2, 3, 4];
// Remove the last two items
arr.splice(arr.length - 2, 2);
// arr is now [1, 2]

var arr = [1, 2, 3];
// Remove the last item of the array
arr.splice(arr.length - 1, 1);
// arr is now [1, 2]

You can also remove a certain item. However, for this you would need to find the actual index where that specific items is in the array.

PHP:
var arr = [1,2, 5, 3, 4];
// Get the index where 5 is
var index = arr.indexOf(5);
// Remove 5 from the array
arr.splice(index, 1);
// arr is now [1, 2, 3, 4]

In your case you don't need to touch the splice method, you can just use the forgetSkill method. The forgetSkill method takes the id of the skill that should be removed, so you can just get the id of the selected skill and pass it to the forgetSkill method.
PHP:
Scene_Skill.prototype.onForgetOK = function () {
    var skill = this.item();
    if (skill) {
        var skillId = skill.id;
        this.actor().forgetSkill(skillId);
        SoundManager.playEquip();
    }
};
Splice requires you to provide the index to know what to delete, so what you could do is try to find the item by doing a loop then check if its the same item. That in turn will provide you the index.
Code:
Scene_Skill.prototype.onForgetOK = function(){
   this.actor().forgetSkill();
   SoundManager.playEquip();
};

Game_Actor.prototype.forgetSkill = function() {
   var item = this.item();

var index; //
for(var i = 0; i < this._skills.length; i++)
{
   if(this._skills[i] == item)
   {
      index = i;
   }
}

if(index != null)
{
   this._skills.splice(index, 1);
}

};
Just a small side note.

@TyberAlyx @fab_54700
In both of your code snippets you actually override the default forgetSkill method. I would advise you against that, because that method is used several places inside the MV Core Code and when you change it's behavior it will not work how it's supposed to work. Instead of overriding you can just create a new function for your behaviour.
@waynee95 , thank you so mush, this work now !
My logic was wrong, i don't think correctly, now i see your code, this were basic...

I left the source code in the rpg_objects and only change the scene.

still tks !

Original thread: https://forums.rpgmakerweb.com/threads/how-to-use-splice.84316/