Jump to content
Sign in to follow this  
Mephistox

[RGSS3] NoteTag Reader

Recommended Posts

Meph's NoteTag Reader (Scripter Tool)

MephistoX

 

Introduction

I didn't like the way that yanfly was reading some information from the notes, so i created my own code to read the data, i think is better this way.

 

Features

- Easy to use

- Easy to implement

- It has some pre-defined data returners

 

How to Use

 

1. Create a new script in the Materials part and paste the main script in int.

2. Define a new type of data in the RPG defined class (that has note space), like:

 

#==============================================================================
# ** Class RPG::Class
#==============================================================================

class RPG::Class
 #--------------------------------------------------------------------------
 # * Set Class Icon
 #--------------------------------------------------------------------------
 def icon
# Use NoteReader
NoteReader.get_data(note, 'Icon', :int)
 end
end

 

 

3. Go to your object label in the database and create a note, the system with read all the lines to look for the data, so remember that 1 line is 1 type of data.

 

You have to use the way:

 

Data => Value

(See the Image)

 

 

sinttulo2os.png

 

 

 

4. Finally use the data for whatever you want, in this case to test just call:

 

p $data_classes[x].icon

 

 

 

SCRIPT

 

 

 

#==============================================================================
# â–  Module NoteReader									   # Author: MephistoX
#------------------------------------------------------------------------------
# Description:
# ------------
# Read and Retrieve Information from notes based on a identifier
# It will return 'string' type data, but also incldues some defined returners
# to return data in type like symbols, strings, arrays, etc to make easy to
# read the data after.
#==============================================================================

module NoteReader
 #-------------------------------------------------------------------------
 #   Name	  : Get Parameter
 #   Info	  : Returns a String with a parameter
 #   Author	: MephistoX
 #   Call Info : note to read, parameter
 #-------------------------------------------------------------------------
 def self.get_parameter(note, parameter)
# Get data to process
dc_data = note.downcase.split("\r\n")
data	= note.split("\r\n")
# Set Result
result = nil
# Pass Through each data line
# If Line Text include parameter
dc_data.each_index do |i|
  next if dc_data[i].start_with?('#')
  # If Line Text include parameter
  if dc_data[i].include?(parameter.downcase)
	# Set Result as second element of line separated by '=>'
	result = data[i].split('=>')[1]
	# Break Loop
	break
  end
end
# Return Result to Sym if Transform
return result
 end
 #-------------------------------------------------------------------------
 #   Name	  : Get Data
 #   Info	  : Get Checked and Proccessed data
 #   Author	: MephistoX
 #   Call Info : text, parameter to search and type
 #-------------------------------------------------------------------------
 def self.get_data(text, parameter, type = :string)
# Set String
string = get_parameter(text, parameter)
# Set Result and Proccess it
result = process_result(string, type)
# Return Result
result
 end
 #-------------------------------------------------------------------------
 #   Name	  : Proccess Result
 #   Info	  : Proccess the result string and transform into the data
 #   Author	: MephistoX
 #   Call Info : string & type
 #-------------------------------------------------------------------------
 def self.process_result(string, type = :string)
# Return nil if no string
return nil if string.nil?
# Delete string whitespaces
r_string = string.strip
# Return the string downcased and to symbolo if type is sym
return r_string.downcase.to_sym if type == :sym
# Return integer if type is integer
return r_string.to_i if type == :int
# Return string if type is string
return r_string if type == :string
# Return Numeric hash if type is nhash
return to_nhash(r_string) if type == :nhash
# Return Array of Symbols if type is sarray
return to_array(r_string) if type == :array
 end
 #-------------------------------------------------------------------------
 #   Name	  : To Hash
 #   Info	  : Transform String into Hash
 #   Author	: MephistoX
 #   Call Info : String
 #-------------------------------------------------------------------------
 def self.to_nhash(string)
# Set Empty Hash
hash = {}
# Get Pairs Array
pairs = string.strip.split(',')
# Pass Through each pair (Array Data)
pairs.each do |pair|
  # Get Splitted Pair
  sp = pair.split(':')
  # Set Hash key to pair 0 index, and value to 1 index
  hash[sp[0].to_i] = sp[1].to_i
end
# Return Hash
hash
 end
 #-------------------------------------------------------------------------
 #   Name	  : To Array
 #   Info	  : Transform string into an array with symbols
 #   Author	: MephistoX
 #   Call Info : String, transform type (:sym or :int)
 #-------------------------------------------------------------------------
 def self.to_array(string, type = :sym)
# Set Empty Array
array = []
# Get Items
sitems = string.strip.split(',')
# Pass Through each item
sitems.each do |item|
  # Push string into symbol if transform type is to symbol
  array << item.strip.downcase.to_sym if type == :sym
  # Push String into integer if transform type is to integer
  array << item.to_i if type == :int
end
# Return Array
array
 end
end

 

 

 

 

FAQ

Q: Can you return other type of data?

A: Yes, i've included several ways and are.

:nhash => return a hash of integers like {1 => 11, 2 => 34, 3 => 55....etc.}

:array => return an array of (:int to integers, :sym to symbols)

:string => will return the original data that you set. (the string without transformation)

 

 

 

Credit and Thanks

- Created by MephistoX

- Credits not needed

- Post it wherever you want putting my name and don't remove the header or the header of the methods.

 

If you need help with the system, just ask, i know it's difficult by the way i explained it.

Edited by Mephistox

Share this post


Link to post
Share on other sites

Cool, but just out of curiosity what didn't you like about YF's note reading? I think perhaps an explanation might warrant more use for this script. I think I know why, but I don't want to assume.

Share this post


Link to post
Share on other sites

@gruffifth_Kun: I wanted something simple and quick instead of dealing with regexp and the way he handle the data didn't convince me.

about the instructions, i think it self explanatory as a tool for scripters.

Share this post


Link to post
Share on other sites

Nothing wrong with the way YF handles data. Regexp allows for better notetag reading capability than straight out one tag per one data pull.

 

Also, notetags benefit more with < and > headers and footers. Without them, your method would conflict in areas that search out words separate like 'debuff' and 'buff'.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted