Self Variables

Discussion in 'JS Plugin Releases (RMMV)' started by Tsukihime, Dec 10, 2015.

  1. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,067
    Location:
    Toronto
    First Language:
    English




    This plugin introduces the concept of "Self Variables" for your events.

    Similar to Self Switches, each event can hold its own set of self-variables, which you can use to keep track of things like how many times you've interacted with the event, or the last position of the player that this event has seen, or anything else that you would like each event to keep track of on their own.

    An event can have as many self-variables you want as long as you find an appropriate name for them.

    Unlike self-switches, which only hold a true or false value, self-variables can hold any kind of information. Because you can access them using script calls, they can be used in conditional branches and other parts of your event to create intricate events that interact with the player or the game itself!
     
    More information and downloads available at HimeWorks
    Self-variables can also be accessed using Custom Page Conditions, allowing you to create page conditions based on self-variables.
     
    Last edited by a moderator: Dec 10, 2015
    #1
    Ebanyle, Philsco, Halrawk and 12 others like this.
  2. Ghost of Christmas Kloe

    Ghost of Christmas Kloe Ghost of a Princess Seagull Veteran

    Messages:
    1,504
    Likes Received:
    913
    Location:
    Somewhere...
    First Language:
    English
    Primarily Uses:
    N/A
    This is super awesomely cool! I love it, now I can have many, many, many variables!!  BD
     
    #2
  3. Capri

    Capri Villager Member

    Messages:
    7
    Likes Received:
    1
    First Language:
    German
    Is this like Iavra Self Variables script? I'm tempted to use yours for better compatibility with your other scripts. But can I access self variables from another map?
    Also, if I clone an event with EST's "Clone Transform Delete Event" script, would it clone the self variables, too? (I'll assume it won't, but I think it would be a nice feature...)
     
    #3
  4. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    It should not be compatible with Hime's custom page conditions (but with mine). Other than that, it does exactly the same, without plugin commands.


    /edit: I see, the page condition plugin has been altered to use my way, instead, so it does work ^^


    Both self variable plugins might be incompatible, btw, as we are using the same class name.
     
    Last edited by a moderator: Dec 10, 2015
    #4
  5. Ghost of Christmas Kloe

    Ghost of Christmas Kloe Ghost of a Princess Seagull Veteran

    Messages:
    1,504
    Likes Received:
    913
    Location:
    Somewhere...
    First Language:
    English
    Primarily Uses:
    N/A
    Thats probably ok though, since two self-variable plugins on one project is rather excessive so most people would use one or the other!
     
    #5
  6. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,067
    Location:
    Toronto
    First Language:
    English
    1. It's similar. I think the biggest difference is I haven't implemented ways to operate on them as numbers.


    2. Self-variables are stored globally, so they can be accessed from outside of the event, but I would not recommend doing that because "self" variables are meant to be private to each event.


    The reason why they are not stored with the event (despite being "self" variables) is because events are not stored in savefiles by default.


    3. Because they are stored globally (and not with the event itself), it won't be cloned with the event (though that depends on how the event cloning works as well)

    Didn't notice there was already a self-variables plugin. I see that you have implemented functions for manipulating the variables as well without having to do it all through scripts, which is more user-friendly.
     
    Last edited by a moderator: Dec 10, 2015
    #6
  7. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,067
    Location:
    Toronto
    First Language:
    English
    Plugin has been updated to allow you to specify event ID and map ID in the script calls.

    This allows you to have an event operate on other events' self-variables.

    Usage is similar

    Code:
    // set self-variable "my variable name" to 3, for current eventthis.set_self_variable("my variable name", 3)// set self-variable "my variable name" to 3, for event 4this.set_self_variable("my variable name", 3, 4)// set self-variable "my variable name" to 3, for event 4, on map 5this.set_self_variable("my variable name", 3, 4, 5)
     
    Last edited by a moderator: Dec 28, 2015
    #7
    Nickel and Roguedeus like this.
  8. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,067
    Location:
    Toronto
    First Language:
    English
    Just wanted to mention that self-variables can be used in move routes now using the same script calls.
     
    #8
  9. Blue001

    Blue001 Veteran Veteran

    Messages:
    231
    Likes Received:
    110
    Location:
    Maine, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Is there a text control for displaying a self variable in a message???


    Like /sv[''] or something?
     
    #9
  10. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,067
    Location:
    Toronto
    First Language:
    English


    That would be somewhat complex, since a self-variable requires three pieces of information


    1. A map ID


    2. an event ID


    3. a variable ID


    Some other issues come to mind.


    1. it probably isn't useful to *hardcode* a map ID or event ID, because you probably want different events to say different things based on what their own self-variables are (otherwise you would probably just use a regular game variable).


    2. Even if hardcoding the ID's are ok, when a message is being displayed, it would need to know *which* event called the message, and there's no guarantee that a message was displayed due to an event (because a message can be displayed by any object, and not just the "show text" command)


    What do you think of these two problems?
     
    #10
  11. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    From Window_Message (which is the part that translates escape codes), it's not possible to know, which event triggered the message. You have 2 options:


    - Add a new property to Game_Message, that gets set by the interpreter, that requested the message. Could lead to some side effects, though, since the message lifecycle is somewhat complex.


    - Create the escape code with 3 parameters, so you can uniquely identify the self variable. More to write for the user, but trivial to do.
     
    #11
    Tsukihime likes this.
  12. Blue001

    Blue001 Veteran Veteran

    Messages:
    231
    Likes Received:
    110
    Location:
    Maine, USA
    First Language:
    English
    Primarily Uses:
    RMMV


    Well, is there a script you can call from an event to save one of it's self variables into a global variable, so we can just use \v[#]?
     
    #12
    Tsukihime likes this.
  13. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,067
    Location:
    Toronto
    First Language:
    English


    Yes, my first thought was to provide 3 parameters, but then I was thinking "what if they wanted each event to display a message using their own self-variables?"


    And then things just went downhill from there.


    I am not a fan of the way the message is designed, since it treats Game_Message as a global variable. So if you had an event call a common event (which does not have self-variables), things won't go well.



    You could do that with a script call


    $gameVariables.setValue(2, this.get_self_variable("SomeVar"))


    Which sets your "SomeVar" self-variable into game variables 2.


    Then you can use \v[2] in your message.


    I might actually just go with this kind of thing


    \vs["SomeVar", 3, 10]


    Which means self-variable "SomeVar" from event 3 on map 10, to avoid having to do that manual setting.


    It means you won't be able to just copy-paste the event and have it work automatically, but it's still better than nothing.
     
    Last edited by a moderator: Feb 2, 2016
    #13
    Blue001 likes this.
  14. mimi-min

    mimi-min Will draw for food. Member

    Messages:
    16
    Likes Received:
    8
    Location:
    Osaka, Japan
    First Language:
    English
    Primarily Uses:
    RMMV


    I'm not sure I understand correctly, I'm getting confused with all the numbers. Is it possible to explain it in a different way, maybe using *A*, *B*, *C* for the "eventId" in this example? Sorry, I'm kind of slow.


    Would it be possible to alter an event's variables based on an event Id that's passed through using a variable? Like grabbing the event Id from the object to the player's left, passing that through and causing it's "color" variable to 4.


    Edit: Never mind, I think I got it after separating it out in notepad. So it goes like this, right?


    this.set_self_variable("my variable name", x, y, z)


    Where x is the value, y is the event id and z is the map id? Don't know why I'm asking, I'm sure that's probably it. It seems obvious now. ^^;


    Thank you for the awesome plugin!
     
    Last edited by a moderator: Apr 26, 2016
    #14
  15. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,067
    Location:
    Toronto
    First Language:
    English


    Yes.



    Basic usage is just


    this.set_self_variable("var name", value)

    This assumes you're working with "this" event, which is the one that's making the script call.


    However, if for some reason you wanted "this" event to access other events, you would specify the Id of the event, and the map that event is on.


    Note that you could have "this" event send its own value to other events.
     
    Last edited by a moderator: Apr 26, 2016
    #15
    mimi-min likes this.
  16. Kanoonoo

    Kanoonoo Todd George Kelly Member

    Messages:
    18
    Likes Received:
    2
    Location:
    UTAH!!
    First Language:
    English
    Question:


    If I want to set a self variable to the current value of a global variable, can I do this and how?
     
    #16
  17. Raen Andaleio

    Raen Andaleio Veteran Veteran

    Messages:
    92
    Likes Received:
    17
    Location:
    Germany
    First Language:
    German
    I get the error "TypeError - Cannot read property 'setValue' of undefined".


    My code:


    this.set_self_variable("regrow", 1);


    When I try to use the code from the tutorial video


    var oldVal = this.get_self_varialbe("talk_count") || 0;


    I get "TypeError - Cannot read property 'value' of undefined".
     
    Last edited by a moderator: Oct 20, 2016
    #17

Share This Page