checking an items note tag from game_event

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
i have a script I've been editing and I'm trying to select a key item then check if that item has the note tag <seed 1> if it does take the number after seed and pass it along otherwise throw a message to the player that the item wasn't a seed.

here is some of the script:

Code:
module FARM_PARAMS
  SEED = 21
end

Plant = {
  #turnip
  1 => {:item => [:item,17,[1,4]],
        :level => 1,
        :timer => 1,
        :base_chance => 75,
        :max_chance => 100,
        :chance_mod => 5,
        :graphic => ["$Turnip",0],
        :sound => ["Jump1",75,1,3]},
        :persist => "false",
}

class game_event

def plant_id
  if FARM_PARAMS::SEED != nil
    return seed_to_plant #part i'm having trouble with.
  end
end

def farm_data
  return Plant[plant_id]
end

def farm_start
  $game_message.item_choice_variable_id = FARM_PARAMS::SEED
  if farm_data != nil
    #code goes here using "farm_data"
  end
end

class RPG::Item
  def seed_to_plant
    seed = $data_items[FARM_PARAMS::SEED]
    if seed.note =~ /<seed (.*)>/i
      return $1.to_i
    else
      $game_message.add("This item isn't a seed")
      return nil
    end
  end
end

end
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,354
Reaction score
8,533
First Language
English
Primarily Uses
RMMV

I've moved this thread to Learning RGSS. Please be sure to post your threads in the correct forum next time. Thank you.

 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
Thank you. I'm new to ruby and I'm picking it up fast but there are some things im just not used to. I've programed in visual basic and c# before so I think i can get the hang of it fast. I just started ruby yesterday.

I see some errors i made. I'm referencing PARAMS_SEED but i need to tell it to get the value of the variable[PARAMS_SEED]
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
I think I found a bit of code that might help. I've typed it here before trying to implement it. Please help if you see something wrong.

Code:
class RPG::BaseItem
  def read_notetags
    if @note =~ /<seed (.*)>/i
      @seed = eval("lambda {  |event| $1.to_i } ")
      return
    end
  end
end

class Game_Event
  def run_notetag(item)
    item.seed.call(self)
  end
end
edit: I guess I don't know what I'm doing as I can't get this to work
 
Last edited:

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
is there just a way to get this to work? i get the error Undefined method 'note' nil:NilClass

Code:
class Game_Event
  def plant_id
    if $data_items[$game_variables[FARM_PARAMS::SEED]].note =~ /<seed (.*)>/i
      return $1.to_i
    end
end
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
I think my best bet would be to load all the notes when the DataManager loads it's database and assign a variable in the item with the note. but now i still don't know how to reference the variable on the item selected by $game_message.item_choice_variable_id called on an event start.

Code:
module DataManager
  class <<self; alias load_database_seeds load_database; end
  def self.load_database
    load_database_seeds
    load_notetags
  end
  def self.load_notetags
    groups = [$data_items]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags
      end
    end
  end
end

class RPG::UsableItem < RPG::BaseItem
  attr_accessor :seed_id
  def load_notetags
    @seed_id = 0
    self.note.split(/[\r\n]+/).each {|line| 
    case line 
    when /<seed (.*)>/i
      @seed_id = $1.to_i
    end }
    @seed_id = 0 if @seed_id <= 0
  end
end
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
generically speaking.

Code:
arr = $items.collect {|i| i.item_id, i.note}.select {|entry| entry[1] =~ "/^(seed)/i"}.collect{|entry| entry[0]}
from database items collect ID and notes, filter notes ~= "seed", return item ID
with the resulting array, you go locate the items which are seeds.

that should be the core logic
if you need to adapt it, ask what you need to know.... that's a rough guess.
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
Code:
arr = $items.collect {|i| i.item_id, i.note}.select {|entry| entry[1] =~ "/^(seed)/i"}.collect{|entry| entry[0]}
I'm not sure if I can use this. what I'm trying to do is when a specific even is started ask the player to select an item($game_message.item_choice_variable_id=$game_variables[x]) if that item has a note tag with <seed 1> then return the number in that note(1).

all the code I have so far is:

Code:
module FARM_PARAMS
 
  SEED = 21
 
end

