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,284
Reaction score
682
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,604
Reaction score
1,983
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,284
Reaction score
682
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,604
Reaction score
1,983
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,854
Reaction score
14,985
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 Posts

Latest Profile Posts

I'm finally back! :kaojoy:
A lot of RL issues happened this year which didn't let me work on Aithne as much, but I am back with new inspiration!
In that time my art style also changed a little, so I'll be doing a small art change with busts/menu art
Ops forgot to fix the hand on the weaponless sprite o_O
opening old GIMP files is a blessing and a curse because it can be fun to look at art you started once upon a time and want to finish BUT come to a total halt when you remember your past self forgot to create separate layers for most files
"The bigger the person, the longer the wait"

Forum statistics

Threads
113,721
Messages
1,076,919
Members
147,750
Latest member
rainbowkombat
Top