fairly easy js scripting question.

Hello, I'm kinda new to this so i'll just start. 

i was scripting today and got stuck on something seemingly really simple

or it should be at least since it should already be in the code provided with mv.

I'm making a customized  menu for my game and for the life of me I just cant seem to figure out how to "drop" or "toss" (get rid of) items and since it's quite essencial to the whole system my game revolves around, i am essencially sutck.

I've been trying to solve the problem for a whole day now and I've made virtually no progress on that front. 

If it's possible for anyone to provide any assistance I'd very much appreciate it.  
Can you explain what "drop" or "toss" means?  What sort of script are you trying to write?

Since it's obviously something to do with selecting items, I'd look at the Window_Item and Scene_Item as a starting point.  
Thanks for the advice.

By "drop" i mean to delete the or a selected item.    
So are you letting the player select an item to "throw away"?

In that case you'd do it almost exactly as the Scene_Item, except on the OK logic, you would just remove the item from inventory rather than go through the choose a target & use it process.

(using $gameParty.gainItem(...))
Yes, that's exactly what i want to implement. 

ok i'll try again. Thank you for your help.  😀
;_;   It doesn't work i think i maybe doing something wrong. I keep getting weird errors.
🙂  You need to give more information that that.  We can't guess what your script looks like, how you've written the command, or what the errors are.

What are the errors?  What does your script look like?  If you turn on dev tools (F8) when playing, what does the console say as far as the list of errors?
i cant make heads or tales of it most of the time but thats what i get.

 

_______________________________________________________________________________________________________________________________

TypeError: Cannot read property 'width' of undefined

    at Scene_GameEnd.Scene_ItemBase.showSubWindow (file:///C:/Users/Zach/Documents/Games/test%20&%20dev%20for%20plugins/js/rpg_scenes.js:919:64)

    at Scene_GameEnd.Scene_GameMenu.determineItem (file:///C:/Users/Zach/Documents/Games/test%20&%20dev%20for%20plugins/js/plugins/in_game_main_menu.js:1201:14)

    at Scene_GameEnd.Scene_GameMenu.onItemOk (file:///C:/Users/Zach/Documents/Games/test%20&%20dev%20for%20plugins/js/plugins/in_game_main_menu.js:1178:10)

    at Window_ItemList.Window_Selectable.callHandler (file:///C:/Users/Zach/Documents/Games/test%20&%20dev%20for%20plugins/js/rpg_windows.js:896:31)

    at Window_ItemList.Window_Selectable.callOkHandler (file:///C:/Users/Zach/Documents/Games/test%20&%20dev%20for%20plugins/js/rpg_windows.js:1165:10)

    at Window_ItemList.Window_Selectable.processOk (file:///C:/Users/Zach/Documents/Games/test%20&%20dev%20for%20plugins/js/rpg_windows.js:1150:14)

    at Window_ItemList.Window_Selectable.processHandling (file:///C:/Users/Zach/Documents/Games/test%20&%20dev%20for%20plugins/js/rpg_windows.js:1021:18)

    at Window_ItemList.Window_Selectable.update (file:///C:/Users/Zach/Documents/Games/test%20&%20dev%20for%20plugins/js/rpg_windows.js:978:10)

    at file:///C:/Users/Zach/Documents/Games/test%20&%20dev%20for%20plugins/js/rpg_core.js:5734:19

    at Array.forEach (native)

________________________________________________________________________________________________________________________________
and your script?  Remember to use code tags to keep the formatting, and spoiler tags to make it small.

It's saying it's trying to access a width property, but the object it belongs to is not defined.

It looks like you might have copied the script a little too closely, and it may be trying to load a window where you can choose who to apply the item to.
okay..the method in question.

Spoiler
Scene_GameMenu.prototype.determineItem = function() {

    var action = new Game_Action(this.user());

    var item = this.item();

    action.setItemObject(item);

        if(action.isForFriend()) {

        this.showSubWindow(this._actorWindow);

        this._actorWindow.selectForItem(this.item());

    } else {

        this.useItem();

        this.activateItemWindow();

    }

    

    console.log(item);

    

      if(item_m_type == 1)

        {

        action.setItemObject(item);

        }

    

        if(item_m_type == 2)

        {

         $gameParty.loseItem(this._item, this.item.id);

            console.log(item);

        }

   

    

};
I suspect this whole block:

      if(action.isForFriend()) {        this.showSubWindow(this._actorWindow);        this._actorWindow.selectForItem(this.item());    } else {        this.useItem();        this.activateItemWindow();    }needs to go into the item_m_type == 1 block, because I'm assuming when item_m_type is 1, you want it to behave like a normal item.

However, what is item_m_type?  You don't define it in this function, and it's not a property of the item.  That's going to cause an error as well.

Also, your loseItem takes the item object and the quantity you want to lose.  You're passing it the item object and the id of the item rather than the quantity.  That'll cause another problem later - it won't crash, but it won't always give you the results you're expecting.
Oh,   :headshake: i knew i was doing something wrong. 

lol my bad, alright i'll check and report my findings.  🙂
Oh and you're correct item_m_type is a global variable i created for that exact purpose.
ok i've adjusted it and it now looks like 

Spoiler
Scene_GameMenu.prototype.determineItem = function() {

    

    

    console.log(item);

       var action = new Game_Action(this.user());

    var item = this.item();

    var item_amnt = 1;

    action.setItemObject(item);

    

      if(item_m_type == 1)

        {

        if(action.isForFriend()) {

        this.showSubWindow(this._actorWindow);

        this._actorWindow.selectForItem(this.item());

    } else {

        this.useItem();

        this.activateItemWindow();

    }

        }

    

        if(item_m_type == 2)

        {

         this.dropItem(item_amnt);     

        }

 

    

};

 

Scene_GameMenu.prototype.dropItem = function(number) {

    $gameParty.loseItem(this._item, number);

};

only it freezes everything so i'm once again lost. 🤔   
Might be a stray squirly bracket (I've just woken up and cannot remember what they are called!) before if item type 2. Cannot tell very easily though. [code.] tags are your friend.
ok ive solved it. Partially at least and you guys were a big help. below is what the code looks like now.

However I'm unable to erase weapons or armor since those, can't be used up, heck they're greyed out in any

scene thats not for equiping or selling.    

Spoiler
Scene_GameMenu.prototype.determineItem = function() {

    

    console.log(item);

       var action = new Game_Action(this.user());

    var item = this.item();

    var item_amnt = 1;

    action.setItemObject(item);

    

      if(item_m_type == 1)

        {

        if(action.isForFriend()) {

        this.showSubWindow(this._actorWindow);

        this._actorWindow.selectForItem(this.item());

    } else {

        this.useItem();

        this.activateItemWindow();

    }

        }

    

        if(item_m_type == 2)

        {

        this.useItem2();

        this.activateItemWindow();

            console.log("toss this item");

        }

    

        /*if(item_m_type == 3)

        {

        

        }*/

    

};

 

Scene_GameMenu.prototype.dropItem = function(number) {

    $gameParty.loseItem(this._item, number);

};

 

Scene_ItemBase.prototype.useItem2 = function() {  // drop item

    this.playSeForItem(); // change this to an erase sound

    this.user().useItem(this.item());

    //this.applyItem();

    this.checkCommonEvent();

    this.checkGameover();

    this._actorWindow.refresh();

};

i'll try my luck again though. i might be able to figure this out.  BD   GO ME!

Once again i'll report my findings.

Original thread: https://forums.rpgmakerweb.com/threads/fairly-easy-js-scripting-question.52569/