RegEx for Getting a value from the note tag

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
I just want to ask how are you able to get the value of a note tag on a certain tab? Here's an example:

<hertz: 90>

I want to know how to get that 90 from the note tag <hertz: x> (which x is the value) and store it in a variable.

Thanks a lot.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,309
Reaction score
531
First Language
indonesian
i usually use match

comment = "<hertz: 90>";result = comment.match(/<hertz:\s*(\d+)?>/im)[1];tonumber = Number(result);return tonumber;this site is really helpful for testing regexp... i found lots of bugs when testing using this site and fix finally fix it.

https://regex101.com/

edit: if you want to get it from item note... for example item 1

change

comment = "<hertz: 90>";to

comment = $dataItems[1].noteother example:comment = $dataWeapons[10].note // weapon 10 in databasecomment = $dataArmors[7].note // armor 7 in databaseyou could also pass item object instead and grab it's note by .note

if you want it from comment in event page... it's a bit tricky though...

edit2: to grab from current map event 7

var comment = "";event = $gameMap._events[7];if (event && event.page()){var pagelist = event.page().list;   for (cmd of pagelist)   {        if(cmd.code == 108)     comment += cmd.parameters[0] + "\n";        if(cmd.code == 408)     comment += cmd.parameters[0] + "\n";            }}result = comment.match(/<hertz:\s*(\d+)?>/im)[1];tonumber = Number(result);return tonumber;you could pass Game_Event object rather than using $gameMap._events[7] too...

hope this help...

some example of using event comment tag... you can see it inside my plugin... link in my signature...
 
Last edited by a moderator:

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
Is the first line needed for that? I'm trying to learn this too so am curious.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
How about simple strings? For example:

<invisible>

How do you read them?
 

 Masked 

Assistant
Veteran
Joined
Oct 28, 2015
Messages
90
Reaction score
261
First Language
Portuguese
Primarily Uses
RMMZ
Or you could just use .meta:

Code:
var hz = Number(item.meta.hertz);console.log(hz) // 90
Edit: for single strings .meta returns true if it exists and false if not:
Code:
var inv = item.meta.invisible;console.log(inv) // true
 
Last edited by a moderator:

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
I see, thanks Masked. If it returns true, then how can you print the value instead of its type?

for example in pseudocode:

if <invisible> 

 then do this

close if statement
 
Last edited by a moderator:

 Masked 

Assistant
Veteran
Joined
Oct 28, 2015
Messages
90
Reaction score
261
First Language
Portuguese
Primarily Uses
RMMZ
You mean, like this?

Code:
if (item.meta.invisible) {  console.log(...) // invisible}
I'm not sure I understood what you want...
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
I mean, how do we check if the note tag is indeed "<invisible>", instead of printing true or false for it.
 

 Masked 

Assistant
Veteran
Joined
Oct 28, 2015
Messages
90
Reaction score
261
First Language
Portuguese
Primarily Uses
RMMZ
Oh, I see. You can check if it's really 'true' or if it's a string, if it has any value assigned to it then the .meta will be a string, if its just an empty tag then the .meta will be a boolean.

Something like this:

Code:
if (item.meta.invisible === true) {    // <invisible>} else if (typeof item.meta.invisible == "string") {    // <invisible:something>}
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
Before my friend wrote an awesome Regex parser I used: http://rubular.com/ to create regex. Now I use his epic script that parses this jazz :D
 

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

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,074
Members
137,578
Latest member
JamesLightning
Top