How to use note-tags?

IneptAttoney_08

Dimas Ridwan AP
Veteran
Joined
Mar 1, 2019
Messages
133
Reaction score
26
First Language
Indonesia
Primarily Uses
RMVXA
I tried to make a costume description for my elbow.
I saw TsukiHime's tutorial about making notes.
But in the tutorial it only shows how to create notetags that contain numbers.
while I want to make a notetag that contains a string.
can someone teach me how to make it?

this is the note I made and the result failed.
Notetag inside skill:
desc.JPG
Regex:
regex.JPG
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,151
Reaction score
1,121
First Language
Spanish
Primarily Uses
RMVXA
Code:
Ext_Regex = <desc>(.*?)<\/desc>
res = self.note =~ RD::Skill::Ext_Regex ? $1 : nil

##
self.note => <desc>[break]Line 1[break]Line 2[break]</desc>
RD::Skill::Ext_Regex => <desc>(.*?)<\/desc>
self.note =~ Ext_Regex => True
$1 => [break]Line 1[break]Line 2[break]
res <= $1
res = [break]Line 1[break]Line 2[break]
res, equals, (self.note resembles Ext_regex ? then return first regexp match, else, nil)
from there:
res, equals, first regexp match.
in this case, [break]Line 1[break]Line 2[break]

you still have to get rid of the break characters and separate the line 1 and 2.

you can still simply read self.note and try to grab the string directly
Code:
res = self.note[/<desc>(.*?)<\/desc>/i]
to filter out break characters:
Code:
<desc>(\w+(?!\n))<\/desc>
replace .* (single character) by \w (alphanumeric).
\w+, alphanumeric, progressive scan
\w+(?!\n), alphanumeric, progressive scan, ignore line break
(\w+(?!\n)), return final finding as back reference.
 
Last edited:

IneptAttoney_08

Dimas Ridwan AP
Veteran
Joined
Mar 1, 2019
Messages
133
Reaction score
26
First Language
Indonesia
Primarily Uses
RMVXA
Code:
Ext_Regex = <desc>(.*?)<\/desc>
res = self.note =~ RD::Skill::Ext_Regex ? $1 : nil

##
self.note => <desc>[break]Line 1[break]Line 2[break]</desc>
RD::Skill::Ext_Regex => <desc>(.*?)<\/desc>
self.note =~ Ext_Regex => True
$1 => [break]Line 1[break]Line 2[break]
res <= $1
res = [break]Line 1[break]Line 2[break]
res, equals, (self.note resembles Ext_regex ? then return first regexp match, else, nil)
from there:
res, equals, first regexp match.
in this case, [break]Line 1[break]Line 2[break]

you still have to get rid of the break characters and separate the line 1 and 2.

you can still simply read self.note and try to grab the string directly
Code:
res = self.note[/<desc>(.*?)<\/desc>/i]
to filter out break characters:
Code:
<desc>\w+(?!\n)<\/desc>
replace .* (single character) by \w (alphanumeric).
\w+, alphanumeric, progressive scan
\w+(?!\n), alphanumeric, progressive scan, ignore line break
thank you for the response.
But I still don't understand about notetag. so I do not understand what you say. might be understood with words that are easy to understand?
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,151
Reaction score
1,121
First Language
Spanish
Primarily Uses
RMVXA
notetags are characters in a text box.
you can grab the contents of the text box, but the program can't possibly know what they mean.
you have to compare the contents of the text box with a blueprint of meaning and see if they match.

your blueprint is the result of a constant in a module.
Code:
module RD
  module Skill
    Ext_Regex = <desc>(.*)<\/desc>
  end
end
the content of the text box, contains line break characters.
Code:
<desc> (break)
Line1 (break)
Line2 (break)
</desc>
when you read the contents of the text box as a string, it comes out as
Code:
<desc>(\n)Line1(\n)Line2(\n)</desc>


does

Code:
<desc>(\n)Line1(\n)Line2(\n)</desc>
resemble

Code:
module RD
  module Skill
    Ext_Regex = <desc>(.*)<\/desc>
  end
end
?

yes.

Code:
<desc>(\n)Line1(\n)Line2(\n)</desc>
is a line of stuff preceded by <desc> and followed by </desc>.

for all intents and purposes of the comparison,
Code:
<desc>(\n)Line1(\n)Line2(\n)</desc>
resembles
Code:
<desc>(.*)<\/desc>
therefore:
Code:
res =~ RD::Skill::Ext_Regex
returns true.

