RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[VXA][Solved]Notetag note working

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 55
RMRK Junior
I've created this script that is supposed to give all items and equipment a variable called "space". I've created a script so I can use notetags for this:

Code: [Select]
module DRAGONISW
   
  ITEM_SPACE = /<(?:SPACE|space):[ ](\d+)>/i
   
end # DRAGONISW

#==============================================================================
# ? DataManager
#==============================================================================

module DataManager
 
  #--------------------------------------------------------------------------
  # alias method: load_database
  #--------------------------------------------------------------------------
  class <<self; alias load_database_isw load_database; end
  def self.load_database
    load_database_isw
    load_notetags_isw
  end
 
  #--------------------------------------------------------------------------
  # new method: load_notetags_aim
  #--------------------------------------------------------------------------
  def self.load_notetags_isw
    groups = [$data_items, $data_weapons, $data_armors]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_isw
      end
    end
  end
 
end # DataManager

#==============================================================================
# ? RPG::BaseItem
#==============================================================================

class RPG::BaseItem
 
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :space
 
  #--------------------------------------------------------------------------
  # common cache: load_notetags_aim
  #--------------------------------------------------------------------------
  def load_notetags_isw
    @space = 0
    #---
    self.note.split(/[\r\n]+/).each { |line|
      case line
      #---
      when DRAGONISW::ITEM_SPACE
        @space = $1.to_i
      end
    } # self.note.split
    #---
  end
 
end # RPG::BaseItem


#==============================================================================
# Game_Interpreter
#==============================================================================
class Game_Interpreter
 
  def inv_item_space
    amount = 0
    for i in 0..999
      item = $data_items[i]
      amount += $game_party.item_number(item) * item.space
    end
    return amount
  end
 
end # Game_Interpreter

I try testing it out by calling the script code:
Code: [Select]
$game_variables[2] = inv_item_space

But I keep getting this error:
Quote
Script 'Game_Interpreter'  line 1409: NoMethodError occurred.

undefined method `space' for nil:NilClass
I tried testing it on a brand new game and I still got this error. I've looked at many script that use notetags and it seems like I'm doing it correctly, so I don't understand what I'm doing wrong.
« Last Edit: February 03, 2013, 11:23:37 PM by dragon3025 »

*
Rep:
Level 82
The first element of $data_items, $data_weapons and $data_armors is a nil value. This is because there isn't an item with ID of 0. It starts at 1. This is the same for any of the other information in the database too.

You will want to move to the next ID if the item found is nil:

Something like:

Code: [Select]
  def inv_item_space
    amount = 0
    for i in 0..999
      item = $data_items[i]
      next if item.nil?
      amount += $game_party.item_number(item) * item.space
    end
    return amount
  end

should help avoid that.
(Why do I always feel like it's the end of the world and I'm the last man standing?)

**
Rep: +0/-0Level 55
RMRK Junior
The first element of $data_items, $data_weapons and $data_armors is a nil value. This is because there isn't an item with ID of 0. It starts at 1. This is the same for any of the other information in the database too.

You will want to move to the next ID if the item found is nil:

Something like:

Code: [Select]
  def inv_item_space
    amount = 0
    for i in 0..999
      item = $data_items[i]
      next if item.nil?
      amount += $game_party.item_number(item) * item.space
    end
    return amount
  end

should help avoid that.
Thanks that worked perfectly. It's funny because I tried making it "for i in 1..999", but that didn't work either.

*
Rep:
Level 82
I gave that a go too, but that came up with the same error: a "no method for nil:NilClass". This just ensures that you won't be calling the method on a nil object.
(Why do I always feel like it's the end of the world and I'm the last man standing?)

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, you could limit it to the number of items in the array, so instead of 0..999, it could be:

Code: [Select]
for i in 1...$data_items.size

But anyway, the nil check does the trick too and there might be some custom scripts out there which would make it so that some elements were nil even limiting it to the size of $data_items.