A guide to Note-tagging

So you’re getting into scripting, maybe you just released a script and naturally you’re a bit peeved because the first person to reply did nothing but complain about the lack of note tagging, maybe the second reply agreed with him… Right so now you’re a double murderer but want to learn how to incorporate note tagging in your future scripts. Then this tutorial is for you.

First let me begin by saying note tagging is NOT REQUIRED NOR EVER WILL BE for a script. It does not improve a script, it does not in any way make a script better. It only makes a script easier to use for people of no scripting ability or those with a weak disposition about editing a script. In some ways it’s a bad thing because it encourages a plug and play attitude and keeps people from doing minor amounts of scripting (which can lead to a better understanding of scripts). But clearly if you’re reading this then you want to make your scripts more “user friendly.” So let’s have a look at the potential classes you can use note tagging in:


C
lick to see full size.

Hopefully you will be able to find in the database and editor where you put the notetags. Notetags usually look like:

<notetag x>

I don’t know who came up with the format but it effectively mimics html tags, notetags don’t have to look like that but it’s what people are used to. If you do something different then any “user friendliness” you add to your script will be quickly be diluted with queries and uncertainty about the notetagging.

Right let’s now get into the code, hypothetical scenario you have a script where by one of your characters has a chance to not consume an item when using it and you want each item to have a different chance to avoid been consumed. You’ve decided your notetag will be:

<con x>

A quick look at the diagram I’ve provided you should lead you to: RPG::Item. Different people implement notetags in slightly different ways, for example Yanfly built an entire architecture around pre-loading notetags but I’ll just show you the way I do notetags and if you’re interested in other ways of notetagging you can also go look at how other scripters implement it.

So we’ve got our class, RPG::Item let’s go into them the script then:

class RPG::Item

end

We now need to add the new method you’ll call from somewhere in your script.

class RPG::Item
  def conserve_chance
  end

end

In all the classes with notes the note is stored in a variable called @note. Anyway this is what our final code looks like:

class RPG::Item
  def conserve_chance
    if @note =~ /<con (.*)>/i
      return $1.to_i
    else
      return 0 # the default if no notetag is present
    end
  end

end

Let’s just examine it a bit closer. =~ basically is checking for a match with the notetag. The two / are to do with regex which unless you want to look into more closely then what I go through here should see you through setting up any note tag. As for .* the . accepts any character except line breaks and the * means you can enter as many as you like. Finally the i after the second / just tells it to ignore case meaning <con x>, <CON x>, <Con x>, <CoN x> would all be accepted as a match.

$1 effectively holds whatever was placed in the notetag, by default it will be a string, if you need it to be an integer then add .to_i onto it like in the example.

I think that concludes the main chunk of the tutorial but there are two more things I want to go through getting an array from notetagging and inheritence with notetagging.

Lets jump into getting an array from notetagging, $1 contains the string from the notetag so we could have people enter the array like: <array 1,2,3,9,4> for example. There is a highly useful function in ruby called split and what it does it break up a string and return an array, best part of all if we can tell it how to break the string up. Right below are two examples one for an array of string and one for an array of integers.

class RPG::Item
  def conserve_chance
    if @note =~ /<con (.*)>/i
      return $1.split(",")
    else
      return []
    end
  end

end

 

class RPG::Item
  def conserve_chance
    if @note =~ /<con (.*)>/i
      ints = []
      for x in $1.split(",")
        ints.push(x.to_i)
      end
      return ints
    else
      return []
    end
  end

end

 

Right then that just leaves me to go through inheritance and notetags. If I may draw your attention to subset of the diagram above:

What the arrows represent is inheritance (I know that in UML they should be clear arrowheads but I don’t care). Inheritance is where the classes inherit all the variables and methods from the other class. The variable note exists in the RPG::BaseItem class and them all the other classes in the diagram inherit it. What this means is that if you need the same method in more than one of these classes you can put it in a class which the classes you need the method in inherit. So for example if I want to add something to both Weapons and Armours then I can put the method in EquipItem.

So hopefully this has helped you understand how to incorporate note tagging in your scripts, if you’re desperate to use notetagging when there are no notes you could always consider name tagging! But in all seriousness if you need any further help or clarification please don’t hesitate to leave a comment.

Jet has scolded me for performing the check every time the method is called so here’s an example of how to cache the notetag so that it only calculates it once per session.

class RPG::Item
  def conserve_chance
    if @conserve_chance.nil?
      if @note =~ /<con (.*)>/i
        @conserve_chance = $1.to_i
      else
        @conserve_chance = 0
      end
    end
    @conserve_chance
  end

end
1
  

4 comments

  1. Vee says:

    Just a question, has anyone thought of standardizing an opening and closing tag for the script system being used so that it doesn’t conflict with other systems out there?

    For example, if I’m using scripts from Yanfly, Yami, Fomar, Jet, Victor, etc. wouldn’t it be ideal for compatibility to only read in a section from the note tag field related to your system. So do something like this in the note tag:

    Yanfly tags here

    Yami tags here

    Of course, each scripter would need to write their scripts to only pull in the information between their tags. The benefit here is that no one would have to worry about what names the other scripters are using for their note tags.

  2. Vee says:

    Ack, it removed my tags… I should have forseen that.

    Lemme try again:

    Yanfly tags here

    Yami tags here

    Fomar tags here

    ...etc.

    • Vee says:

      Ok, wordpress isn’t allowing me to put the xml tags in my comments (even enclosed in code tags). Anyway, the idea is to enclose each scripting system in their own tags and only parse out that data from the note tag field.

    • Fomar0153 says:

      I don’t think it’s a big problem, not big enough that we should be collaborating on note tagging.