but you need to retrieve the actual line, which is *the stuff in between <desc> and </desc>*.
SO:
Code:
res = self.note =~ RD::Skill::Ext_Regex ? $1 : nil
OR:
Code:
res = self.note[RD::Skill::Ext_Regex]
which is the same as
Code:
res = self.note[/<desc>(.*)<\/desc>/i]
which is what you want to extract.

it'll still come out as
Code:
(\n)Line1(\n)Line2(\n)
so you need to remove the line breaks and split the lines into individual values.

(MODERATORS: Sorry for wall post. I can't simply point at the code in question and state "this!" while I point at it if the OP can't possibly know what I'm pointing at unless I write the actual thing I want to reference. Can't sum up *programming* as *this! goes here! outputs stuff, there!*)
 
Last edited:

IneptAttoney_08

Dimas Ridwan AP
Veteran
Joined
Mar 1, 2019
Messages
133
Reaction score
26
First Language
Indonesia
Primarily Uses
RMVXA
then how do I make @custom_desc be * an item between <desc> and </desc> *?
hex2.JPG
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,151
Reaction score
1,121
First Language
Spanish
Primarily Uses
RMVXA
how do I make @custom_desc be * an item between <desc> and </desc> *?
and what *is* <desc>whatever</desc>?
isn't it self.note?

self.note *IS* <desc>#############</desc>.

what are you doing with self.note?

isn't it being read by self.note =~ RD::Skill::Ext_regex ?
what's coming out of that?
 

IneptAttoney_08

Dimas Ridwan AP
Veteran
Joined
Mar 1, 2019
Messages
133
Reaction score
26
First Language
Indonesia
Primarily Uses
RMVXA
*DO YOU* have any way of getting any items whatsoever from the bulk that is <desc>whatever</desc>?
I want to display a custom description in window_Help like this
ffd.JPG
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,151
Reaction score
1,121
First Language
Spanish
Primarily Uses
RMVXA
right.....
so, custom_desc is the method you're adding to the object item.

custom_desc has to be the text contained within the object item's note block.
right.

so.... where is the text contained within the object item's note block going?
you have a text contained within the object item's note block, and you have a method that needs to return the contents of that object item's note block.
where is the contents of the object item's note block going?

(Yes, I did write "is" and "contentS", because contentS is actually one object. I'm trying to make you read and follow the code you're writing.)
 

IneptAttoney_08

Dimas Ridwan AP
Veteran
Joined
Mar 1, 2019
Messages
133
Reaction score
26
First Language
Indonesia
Primarily Uses
RMVXA
Alright I give up ..
I will use another method for this. thank you for helping.
I really don't understand XD
I assume this has been solved
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,151
Reaction score
1,121
First Language
Spanish
Primarily Uses
RMVXA
I simply can't explain it more basically, other than saying "go read the help files", or simply "read the code you just wrote"

how did you come up with that code and not understand how to use regular expressions?
did you simply copy something else?
how do you expect to understand the solution given to you upon presenting a problem, if you can't read the very code that's creating the problem for which the solution is written using the same code?
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
560
Reaction score
273
First Language
German
Primarily Uses
One more thing about the regular expression from your first attempt, which was almost working:

A dot in a regular expression normally matches any character except a linebreak - unless your regular expression has multi-line mode enabled (although irrelevant here, multi-line mode will still try to match as few lines as possible if I remember correctly).

To set multi-line mode you can add a "m" to the very end of your expression:
/<desc>(.*?)</desc>/im

Alternatively you can of course explicitely match the linebreak:
/<desc>((?:.|\n)*?)</desc>/i


Edit: What gstv87 said still applies here of course, but in case you couldn't find a match with your regular expression, this might be why.

Edit2:
to filter out break characters:
Code:
<desc>(\w+(?!\n))<\/desc>
replace .* (single character) by \w (alphanumeric).
\w+, alphanumeric, progressive scan
\w+(?!\n), alphanumeric, progressive scan, ignore line break
(\w+(?!\n)), return final finding as back reference.
I might be missing something, but I don't think I can agree with this one.
As you said, \w matches alphanumeric characters, so the "description" cannot contain any spaces or punctuations. The negative look-ahead should only make sure that what you are matching is not directly in front of a line break, but it should not ignore anything.
 
Last edited:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,299
Reaction score
6,056
First Language
Indonesian
Primarily Uses
RMVXA
Don't give up yet, if you want to learn. Try to learn it from the basics. First off, forget default scripts. And show the console by clicking the Game > Show Console. Then add this script just like how you add a new script.
Code:
DataManager.init
# you can change the id
p $data_actors[6].note
p $data_actors[6].note =~ /<desc>(.*)<\/desc>/i

