Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> TagNote v2.0, A simple system for pulling values out of the notes field
Queex
post Mar 20 2008, 05:15 AM
Post #1


Level 6
Group Icon

Group: Member
Posts: 75
Type: None
RM Skill: Beginner




TagNote
Provides a means for pulling tag/value pairs out the notes field for anything. This enables simple storage of extra parameters for other scripts in a way that won't work at cross-purposes with itself or other uses for the notes field.

Note that you will probably need to put this script before any others that use it.

In any notes field, you can write: <tag_name tag_value> to store tag_value under the name tag_name. You can also store nothing, if no value is needed, through <tag_name> in the notes field. This slightly updated version supports additional parameters in the tag name.

Download: http://chthonic.150m.com/scratch/Queex_scripts.zip

CODE
###############
# TagNote #
######################################################################
# Version 2.0 #
# Author: Queex #
# Licence: Creative Commons non-commercial attributive #
######################################################################
# Allows the easy use of tags in the note field for #
# objects to store data. Syntax is simple, and the system ignores #
# any lines in the notes field that don't match the syntax. #
# #
# Version history: #
# 1.2 Final 1.x version #
# 2.0 Changed to follow Ruby naming conventions #
# #
# Usage: #
# get_tag(<notes field>,<tag name>) #
# has_tag?(<notes field>,<tag name>) #
# has_tag_value?(<notes field>,<tag name>,<tag value>) #
# get_additional_tag(<notes field>,<tag name>,<index> #
# get_additional_tag_by_value(<notes field>,<tag name>,<tag value> #
# ,<index> #
# #
# Syntax in the note field: #
# <tag_name tag_value> #
# <tag_name> #
# <tag_name tag_value param1 param2 ...> #
######################################################################

module TAGNOTE

###########
# get_tag #
###################################################################
# Gets the stored value of the first occurrence of the named tag #
# in the notes field. #
# <tag_name tag_value tag_value2> will return 'tag_value' #
# <tag_name tag_value> will return 'tag_value' #
# <tag_name> will return true #
# if no tag with tag_name, returns nil #
###################################################################
def get_tag(note_field, tag_name)
lines=note_field.split("\n")
for line in lines
#process line by line
if line[0,1].eql?("<")
#this line has a tag
line2=line.split(/[<> ]/)
if line2[1].eql?(tag_name)
if(line2.length==2)
#there is actually no value
return true
else
return line2[2]
end
end
end
end
return nil
end

############
# has_tag? #
##################################################################
# Indicates whether the given note field has a tag of that name. #
# <tag_name tag_value tag_value2> and #
# <tag_name tag_value> and #
# <tag_name> will both return true #
# if no tag with tag_name, returns false #
##################################################################
def has_tag?(note_field,tag_name)
lines=note_field.split("\n")
for line in lines
if line[0,1].eql?("<")
line2=line.split(/[<> ]/)
if line2[1].eql?(tag_name)
return true
end
end
end
return false
end

##################
# has_tag_value? #
#################################################################
# Indicates whether the note field has a tag of a given name #
# with a certain value. #
# <tag_name tag_value> returns true #
# <tag_name wrong_tag_value> returns false #
# <tag_name> returns false #
# if no tag with tag_name has the correct value, returns false. #
# tag_value2 is ignored #
#################################################################
def has_tag_value?(note_field,tag_name,tag_value)
lines=note_field.split("\n")
for line in lines
if line[0,1].eql?("<")
line2=line.split(/[<> ]/)
if line2[1].eql?(tag_name) and line2[2].eql?(tag_value)
return true
end
end
end
return false
end

######################
# get_additional_tag #
######################################################################
# Gets additional parameters for a tag of a given name. #
# Calling with an index of 1 returns #
# the first value after the tag name. #
# Returns nil if the index is higher than the last parameter. #
# Returns false if no match for the tag name is found. #
######################################################################
def get_additional_tag(note_field,tag_name,index)
lines=note_field.split("\n")
for line in lines
if line[0,1].eql?("<")
line2=line.split(/[<> ]/)
if line2[1].eql?(tag_name)
if(line2.length<index+2)
#Actually no value to get
return nil
else
return line2[index+1]
end
end
end
end
return false
end

###############################
# get_additional_tag_by_value #
######################################################################
# Gets additional parameters for a tag of a given name #
# with a certain value. Calling with an index of 1 returns #
# the first value after the tag name. #
# Returns nil if the index is higher than the last parameter. #
# Returns false if no match for the tag name and tag value is found. #
######################################################################
def get_additional_tag_by_value(note_field,tag_name,tag_value,index)
lines=note_field.split("\n")
for line in lines
if line[0,1].eql?("<")
line2=line.split(/[<> ]/)
if line2[1].eql?(tag_name) and line2[2].eql?(tag_value)
if(line2.length<index+2)
#Actually no value to get
return nil
else
return line2[index+1]
end
end
end
end
return false
end

end


Enjoy.

UPDATED: to v2.0

This post has been edited by Queex: Apr 4 2008, 05:04 PM
Go to the top of the page
 
+Quote Post
   
Twilight
post Mar 29 2008, 12:08 AM
Post #2


Real name, Lily White
Group Icon

Group: Revolutionary
Posts: 227
Type: Developer
RM Skill: Advanced




The formatting is broke in the script. Mind uploading it in a text file?
Go to the top of the page
 
+Quote Post
   
Queex
post Mar 29 2008, 02:12 AM
Post #3


Level 6
Group Icon

Group: Member
Posts: 75
Type: None
RM Skill: Beginner




'Tis done.
Go to the top of the page
 
+Quote Post
   
YanXie
post Apr 1 2008, 12:00 AM
Post #4


Because Tomorrow Will Surely Come...
Group Icon

Group: Revolutionary
Posts: 1,137
Type: None
RM Skill: Skilled




I just realize that this script is really usefull to get my script done,wow,I feel dumb.


__________________________
how make teleport to graveyard then your character die?

AWAY FOR VACATION.
NOT HERE UNTIL JAN/FEB 2010 -w-/
Go to the top of the page
 
+Quote Post
   
Hadriel
post Apr 2 2008, 06:30 AM
Post #5



Group Icon

Group: Member
Posts: 1
Type: Artist
RM Skill: Masterful




Could you create a little demo because I don't really understand what this script does...
Go to the top of the page
 
+Quote Post
   
Queex
post Apr 2 2008, 06:44 AM
Post #6


Level 6
Group Icon

Group: Member
Posts: 75
Type: None
RM Skill: Beginner




QUOTE (Hadriel @ Apr 2 2008, 02:44 PM) *
Could you create a little demo because I don't really understand what this script does...


It's for use by other scripts. It makes storing extra information in the notes field super easy and convenient. The Skill Requirement Script I wrote uses this- in fact it was the motivation for this script.

So far only I've used it, but I find it so convenient that I'm sure it's only a matter of time before other scripts start using it wink.gif
Go to the top of the page
 
+Quote Post
   
Queex
post Apr 4 2008, 05:05 PM
Post #7


Level 6
Group Icon

Group: Member
Posts: 75
Type: None
RM Skill: Beginner




Bump, to point out it has been updated. It now conforms to usual Ruby naming conventions and has been put in a module.
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 25th May 2013 - 06:54 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker