Splitting /[\r\n]+/ and placing it in one value?

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 want to detect if an actor has this note tag:

/<(?:METRONOME|metronome):[ ]*(\d+)([%%])>/iand from the answers I've learned, I did something like this:

Game_Actor.prototype.getMetronome= function() { this._metronome = /<(?:METRONOME|metronome):[ ]*(\d+)([%%])>/i; this.note.split(/[\r\n]+/g).forEach(function (line) { line.match(/<metronome:[ ]*(\d+)>/ig); var metronomeValue = 1; if (match) { metronomeValue = Number(match[0] || 0); } } }Is this correct? Or is there a better implementation? Because I want to get the note tag

<metronome: 10>and then give that value from the note tag of the actor to a variable, which I can call later.
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
I'd do something like this:

/<(?:metronome):?\s*(\d+)>/iThis means that we are looking for <metronome#> at the very minimum. More digits are acceptable, and will also be matched. You don't need the (?:METRONOME|metronome), because the 'i' at the end means case-insensitive, so having both doesn't change anything. The :? means the colon is optional, and \s* means any amount of spaces, including none. Therefore, all the following are valid:

<metronome 5>

<metronomE79356>

<metronome:3>

<metronome: 725>

While the website specifically uses Ruby, rubular.com is a great resource for testing regular expressions. Here's the example I made on that site.
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
When I usually make my regular expressions, I try to do it with as many place for spaces possible.

Example :

/\"(.+)\"\s*(\d+)\s+(\d+)\s+(\d+)/igAlso, Rubular is for Ruby, and Scriptular is for JS.

But it doesn't matter, regular expressions are not very different...

But you can also use meta for reading notetags, it's very useful.

If, for example you wanted to read it, you could just use

this.actor().meta.metronomeIf it's null, there's no value. Otherwise, it would be a string.
 
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. This is beneficial. I looked at a certain scripter's plugin and it confused me. What is the need of adding it into the datamanager? I tried using like it:

DataManager.acquireActorNotation = function(group) { var metronome_condition = /<(?:metronome):?\s*(\d+)>/i; var metronome_state = /<(?:metronome):?\s*(\d+)>/i; for (var notation = 1; notation < group.length; notation++) { var object = group[notation]; var notedata = object.note.split(/[\r\n]+/); object.metronomeValue = {}; object.metronomeStateValue = {}; for(var i = 0; i < notedata.length; i++) { var line = notedata; if (line.match(metronome_condition)) { object.metronomeValue[parseFloat(RegExp.$1)] = parseInt(RegExp.$2); } if (line.match(metronome_state)) { object.metronomeStateValue[parseInt(RegExp.$1)] = parseInt(RegExp.$2); } } } }but I don't even know if that's correct and how to get it. Metronome Condition is like the % of the actor's life before the Metronome State gets activated and applied to him / her.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
When I usually make my regular expressions, I try to do it with as many place for spaces possible.

Example :

/\"(.+)\"\s*(\d+)\s+(\d+)\s+(\d+)/igAlso, Rubular is for Ruby, and Scriptular is for JS.But it doesn't matter, regular expressions are not very different...

But you can also use meta for reading notetags, it's very useful.

If, for example you wanted to read it, you could just use

this.actor().meta.metronomeIf it's null, there's no value. Otherwise, it would be a string.
There's one big different that may become relevant: . (dot) doesn't match on new-lines.

So if you were matching multi-line like this

<my tag> stuff</my tag>Simply writing

Code:
/<my tag>(.*?)<\/my tag>/im
Won't work.You need to use something like

Code:
/<my tag>([\s\S]*?)<\/my tag>/im
 
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
@kocka:

I did try parsing the value of the meta, which my actor has. My actor has this note tag:

<metronome_condition: 200><metronome_state: 2>Basically what I wanted is in Battle / Map, I wanted to check if the actor has 200HP. If his / her hp is equal or lower than that. metronome_state should be added, in this case, is 2. I wanted metronome_condition to be percentages though. Not checking the note tag and going directly to the meta doesn't seem to work:

Code:
(function() {	var milena_gb_refresh = Game_BattlerBase.prototype.refresh;	Game_BattlerBase.prototype.refresh = function() {	    milena_gb_refresh.call(this);	    this.applyMetronomeState();	};		Game_BattlerBase.prototype.applyMetronomeState = function() {		if (this.metronomeStateID() <= 0) {			return;		}		this.metronome() ? this.addState(this.metronomeStateID()) : this.removeState(this.metronomeStateID());	}	Game_BattlerBase.prototype.metronomeStateID = function() {		return 0;	}	Game_BattlerBase.prototype.metronome = function() {		return false;	}	Game_Actor.prototype.metronome = function() {		return this.hp <= parseInt(this.actor().meta.metronome_condition);	}	Game_Actor.prototype.metronomeStateID = function() {		return parseInt(this.actor().meta.metronome_state);	}})();
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
Try to remove spaces in your notetags.

That's one big issue when using meta.

And always check if something.meta.something is null
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Use the meta. If it doesn't work, it means it needs to be tweaked. Even if you write your own big, long function to do what's already been done for you by the DataManager, you'll still have to figure out how to read the data properly (ie - whether you use meta or your own function, you're still going to have to figure out why you couldn't read it)

Either remove the space when you create the note tag, or trim it when you retrieve it.

Code:
if (this.actor().meta.metronome_condition) {  value = parseInt(this.actor().meta.metronome_condition.trim()) / 100;}
gets rid of the space between the key and value, converts it to an integer, and changes it to a percent.
 
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
Use the meta. If it doesn't work, it means it needs to be tweaked. Even if you write your own big, long function to do what's already been done for you by the DataManager, you'll still have to figure out how to read the data properly (ie - whether you use meta or your own function, you're still going to have to figure out why you couldn't read it)

Either remove the space when you create the note tag, or trim it when you retrieve it.

if (this.actor().meta.metronome_condition) { value = parseInt(this.actor().meta.metronome_condition.trim()) / 100;}gets rid of the space between the key and value, converts it to an integer, and changes it to a percent.
Amazing Shaz! That eliminated my doubts how to use meta without the spaces <3
 

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,847
Messages
1,016,972
Members
137,561
Latest member
JaCrispy85
Top