How would I self-reference an event in this script call?

StrayBalloon

Warper
Member
Joined
Oct 30, 2018
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMVXA
I'm using the following script call in a conditional branch,

Code:
Math.abs($gamePlayer.x - $gameMap.event(id)._x) + Math.abs($gamePlayer.y-$gameMap.event(id)._y) <= distance trigger;

I would then fill in the "event(id)" and "triggering distance" manually. This would be used in the running event that would then trigger a response. Like say, chase the player, run from the player, do something goofy etc etc.

In Ace, there was a way to self-reference a running event to itself. (I forget off the top of my head; something like @thisevent maybe.)

My question is how could I change this script call so it references itself, making it much more easy to copy/paste dozens of them at a time?

Something like,

Code:
Math.abs($gamePlayer.x - $gameMap.event(this._eventid)._x) + Math.abs($gamePlayer.y-$gameMap.event(this._eventid)._y) <= 3;

But has correct syntax?
 

lordosthyvel

Veteran
Veteran
Joined
Jun 11, 2012
Messages
61
Reaction score
29
First Language
Swedish
Primarily Uses
RMMV
I am not at the computer so can't double check, but iirc this. _eventId or this.eventId I'm pretty sure :)
 

StrayBalloon

Warper
Member
Joined
Oct 30, 2018
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMVXA
I hadn't thought of trying it without the "_" . Gave it a try, but the results are the same. The game doesn't crash or anything, but the event doesn't do what it's supposed to do. Below is the script call copied and pasted from the conditional branch.
Code:
Math.abs($gamePlayer.x - $gameMap.events(this.eventid)._x) + Math.abs($gamePlayer.y - $gameMap.events(this.eventid)._y) <= 2;

It's supposed to flip self-switch "A" when the character gets within 2 tiles of the event. This will result in an image change so I can verify it works. But it doesn't do anything.

I'll include screen captures.EventPage1.png
 
Last edited:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,417
Reaction score
1,434
First Language
Spanish
Primarily Uses
RMVXA
In Ace, there was a way to self-reference a running event to itself

because the interpreter on the event runs at event level, so "this" is effectively "this event"
you can call event functions directly instead of Game_Object.function() because the object you're running from is already Game_Object.

I believe the word you're looking for, for Ace, is "self"
"self.x" is effectively $map.events(self.id).x.

I can't tell you the JS form from memory... in fact, I don't know if JS has one for that.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,136
Reaction score
10,674
First Language
Czech
Primarily Uses
RMMV
I wonder, what is the event actually supposed to do? The syntax in your first post is legit, but it looks like you're having different expectations than the result is actually. So what is it supposed to do?
 

StrayBalloon

Warper
Member
Joined
Oct 30, 2018
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMVXA
Well I opened an old Ace project just to sort this out. Copied and pasted from the working game; looks like this:
Code:
(($game_map.events[@event_id].x - $game_map.events[001].x).abs + ($game_map.events[@event_id].y - $game_map.events[001].y).abs) == 1
This conditional would check if Event#1 (which is an arrow fired by the player) was one tile space away from the running event.

So the running event could reference itself with @event_id.

I would desperately like to recreate this functionality in MV. I've found "this._eventid" to work in some other situations, but doesn't seem to work in this particular case.


POST Edit:

@Poryg

What I'm trying to do is have an event check its distance from either the player or another event, and when the specified distance has been met, run the contents provided in the conditional branch.

So in the simplest of terms, is the player an (X) distance from me(the parallel process event)? If yes, then (things happen).

This might have been showcased better in one of my previous posts pictures, but it looks like it didn't post proper so I will edit that and fix it.
 
Last edited:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,417
Reaction score
1,434
First Language
Spanish
Primarily Uses
RMVXA
this.whatever is the same as self.whatever, in JS.
_var is the equivalent of @var.

so, eyeballing,...
Code:
((this.x - $game_map.events[001].x).abs + (this.y - $game_map.events[001].y).abs) == 1

but that should only work if the conditional is used in the events' pages.
the syntax for the move route is different.
in some cases, you don't even need the "this", because since the code is run at event level the program will take that call as a local function (it should inform you that it's missing from the code, if it can't find it... in which case, you direct it to "Object.functionWhatever", specifying the Object it is from)
 

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
733
Reaction score
590
First Language
French
Primarily Uses
@gstv87
There are so many things wrong in that script call.
To start with it's $gameMap, event and abs are functions and should be called as such. Also you should use strict equality checks with ===.
A translation of the above's script call that would actually work would be:
Code:
(Math.abs(this.x - $gameMap.event(eventId).x) + Math.abs(this.y - $gameMap.events(eventId).y)) === 1
But that would be assuming event script calls are done in the event context, which is wrong.

@StrayBalloon
Your second script call in the opening post was mostly right.
Do a script call with console.log(this) and check the logs you'll see where you've gone wrong.
If you want the ready made solution:
Your first script call was right, only the property isn't named _eventid but _eventId, casing is important.
Code:
(Math.abs($gamePlayer.x - $gameMap.event(this._eventId)._x) + Math.abs($gamePlayer.y-$gameMap.event(this._eventId)._y)) <= 3;

So yes, lordosthyvel already gave you the answer, but you focused on the wrong part of it
 
Last edited:

StrayBalloon

Warper
Member
Joined
Oct 30, 2018
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMVXA
Heh, yep you're right. I had two separate issues.

I would sometimes type $gameMap.events() instead of $game Map.event().
And as you pointed out, this._eventId has a capital "I".

Tested, and working fine now. Thanks a ton. We can close as resolved.
 

Minionice

Villager
Member
Joined
Dec 29, 2018
Messages
7
Reaction score
5
First Language
English
Primarily Uses
RMMV
In MV, in the contents of an event, you can reference its JS object using:

$gameMap.event(this._eventId) .
This would only fail if the player moves to a different map within the event.
 

Latest Threads

Latest Profile Posts

Who here knows of the hidden laws of this multiverse? Such as the law of attraction
Exploding Fruits and Rasaks Pixelfarm Assets | RPG Maker News #108

So ghosts can go through walls and stuff, and depending their type (according to fantasy media) they can or can't interact with objects to a certain degree...

So why they don't always fall through floors? Do they always float and sometimes simulate walking? If things go through them how can they hear/see? And why sometimes they have clothing? Do clothes die as well?
my birthday was yesterday...
i feel closer 2 being able 2 get a discount on the kids menu than i do being able to buy booze1627428008986.png
Getting to play your RM game on Steam Deck? How cool is that?

Forum statistics

Threads
113,704
Messages
1,076,773
Members
147,726
Latest member
Switchboy0815
Top