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

● ARCHIVED · READ-ONLY
Started by StrayBalloon 11 posts View original ↗
  1. 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?
  2. I am not at the computer so can't double check, but iirc this. _eventId or this.eventId I'm pretty sure :)
  3. 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
  4. StrayBalloon said:
    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.
  5. 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?
  6. 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.
  7. 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)
  8. @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:
    Spoiler
    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
  9. 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.
  10. Astfgl66 said:
    There are so many things wrong in that script call.

    like I said.
    eyeballing.
  11. 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.