Accessing variable inside event

Discussion in 'Javascript/Plugin Support' started by Amy Pond, Jun 12, 2016.

  1. Amy Pond

    Amy Pond Veteran Veteran

    Messages:
    667
    Likes Received:
    1,359
    First Language:
    English (UK)
    Hi,


    I have some events which have a variable called _player. This is used to just give them an id number that associates with a player.


    I do this by:


    $gameMap._events[event]._player = player;


    Where player is an integer.


    The following works:


    alert($gameMap._events[event]._player); // prints an integer




    But inside the event, I use this script call:


    a = this._player;
    window.open(url + a);


    a is always undefined.


    How do I access the _player variable I have created from inside an event, if not with this._player ?


    To clarify this is what I am trying to replicate, but using the currently running event. This works:


    a = $gameMap._events[17]._player;
    window.open(url + a);


    Thanks for your help.
     
    #1
  2. Marrend

    Marrend Bludgeon of Inspiration Veteran

    Messages:
    60
    Likes Received:
    15
    Location:
    Temple of the Oracle
    First Language:
    English
    I'm going off VX Ace knowledge here. However, my gut instinct is telling me that, in the context of a script-call, "this" is referring to Game_Interpreter, or the MV equivalent thereof. Unfortunately, the only way I would know how to replicate the effect you are looking for would be to stash the event ID into a variable, and pass it into a function that looks like...


    a = $gameMap._events[num]._player;
    window.open(url + a);


    ...this?
     
    #2
    Amy Pond likes this.
  3. Victor Sant

    Victor Sant Veteran Veteran

    Messages:
    1,694
    Likes Received:
    1,437
    Location:
    Brazil
    First Language:
    Portuguese
    When you make a script call on anĀ event, 'this' don't refer to the event, but to the Game_Interpreter.


    the Game_Interpreter stores the event Id on 'this._eventId'
     
    #3
    Amy Pond likes this.
  4. Amy Pond

    Amy Pond Veteran Veteran

    Messages:
    667
    Likes Received:
    1,359
    First Language:
    English (UK)
    Thank you!
     
    #4

Share This Page