FARMING_OBTAINED_STRING = '"Obtained \\\i[#{item.icon_index}] #{item.name} x#{amount}."'
FARMING_GATHERFAIL_STRING = "Failed to gather resource."
FARMING_LOWLEVEL_STRING = '"Level #{node_data[:level]} required."'
FARMING_TOOLREQ_STRING = '"Tool \\\i[#{item.icon_index}] #{item.name} required."'

Plant = {
  #turnip
  1 => {:item => [:item,17,[1,4]],
        :level => 1,
        :timer => 1,                      #in-game hours until grown decided by another script
        :base_chance => 75,
        :max_chance => 100,
        :chance_mod => 5,
        :graphic => ["$Turnip",0],
        :sound => ["Jump1",75,1,3]},
        :persist => "false",
       
}



class Game_Event
  alias farm_update update
  alias gather_start start
  alias farm_init setup_page
  def setup_page(*args)
    farm_init(*args)
    @@empty_plot = true
    @@days_to_grow = 0
    @@hours_until_full = 0
  end
 
  def event_timer(rate)
    if farm_data != nil
      @@hours_until_full += rate if @@hours_until_full < farm_data[:timer].to_i
      return farm_data[:timer].to_i - @@hours_until_full
    else
      return 0
    end
  end
  def farmland
    @event.name.include?("Farmland")
  end
  def plant_id
    if $data_items[$game_variables[FARM_PARAMS::SEED]].seed_id > 0
      return $data_items[$game_variables[FARM_PARAMS::SEED]].seed_id
    else
      $game_message.add("This item isn't a seed")
      return nil
    end
  end
  def farm_data
    Plant[plant_id]
  end
  def start
    farmland ? farm_start : gather_start
  end
  def grown
    if event_timer(0) <= 0 && empty_plot == false
      return true
    else
      return false
    end
  end
  def anim_stages
    if farm_data != nil
      if @@days_to_grow < farm_data[:timer].to_i / 4
        @@days_to_grow = 0
        if @@dir < 8
          @@dir += 2
        end
        @direction = dir
      end
    end
  end
  def farm_start
    if plant_id != nil
      if @@empty_plot == true
        $game_message.add("What would I like to plant?")
        $game_message.item_choice_variable_id = FARM_PARAMS::SEED
        return no_tool if !carrying_tool?
        return no_level if farm_data[:level] > $game_party.highest_level
        #persist = farm_data[:persist].to_s == 'true' ? true : false
        graphic = farm_data[:graphic]
        @character_name = graphic[0]
        @character_index = graphic[1]
        @@days_to_grow = 0
        @@dir = 8
        @direction = dir
        end
      if grown
        $game_party.gathering = true
        if gather_success
          item_d = farm_data[:item]
          item = $data_items[item_d[1]] if item_d[0] == :item
          item = $data_weapons[item_d[1]] if item_d[0] == :weapon
          item = $data_armors[item_d[1]] if item_d[0] == :armor
          msgbox("Invalid item category") unless item
          amount = rand(item_d[2][1] - item_d[2][0]) + item_d[2][0]
          $game_party.gain_item(item,amount)
          $game_message.add(eval(FARMING_OBTAINED_STRING))
        end
        if farm_data[:sound]
          farm_data[:sound][2].times do |i|
            Audio.se_play("Audio/SE/" + farm_data[:sound][0],farm_data[:sound][1])
            node_data[:sound][3].times do |i|
              Graphics.update
              SceneManager.scene.update
            end
          end
        end
        $game_party.gathering = false
      end
    end
  end
  def carrying_tool?
    if plant_id != nil
      item_d = farm_data[:tool]
      return true if item_d.nil?
      item = $data_items[item_d[1]] if item_d[0] == :item
      item = $data_weapons[item_d[1]] if item_d[0] == :weapon
      item = $data_armors[item_d[1]] if item_d[0] == :armor
      return $game_party.has_item?(item)
    end
  end
  def unerase
    @erased = false
    refresh
  end
  def erased?; @erased == true; end
  def event_id; @id; end
  def no_level
    $game_message.add(eval(FARMING_LOWLEVEL_STRING))
  end
  def no_tool
    if plant_id != nil
      item_d = farm_data[:tool]
      item = $data_items[item_d[1]] if item_d[0] == :item
      item = $data_weapons[item_d[1]] if item_d[0] == :weapon
      item = $data_armors[item_d[1]] if item_d[0] == :armor
      $game_message.add(eval(FARMING_TOOLREQ_STRING))
    end
  end
  def gather_success
    if plant_id != nil
      empty_plot = true
      chance = farm_data[:base_chance]
      chance += farm_data[:chance_mod] * ($game_party.highest_level - farm_data[:level])
      chance = [chance,farm_data[:max_chance]].min
      if rand(100) < chance
        return true
      else
        $game_message.add(FARMING_GATHERFAIL_STRING)
        return false
      end
    end
  end
