Game_Event questions

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'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:



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?
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
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.
 
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
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.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
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.
 
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
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.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
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 :D . if you use that it will clash with my plugin :p .

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...
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
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.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
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;}
 
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
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.
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
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 :)
 

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 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.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
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.
 

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 was able to solve it, thanks :)
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,017
Messages
1,018,356
Members
137,802
Latest member
rencarbali
Top