loop do
  Graphics.update
  Input.update
end
It prints this note
Screenshot_337.jpg
To something like this.
Screenshot_338.jpg

Notice that the line break consists of escape character which is carriage return (\r) and line break (\n). A line break (\n) is not detectable by a greedy match (.*). So you need another way. The most intuitive and easiest way is to break it to smaller chunks. And yes, split it.

How to do that? use this
Code:
$data_actors[6].note.split(/[\r\n]+/)
It will be an array.
Screenshot_339.jpg
From here, you can fetch "line 1", "line 2", and "line 3".
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,339
Reaction score
483
First Language
English
Primarily Uses
RMVXA
I really don't understand XD
Is it that you do not understand what the letters do?
I don't remember what they all do either. But here is where you can test your code.
1586524740440.png
it shows some of the Regex quick reference below the expression window.

* Note that this may not translate exactly as you see here into rpg maker.

And what TheoAllen says is good, the regex will not always give you the clean results and you have to figure out how to fix it.
gstv87 was explaining the structure of the code.

This is myself playing with exactly what you are doing now. But most of what I do is a replication of what others have done.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,151
Reaction score
1,121
First Language
Spanish
Primarily Uses
RMVXA
Alternatively you can of course explicitely match the linebreak:
/<desc>((?:.|\n)*?)</desc>/i
<desc>([\n](.*)[\n])+</desc>

identify set of (\n or no \n, thing, \n or no \n) between <desc> structure, grab (thing) as back reference.
there are a number of ways to do it, more or less complex, but all equally unintelligible if the OP doesn't know the structure he's looking at.

How to do that? use this
Code:
$data_actors[6].note.split(/[\r\n]+/)
split!
I knew there was a split command.... I was looking at "slice" instead
 

IneptAttoney_08

Dimas Ridwan AP
Veteran
Joined
Mar 1, 2019
Messages
133
Reaction score
26
First Language
Indonesia
Primarily Uses
RMVXA
Don't give up yet, if you want to learn. Try to learn it from the basics. First off, forget default scripts. And show the console by clicking the Game > Show Console. Then add this script just like how you add a new script.
Code:
DataManager.init
# you can change the id
p $data_actors[6].note
p $data_actors[6].note =~ /<desc>(.*)<\/desc>/i

loop do
  Graphics.update
  Input.update
end
It prints this note
View attachment 139306
To something like this.
View attachment 139307

Notice that the line break consists of escape character which is carriage return (\r) and line break (\n). A line break (\n) is not detectable by a greedy match (.*). So you need another way. The most intuitive and easiest way is to break it to smaller chunks. And yes, split it.

How to do that? use this
Code:
$data_actors[6].note.split(/[\r\n]+/)
It will be an array.
View attachment 139308
From here, you can fetch "line 1", "line 2", and "line 3".
I tried to make the <desc> and </desc> notetag by copying your Dual Terms + script. and the results still don't work. is there a problem in this script?
I understand clearly how this script works.
he will check every line in the note.
and when he meets <desc> he will start reading the lines below until he meets </desc>
ct.JPG
I'm not giving up because this makes me even more curious

Edit:
Finally I managed to make my first notetag XD
But there seems to be something strange ..
This is the script I made. I can't believe I can make it only with your guidance.
success.JPG
But I have to make notes in the database like this so there are no blank lines in the first line.note.JPG
line.JPG
I want to make it so that I only need to write
Code:
<desc>
Line 1
Line 2
</desc>
 
Last edited:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,151
Reaction score
1,121
First Language
Spanish
Primarily Uses
RMVXA
just to spark your curiosity:

Code:
module RD
module USABLE_ITEM
   CUSTOM_DESC = /<desc>(.*?)<\/desc>/im
   DSC_HASH = {
    :item1 => "This is a long description in a hash, in a module";
   }
end
end

class RPG::BaseItem
alias rd_desc description
def description
  if self.note =~ RD::USABLE_ITEM::CUSTOM_DESC
    @custom_desc = eval($1)
  else
    rd_desc
  end
end
end
and then in the database:

Code:
<desc>
RD::USABLE_ITEM::DSC_HASH[:item1]
</desc>
.....and you can keep refining the formatting until you get rid of the <> tags altogether, and only scan for specific instructions.
and once you have that, you can put the whole string of the description in a module, where it can be as long as you want, bypassing the limitation of the note box.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,299
Reaction score
6,056
First Language
Indonesian
Primarily Uses
RMVXA
Another curiosity spark
Code:
module RD
  module USABLE_ITEM
   CUSTOM_DESC = /<desc:\s*(.+)>/i
   DSC_HASH = {
    :item1 => "This is a long description in a hash, in a module";
   }
  end
