Game_Event questions

I'd like to check if an event has a certain comment on it. I am doing it on Game_Event's update method. What code should I place in order to know whether the Game_Event has one?

I would also like to ask how you'd do the same if the Event name as something like [WATER] in its name. For example:

SCLClbq.png


What's the efficient way on knowing the event name's contents, and possibly also, get rid of the spaces when detecting them? I mean, doing something like === should be specific. I'd like to know how to get rid of this detection so for example the developer accidentally placed something like:

[WATER]            Waterfall

It would still work?
don't check comment tag on game event update. it have probability to make your project super laggy.

check it once in game event setup page settings. store it in variable and use the stored variable in your update method (or any method that require it)

example code with documentation to check comment:

taken from my EST - EVENT GRAPHIC SHIFT

Game_Event.prototype.get_event_shift = function() {// this is default value if there's no comment    var shift = null;// comment start grabbing below    var comment = ""; //initialize// if no event page (event which have no active page) return default value    if(!this.page()) return shift;// store current active page command list    var pagelist = this.page().list;// loop each command inside that    for (var cmd of pagelist)    {// code 108 is comment FIRST line, while the rest line is code 408// add the string we init above with the comment content and add line break each line        if(cmd.code == 108)     comment += cmd.parameters[0] + "\n";        if(cmd.code == 408)     comment += cmd.parameters[0] + "\n";    }// check the string does it contain your pattern? need to understand regexp    if(comment.match(/<graphic_shift:\s*(.*)>/im))         {              // split it with , in my case. you can do whatever you want here            var shift = comment.match(/<graphic_shift:\s*(.*)>/im)[1].split(/(?:\s+,\s+|,\s+|\s+,|\s+|,)/);         }// return the value    return shift;}; // alias methodvar est_event_graphic_shift_Game_Event_setupPageSettings = Game_Event.prototype.setupPageSettingsGame_Event.prototype.setupPageSettings = function() {  // check if event have active page or not. if not just return original method  if (!this.page())   {    return est_event_graphic_shift_Game_Event_setupPageSettings.call(this);    }// grab the event comment result in above function  var shift = this.get_event_shift();// store it in variable inside game event. you can use other function event like $gameMap, $gameSystem, etc.// depending on what you need it for i store in in this event and later offset the event graphic x y z  this._graphicOffsetX = shift && shift[0] ? Number(shift[0]) : 0;  this._graphicOffsetY = shift && shift[1] ? Number(shift[1]) : 0;  this._graphicOffsetZ = shift && shift[2] ? Number(shift[2]) : 0;// call original method  est_event_graphic_shift_Game_Event_setupPageSettings.call(this);};there are other comment grabbing method from other coder. but above is how i do mine.

hope this help.
The regular expression seems to be getting values as well. Is there a way so it can check a string based value first?

Game_Event.prototype.get_event_shift = function() { var shift = null; var comment = ""; if(!this.page()) return shift; var pagelist = this.page().list; for (var cmd of pagelist) { if(cmd.code == 108) comment += cmd.parameters[0] + "\n"; if(cmd.code == 408) comment += cmd.parameters[0] + "\n"; } if(comment.match(/<run>/im)) { var shift = comment.match(/<run>/im)[1].split(/(?:\s+,\s+|,\s+|\s+,|\s+|,)/); } return shift;};What I wanted was like to get a check from the update if the comment run (no quotation marks) is present. So I went from something like this:

Game_Event.prototype.checkRunMotion = function(){ if (this.get_event_shift()) { // if comment run is found in the event... }}The shift value from the example you gave me returns a value, am I right?

Thanks.
The shift value from the example you gave me returns a value, am I right?

Thanks.

};
my example above is returning [x,y,z] array.

if you just use <run> you can simplify it to return true / false only.

Game_Event.prototype.get_event_shift = function() {var comment = "";if(!this.page()) return false;var pagelist = this.page().list;for (var cmd of pagelist){if(cmd.code == 108) comment += cmd.parameters[0] + "\n";if(cmd.code == 408) comment += cmd.parameters[0] + "\n";}if(comment.match(/<run>/im)) return true;return false;};so if no active page... return false.

if comment found <run> return true.

if not found... return false.

also... for your second question about [water]... instead of name... why don't you use event note. it's easier to use that than event name.

i think you can access it inside Game_Event using: this.note

or any event_instance_object.note

you could also use match and regexp so it more flexible for your extra space problem.
Ahhh it works perfectly! My event runs, lol.

Another variation I would like to ask is, if we get just one value:

<run: 10>

I'd like to store 10 to get_event_shift, so if I detect it, I will do some more condition. It probably goes with two values, say if I do:

<run: x, y>

I'd like to store x and y separately into a variable I can call later.
Ahhh it works perfectly! My event runs, lol.

Another variation I would like to ask is, if we get just one value:

<run: 10>

I'd like to store 10 to get_event_shift, so if I detect it, I will do some more condition. It probably goes with two values, say if I do:

<run: x, y>

I'd like to store x and y separately into a variable I can call later.
wait... please use other name than get_event_shift 😀 . if you use that it will clash with my plugin 😛 .

for <run: 10>

if(comment.match(/<run:\s*(.*)>/im)){ var shift = comment.match(/<run:\s*(.*)>/im)[1];}also remember it's a string. so you might want to use Number(shift) to make it number

for <run: x, y>

you could use my example from my plugins and change graphic_shift to run instead. it will return an array (of text)

then you can access that array[0] and array[1] for first and second element. don't forget to use Number function to convert it to number.

it also mean if people accidentally add extra value

it won't throw error...
Here's how I did it:

Game_Event.prototype.getRunValue = function(){ var comment = ""; if (this.page()) { var pagelist = this.page().list; for (cmd of pagelist) { if(cmd.code == 108) comment += cmd.parameters[0] + "\n"; if(cmd.code == 408) comment += cmd.parameters[0] + "\n"; } } if(comment.match(/<run:\s*(.*)>/im)) { var shift = comment.match(/<run:\s*(.*)>/im)[1]; } var range = Number(shift); console.log(range); return range;}When it is printed via update, it throws me NaN.

I am doing this for like, the event in the map. Say for example:

Game_Event.prototype.checkRun= function(){ if (Math.abs($gamePlayer.x - this.x) + Math.abs($gamePlayer.y - self.y) <= this.getRunValue()) { //run command here }}and the reason why I want the <run:x> is because the x value is supposed to be the distance of the player from the event in order for it to run. Like a range of some sort. However I ran into errors and problems.
it will throw NaN because Number(null) will return NaN.

shift will only have value when you have "run" comment.

but there's also other event that didn't have that command. thus that other event will return NaN.

either you set default value or...

you could add check... if shift 'have' value. it will be Number(shift) else it's undefined it will be null.

example:

Code:
Game_Event.prototype.getRunValue = function(){    var comment = "";    if (this.page())    {    var pagelist = this.page().list;       for (cmd of pagelist)       {            if(cmd.code == 108)     comment += cmd.parameters[0] + "\n";            if(cmd.code == 408)     comment += cmd.parameters[0] + "\n";                }    }    if(comment.match(/<run:\s*(.*)>/im))    {        var shift = comment.match(/<run:\s*(.*)>/im)[1];    }    var range = shift ? Number(shift) : null;    console.log(range);    return range;}
Oh wow, okay it does give me the value. But the problem left is that this command seems not to work:

Game_Event.prototype.checkRun= function(){ if (Math.abs($gamePlayer.x - this.x) + Math.abs($gamePlayer.y - self.y) <= this.getRunValue()) { //run command here }}It gets the value, say I do <run: 4>

the event should detect if I am near it, then runs. I wonder if I messed up my formula.
I personally walk through the current maps set of event and then dasherize (via undercore.string) the name of the event. 

If I need them for something else I will create an object container that stores the events so I can reference them when you are not on said map any more 🙂
I am basing this from an old code by Littledrago and I don't know where I messed up. What I wanted was like a pre-made ranged events, where if they are standing near you, they should be walking, running or jumping, depends on the note tag. It gets the note tag's value well, but then again it doesn't do anything after. I tried to make a print value to see if it works and it does...but the actions, no. A simple this.jump(0,0) won't even execute.
if the value returned by comment is already correct then your code to execute the action is at fault.

do you convert some ACE script? because sometime there's a difference between ACE and MV. and we need to find how to make it work in MV.
I was able to solve it, thanks 🙂

Original thread: https://forums.rpgmakerweb.com/threads/game_event-questions.51468/