end

module DataManager
  class <<self; alias load_database_seeds load_database; end
  def self.load_database
    load_database_seeds
    load_notetags
  end
  def self.load_notetags
    groups = [$data_items]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags
      end
    end
  end
end

class RPG::UsableItem < RPG::BaseItem
  attr_accessor :seed_id
  def load_notetags
    @seed_id = 0
    self.note.split(/[\r\n]+/).each {|line| 
    case line 
    when /<seed (.*)>/i
      @seed_id = $1.to_i
    end }
    @seed_id = 0 if @seed_id <= 0
  end
end

class Game_Map
  alias farm_set setup_events
  alias farm_up update_events
  def setup_events
    farm_set
    @events.each_value do |event|
      next unless event.farmland
      event.erase if event.event_timer(0) > 0
    end
  end
  def update_events
    farm_up
    @events.each_value do |event|
      next unless event.farmland && event.erased?
      event.unerase if event.event_timer(0) == 0
    end
  end
end
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
so, at item selection time, pop up a message based on that item?
you can simply react to whatever item is selected, from scene_item.item (I believe... let me check the function)

yep....
Scene_Item.item will return the last item selected/used

to grab the note tag:
Code:
item = Scene_Item.item
tag, id = item.note =~ "/^<(seed) (\n)>"/i ? (true, $1) : (nil, nil)
if tag
 #<here your process involving id>
end
that should be quick and simple, without having to load one line at a time
it won't be fool-proof though
if you mess up the definition of lines of <seed X>, it won't work
 
Last edited:

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
I need to know what kind of seed the key item is or even if it is a seed. I use the note tag <seed #> to determine what id the seed should have. I need to pass that id to figure out what stat block to use.

if the note on the selected key item reads <seed 1> it would pass a 1 from the note to figure out what plant it is
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
(check the previous edit)
look at it this way:
ID relates to "seed"
"seed" is encapsulated as <seed #>
you can grab <seed, whatever follows, and whatever follows, followed by ">"
meaning, you can grab a whole line
grab whatever whole line you have, from item.note, which you get from item, which you get from scene_item, and compare it to you reference.
if it matches, you've got it.

instead of grabbing one thing at a time, grab the whole thing and just take it if it matches your reference.
you don't need checks for validation if everything will match one reference, and one reference only.
you only need validations when setting the code up for multiple inputs over which you don't have control
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
something is wrong... I'm getting the error on this bit saying:
=~ "/^<(seed) (\n)>"/i ? (true, $1) : (nil, nil) cant assign to true

I've tried this too

Code:
      $game_message.item_choice_variable_id = FARM_PARAMS::SEED
      item = Scene_Item.item
      if item.note =~ "/^<(seed) (\n)>"/i
        @@plant_id = $1.to_i
      else
        $game_message.add("This item isn't a seed")
        @@plant_id = 0
      end
that bit of code gets me a Undefined meathod 'item' for class Scene_Item
 
Last edited:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
that bit of code gets me a Undefined meathod 'item' for class Scene_Item
you don't put it right like that into the program and it works.
you have to direct it to your objects.

Scene_Item is *your* scene_item, where you get the item from.

try this to fix the other error
Code:
"/^<(seed) (\n)>"/i ? [true, $1] : [nil, nil]
replace parentheses with brackets.

I thought it would interpret true and $1 as separate instructions, so I put the parenthesis in there.
brackets should turn it into an array, which should still load right into [tag, id]
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
how would I go about calling scene_item.item in my event class under my start method?
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,074
Members
137,578
Latest member
JamesLightning
Top