end

class RPG::BaseItem
  alias rd_desc description
  def description
    if self.note =~ RD::USABLE_ITEM::CUSTOM_DESC
      @custom_desc = RD::USABLE_ITEM::DSC_HASH[$1.to_sym]
    else
      rd_desc
    end
  end
end
Won't hurt to get more I think :p
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,151
Reaction score
1,121
First Language
Spanish
Primarily Uses
RMVXA
exactly XD
and from there, just redefine the item altogether since you're at it, and read everything from the code, you don't even need the database!
 

IneptAttoney_08

Dimas Ridwan AP
Veteran
Joined
Mar 1, 2019
Messages
133
Reaction score
26
First Language
Indonesia
Primarily Uses
RMVXA
exactly XD
and from there, just redefine the item altogether since you're at it, and read everything from the code, you don't even need the database!
Woah! I see!
it really helps.
Thanks a lot for helping me. :kaopride:
 

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,228
Reaction score
1,304
First Language
English
Primarily Uses
RMXP
Personally I prefer using multiline regular expression for multiline logic.

Let us for fun consider two notetags
Actor 6 notetag:
note6.png

Actor 7 notetag:
note7.png

Here is my code
Ruby:
DataManager.init

def test_regex(note, regex)
  first_match = note =~ regex
  raw = $1.inspect
  print "#{regex.inspect}   \t#{first_match.inspect}\t#{raw}\n"
end

regex1 = /<desc>(.*?)<\/desc>/i
regex2 = /<desc>(.*?)<\/desc>/im
regex3 = /<desc>(.*)<\/desc>/im
regex4 = /<desc>([^<]*)/im
regex5 = /<desc>[\r\n]*(.*?)[\r\n]*<\/desc>/im

note = $data_actors[6].note
p note
test_regex(note, regex1)
test_regex(note, regex2)
test_regex(note, regex3)
test_regex(note, regex4)
test_regex(note, regex5)
print "\n"

note = $data_actors[7].note
p note
test_regex(note, regex1)
test_regex(note, regex2)
test_regex(note, regex3)
test_regex(note, regex4)
test_regex(note, regex5)


print "\n\n"
for match in note.scan(regex5)
  # We only have one capture group so let us extract that from the array
  desc = match[0]
  p desc
end

Here is my output
Code:
"<desc>\r\nLine 1\r\nLine 2\r\n</desc>"
/<desc>(.*?)<\/desc>/i          nil     nil
/<desc>(.*?)<\/desc>/mi         0       "\r\nLine 1\r\nLine 2\r\n"
/<desc>(.*)<\/desc>/mi          0       "\r\nLine 1\r\nLine 2\r\n"
/<desc>([^<]*)/mi       0       "\r\nLine 1\r\nLine 2\r\n"
/<desc>[\r\n]*(.*?)[\r\n]*<\/desc>/mi           0       "Line 1\r\nLine 2"

"<desc>\r\n\r\nLine 1\r\nLine 2\r\n\r\n</desc>\r\n<other>Hello</other>\r\n<desc>\r\nLine 3\r\nLine 4\r\n</desc>"
/<desc>(.*?)<\/desc>/i          nil     nil
/<desc>(.*?)<\/desc>/mi         0       "\r\n\r\nLine 1\r\nLine 2\r\n\r\n"
/<desc>(.*)<\/desc>/mi          0       "\r\n\r\nLine 1\r\nLine 2\r\n\r\n</desc>\r\n<other>Hello</other>\r\n<desc>\r\nLine 3\r\nLine 4\r\n"
/<desc>([^<]*)/mi       0       "\r\n\r\nLine 1\r\nLine 2\r\n\r\n"
/<desc>[\r\n]*(.*?)[\r\n]*<\/desc>/mi           0       "Line 1\r\nLine 2"


"Line 1\r\nLine 2"
"Line 3\r\nLine 4"
A lot can be done with careful manipulation of the regular expressions themselves.
At the same time you may gobble more than you want.

Hope there are some ideas here that you will find useful.

*hugs*
- Zeriab
 

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

Latest Threads

Latest Profile Posts

Well, It is 4:23 here! Time to sleep!
Good night y'all! <3 :rock-right:
Anybody else ready for MZ Ace?
For scrolling of large maps... Minimap, or very small zoom?
Sometimes you think you know people, then the next thing you know it's below freezing outside, and they're falling from the sky. And no two are exactly alike.

Forum statistics

Threads
99,579
Messages
966,898
Members
131,238
Latest member
Ordnael
Top