Status
Not open for further replies.

KotoYama

Veteran
Veteran
Joined
Apr 20, 2019
Messages
358
Reaction score
51
First Language
Spanish
Primarily Uses
RMMV
I've tried different scripts but none of them worked for me. Suggestions?

1623412743603.png
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,307
Reaction score
702
First Language
English
Primarily Uses
RMMV
There are a number of problems with that.
1) You're already inside an event, which would be what "this" is referring to - so what do you think this.event() means?

2) Events do not have a meta member, RPG Maker MV does not read event comments into metadata. It only does that with notetag fields.

If you want to do this, you need to write your own method to read the contents of an event as text, detect a comment, then extract the pertinent data from that. I know Yanfly's Common Event Menu does that, but it's a paid plugin, so that might be a little much just to use as a learning tool. I'm not familiar with something free that does it.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,617
Reaction score
1,997
First Language
EN
Primarily Uses
RMMZ
Script commands are evaluated in the context of their interpreter (Game_Interpreter), so you can use:
  • this.character(0) = "This Event"
  • this.character(0).event().meta = "notetag data for This Event"
Map events have a meta property, but it is associated with their note box (found next to their name box). The event() method goes from the Game_Event instance to the corresponding $dataMap entry.

Comments are a bit different. There is no core script method to fetch all Comment commands or scan them for a specific tag. However, you can do that manually, e.g.
If you were talking about comment tags: they are typically used to give an event different values based on the active page. There's no shortcut of which I'm aware: you'll have to scan the event's command list for Comment commands, then parse the contents of each command in search of the appropriate notetag. Here's an example designed for use in a Script command:
Code:
var RX = /<tag:\s*(\d+)>/;    // regular expression for <tag: X> (+integer X)
var ev = this.character(0);   // this event
var res = ev.list().filter(function(c) {
  return c.code === 108;      // get comments (command 108, cf rpg_objects.js)
}).map(function(c) {
  var match = RX.exec(c.parameters[0]);
  return match ? match[1] : '';  // digit match or empty string
}).filter(function(c) {
  return !!c;                    // filter out empty strings
})[0] || '';                     // return first entry or empty string
ev.tag = parseInt(res, 10) || 0; // assign retrieved value as a property
For use in a plugin you'd probably want to replace the ev var with a this reference and insert the comment-parsing code in an alias of the setupPage method of Game_Event or something like that~
 

KotoYama

Veteran
Veteran
Joined
Apr 20, 2019
Messages
358
Reaction score
51
First Language
Spanish
Primarily Uses
RMMV
@caethyril not going to pretend, I don't quite understand how to use this.
After that I've tried adding two script calls for the last remaining line:
$gameActors.actor(1).setName(ev.tag)
$gameVariables.setValue(1, ev.tag)
and check values in an message window "\V[1]\N[1]", both had values of zero.
Am I missing something?

P.S. I know how to check event's notes, but I need comments too since I thought it would be easier than dissecting the note's name into separate values, etc since they're not flexible enough.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,307
Reaction score
702
First Language
English
Primarily Uses
RMMV
Map events have a meta property, but it is associated with their note box
Sorry, I misremembered without the editor open. I don't think I've ever used that.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,617
Reaction score
1,997
First Language
EN
Primarily Uses
RMMZ
After that I've tried adding two script calls for the last remaining line:
$gameActors.actor(1).setName(ev.tag)
$gameVariables.setValue(1, ev.tag)
and check values in an message window "\V[1]\N[1]", both had values of zero.
Am I missing something?
The example in the post I quoted is designed to match something in the form <tag: X>, where X is an integer. For something like <tag: text>, try this instead:
JavaScript:
var RX = /<name:\s*([^>]+)>/i;   // match <name: text>
var ev = this.character(0);
var res = ev.list().filter(function(command) {
  return [108, 408].contains(command.code);  // comments only
}).map(function(comment) {
  return comment.parameters[0];              // get comment text
}).reduce(function(a, c) {
  var match = RX.exec(c);
  return a.concat(match ? [match[1]] : [])   // push matches to array
}, []);
console.table(res);                          // test! (F8 during test to show console)
$gameVariables.setValue(1, res[0]);          // store first match in game variable 1
This should match up to one <name: text> tag per comment line (comments can have multiple lines, that's what code 408 is for). There might be a better approach, but this seems to work for me! :kaopride:

More technical details on regular expressions can be found here~

P.S. I know how to check event's notes, but I need comments too since I thought it would be easier than dissecting the note's name into separate values, etc since they're not flexible enough.
Imagine an event's note box is a mess like this:

BigBadBeetroot<enemy><vegetable><age: 341.2><can fly><alien>

The event's meta property, created automatically by the core scripts, should still be nice and tidy:

{ age: "341.2", alien: true, "can fly": true, enemy: true, vegetable: true }

Comment tags are only really necessary if you want to store different tags for each event page.
 

KotoYama

Veteran
Veteran
Joined
Apr 20, 2019
Messages
358
Reaction score
51
First Language
Spanish
Primarily Uses
RMMV
I ended up using other methods, but I won't close the thread in case someone finds an answer.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,891
Reaction score
14,994
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.


(at OP's request)
 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts

Here in Fla were are seeing crazy covid spikes and some vaccinated getting bad infections. I had a mild fever on Thurs but it went down fast. How is everyone else doing. Hopefully you are all well. :)
Wish I was better at art, specifically that I was faster at it, bc this one NPC took Several Days to complete! It's gonna take So Extremely Long to do all of the art for my game, never mind writing it... Anyways, here's my gorgon, Hopernica Sthyxis!

57b88732c7abbcd84981dacf624a98495af61fcc.gifv
Idk if this is my ADHD or if it's a common problem. But I cant stay motivated for anything. I want to work on so many different things at once. Game dev, skateboarding, ranking up in League, playing OSRS, fitness, nutrition, relationships. It's like, where do I even begin?
Well. Looks like I need to redo the entire battle system in order to have the things I want in it. Also I'd like to say that console.log() is the greatest function in Javascript XD.

Forum statistics

Threads
113,817
Messages
1,077,698
Members
147,872
Latest member
hibixon
Top