I found an item storage script, but it gives me an error.

http://forum.chaos-project.com/index.php?topic=3444.0


<snip>


When I call a new chest, I get an error on this line:


if @chests[n] == nil


saying undefined method [] for nil class. What does that mean?


Thanks
I'm not familiar with this script, but did you simply copy and paste it into your script tab? If so, I think it is telling you "nil" because there aren't any chests configured?:

#==========================================================================    # Config Chest Items    # Use this    # when chest_id then return [[id, amount, type], [id, amount, type]]    # id = item, weapon, or armor id    # amount = the amount    # type = 0, 1, or 2 0 = item, 1 = weapon, 2 = armor    # Example:    # when 1 then return [[1, 3, 0], [1, 1, 1]]    # This has 3 potions, and 1 bronze sword. So when this is called    # $scene = Scene_Chest.new(1)    # it will have those items in the chest already.    #==========================================================================    when 1 then return []    end    return []Have you setup a chest as specified?
I predefined a chest:

#========================================================================== # Config Chest Items # Use this # when chest_id then return [[id, amount, type], [id, amount, type]] # id = item, weapon, or armor id # amount = the amount # type = 0, 1, or 2 0 = item, 1 = weapon, 2 = armor # Example: # when 1 then return [[1, 3, 0], [1, 1, 1]] # This has 3 potions, and 1 bronze sword. So when this is called # $scene = Scene_Chest.new(1) # it will have those items in the chest already. #========================================================================== when 1 then return [[1, 3, 0], [1, 1, 1]] end return []and I called it exactly how it says, by using $scene = Scene_Chest.new(1) (for chest #1). Same error. Also, that section is to have items in the chest already, which I don't want. I'm really lost 🙁
I have removed the script from your post. When you are using a script you downloaded and you need help with it, please JUST post a link - don't add the whole script to your post.


I would almost wager you had a saved game, added the script, then loaded your saved game. You need to start a new game after adding this script (and many others).
I have removed the script from your post. When you are using a script you downloaded and you need help with it, please JUST post a link - don't add the whole script to your post.

I would almost wager you had a saved game, added the script, then loaded your saved game. You need to start a new game after adding this script (and many others).
Ah, should of thought of that. Alright, it works now. Thanks.

Edit: Darn, new error. Ok, so now it works, and I can store items and weapons in the chest. But when I store armor, I get this error:

undefined method `element_set' for #<RPG::Armor:0x8006db0>

What's wrong now? 🙁
I don't have my laptop with me.


You ARE making an RMXP project? Does armor have elements? Or does that require another script?


Can you give the COMPLETE error message (there should be a script name and line number)
I don't have my laptop with me.

You ARE making an RMXP project? Does armor have elements? Or does that require another script?

Can you give the COMPLETE error message (there should be a script name and line number)

This is RMXP.

I don't really understand what this script means by elements to be honest. I know it's used to make items non-storable, but I dont know how to define the elements in armor, like is it literally the element checkboxes in the database? I dont know. And I cant test cause I get an error. And yes, the error:

http://tinypic.com/r/9kwac4/8
Yes, element_set is the list of checkboxes for elements - or not checkboxes, but the boxes where you select A-F for strength. I think (don't have laptop again) if there is a list of elements for armor, it's the elements you're protected against when you have that armor on.


That does seem a bit weird, unless you have other scripts that redefine the classes and don't include that variable.


Are you able to zip up your project folder and load it up somewhere so someone can take a look?
Yes, element_set is the list of checkboxes for elements - or not checkboxes, but the boxes where you select A-F for strength. I think (don't have laptop again) if there is a list of elements for armor, it's the elements you're protected against when you have that armor on.

That does seem a bit weird, unless you have other scripts that redefine the classes and don't include that variable.

Are you able to zip up your project folder and load it up somewhere so someone can take a look?
Well, I'm basically using Moghunter's XAS ABS. So if this script that work with that, it can work with my game.

https://xasabs.wordpress.com/xas-v3-91-by-moghunter/
Hi,

The script checks an items element set to check if the item should be treated as a key item. In RMXP, the method uses to access this set is called  element_set  for items and weapons, and   guard_element_set  for armors. The script considers that difference most of the time, except in line 516 where element_set is called regardless of the item type.

This line is executed when you try to move an item from the partys inventory into a chest.

You could fix that by...

1) ...either define element_set for armors (what I'd personally recommend):

class RPG::Armor  def element_set    guard_element_set  endend2) ...or change the said line from
if @item.element_set.include?(GameGuy::KeyItemId)

to

if (@item.is_a?(RPG::Armor) ? @item.guard_element_set : @item.element_set).include?(GameGuy::KeyItemId)
Hi,

The script checks an items element set to check if the item should be treated as a key item. In RMXP, the method uses to access this set is called  element_set  for items and weapons, and   guard_element_set  for armors. The script considers that difference most of the time, except in line 516 where element_set is called regardless of the item type.

This line is executed when you try to move an item from the partys inventory into a chest.

You could fix that by...

1) ...either define element_set for armors (what I'd personally recommend):

class RPG::Armor  def element_set    guard_element_set  endend2) ...or change the said line from

if @item.element_set.include?(GameGuy::KeyItemId)

to

if (@item.is_a?(RPG::Armor) ? @item.guard_element_set : @item.element_set).include?(GameGuy::KeyItemId)
Thanks, that fixed the error, but I still don't understand what this script means by KeyItemId. How exactly would I make an item not being able to be stored? What would I write as a value for KeyItemId?

  #============================================================================

  # KeyItemId       = Element ID for non removable items.

  #                   Items/weapons/armors with marked with this element

  #                   cannot be removed.

  #============================================================================

  KeyItemId         = 1

So if I want an armor piece to not get stored, it needs to have element 1, which is the Fire checkbox in the default case? I'm not sure if I'm even on the right track 😛
So if I want an armor piece to not get stored, it needs to have element 1, which is the Fire checkbox in the default case? I'm not sure if I'm even on the right track 😛
In case you didn't find out already: exactly this. 🙂
In case you didn't find out already: exactly this. 🙂
Wow, I was right. Cool, everything is working fine now 🙂 . Thanks.

Original thread: https://forums.rpgmakerweb.com/threads/i-found-an-item-storage-script-but-it-gives-me-an-error.37562/