A Guide to Notetagging

Fomar0153

Arkz
Restaff
Joined
Mar 13, 2012
Messages
1,240
Reaction score
231
First Language
English
Primarily Uses
N/A
Can also be read on my blog: http://cobbtocs.co.uk/wp/?p=312

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:



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



Code:
<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:



Code:
<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:



Code:
class RPG::Item

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



Code:
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:



Code:
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.



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

end


Code:
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.



Code:
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
 
Last edited by a moderator:

amerk

Veteran
Member
Joined
Mar 13, 2012
Messages
1,439
Reaction score
511
First Language
English
Primarily Uses
You've been on a role lately, haven't you. Another great tutorial. I personally don't know how to script, and I seldom ever look beyond the "Do not Edit" point, but I have been trying to come to an understanding. I agree note tags are easier and I wondered why more scripts don't implement them, but you did a good job of explaining the other perspective of this.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,413
Reaction score
12,947
First Language
English
Primarily Uses
RMMV
I said it before, and I'll say it again ... great explanations! Thanks for all the work you put into this.
 

Fomar0153

Arkz
Restaff
Joined
Mar 13, 2012
Messages
1,240
Reaction score
231
First Language
English
Primarily Uses
N/A
You've been on a role lately, haven't you. Another great tutorial. I personally don't know how to script, and I seldom ever look beyond the "Do not Edit" point, but I have been trying to come to an understanding. I agree note tags are easier and I wondered why more scripts don't implement them, but you did a good job of explaining the other perspective of this.
The other thing I have against them is that they can be seen as an additional barrier to entry into scripting. Though hopefully this tutorial will remedy that.

I said it before, and I'll say it again ... great explanations! Thanks for all the work you put into this.
You're too kind but it does encourage me to keep writing tutorials.
 

PussiCat

Villager
Member
Joined
Sep 25, 2015
Messages
24
Reaction score
4
First Language
english
Primarily Uses
How would i go about using this to change the colour of a character class name depending on what it was? Example: Warrior was a red colour and Mage was a blue colour?
 

MusicTF

Soundtrack Composer
Veteran
Joined
Mar 30, 2015
Messages
102
Reaction score
8
First Language
English
Primarily Uses
How does one then use the value of a notetag in a class defined in the editor, like Game_Actor?
 

Jono99

Veteran
Veteran
Joined
May 8, 2015
Messages
76
Reaction score
17
First Language
English
Primarily Uses
RMVXA
I'm probably not going to get a reply considering how old this thread is, but I did this, but I'm having trouble calling the method. When I did (msgbox(RPG::Item.conserve_chance)), the game crashed before the game even executed the code and when I did (msgbox($RPG::Item.conserve_chance)), I got an error saying "unitialised constant Game_Interpreter::Item" (I ran the code via a script call from an event). Can you please help? Thank you.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,265
Reaction score
7,141
First Language
German
Primarily Uses
RMMV
The game interpreter (which handles the script call command in events) is a sandboxed part of the engine, especially blocked from direct access of the main scripts to prevent damage to the engine by mistakes in eventing.


Scripts that get data by the script event command have been prepared for that by giving them interpreter functions for example.


As a result, you can't test everything in the script call command, some code needs to be executed in the scripts themselves - and that requires placing those commands in a class/module and the entire sequence being placed in the script editor.
 

Jono99

Veteran
Veteran
Joined
May 8, 2015
Messages
76
Reaction score
17
First Language
English
Primarily Uses
RMVXA
The game interpreter (which handles the script call command in events) is a sandboxed part of the engine, especially blocked from direct access of the main scripts to prevent damage to the engine by mistakes in eventing.


Scripts that get data by the script event command have been prepared for that by giving them interpreter functions for example.


As a result, you can't test everything in the script call command, some code needs to be executed in the scripts themselves - and that requires placing those commands in a class/module and the entire sequence being placed in the script editor.
Thanks for responding, but it didn't help. I've tried everything reasonable: Passing the code off to another module, replacing the code of an event with the test code, replacing the code of the menus with the test code, but nothing works. I keep getting the same error that I mentioned before, but it says the script I put the code in (or Game_Interpreter if I ran it through a script call). Any other ideas?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,265
Reaction score
7,141
First Language
German
Primarily Uses
RMMV
you need to place it in its own script if you don't know exactly where to change an existing script. And then of course you need to connect this script to the rest of the engine.


I suggest you make a new topic in the "learning ruby and RGSS" forum, listing the script you have so far, explaining what exactly it should do and asking for help there.
 

Jono99

Veteran
Veteran
Joined
May 8, 2015
Messages
76
Reaction score
17
First Language
English
Primarily Uses
RMVXA
you need to place it in its own script if you don't know exactly where to change an existing script. And then of course you need to connect this script to the rest of the engine.


I suggest you make a new topic in the "learning ruby and RGSS" forum, listing the script you have so far, explaining what exactly it should do and asking for help there.
Well, I found a way of doing it, but it isn't all that great. I have to call the functions from within RPG::Item itself (eg. Instead of doing msgbox($RPG::Item.conserve_change), I'd do class RPG::Item


  msgbox(conserve_change)


end.


It's not elegant, but it'll work at least.
 

Destiny205

Warper
Member
Joined
Jul 12, 2015
Messages
4
Reaction score
0
First Language
Indonesian
Primarily Uses
N/A
I'm completely new to RPG Maker so I've got a question:


where can we put the notetags?


I'm serious. Like I said, I'm completely new to this.
 

Jono99

Veteran
Veteran
Joined
May 8, 2015
Messages
76
Reaction score
17
First Language
English
Primarily Uses
RMVXA
I'm completely new to RPG Maker so I've got a question:


where can we put the notetags?


I'm serious. Like I said, I'm completely new to this.
You can put notetags in maps along with almost everything in the database. There should be a section called "Notes" with a text box right underneath it. You put the notetags in there.
 

Destiny205

Warper
Member
Joined
Jul 12, 2015
Messages
4
Reaction score
0
First Language
Indonesian
Primarily Uses
N/A
You can put notetags in maps along with almost everything in the database. There should be a section called "Notes" with a text box right underneath it. You put the notetags in there.
Okay. Thx a lot.
 

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

Latest Threads

Latest Profile Posts

Meet the cute little ghost, FhooFhoo. :kaopride:
If anyone here is looking for another high-potential RPGMaker game--besides She Dreams Elsewhere--be sure to follow Lawmage Academy. Good social media presence will take that game far.
Lol, I was about to write a small tutorial and realized it would belong to the MZ section ....that does not exist yet.
I've noticed that more videos on YouTube have these segmented bookmark things in the videos themselves. It's nice being able to jump to parts of a video you want, and to have them all clearly labelled.
Why you do this? Now I have to buy the new RPG Maker xD

Forum statistics

Threads
99,574
Messages
966,792
Members
131,229
Latest member
jackermv
Top