Self Variables

● ARCHIVED · READ-ONLY
Started by Tsukihime 17 posts View original ↗




  1. 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.
  2. This is super awesomely cool! I love it, now I can have many, many, many variables!!  BD
  3. 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...)
  4. 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.
  5. Iavra said:
    Both self variable plugins might be incompatible, btw, as we are using the same class name.
    Thats probably ok though, since two self-variable plugins on one project is rather excessive so most people would use one or the other!
  6. Capri said:
    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...)
    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)

    Iavra said:
    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.
    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.
  7. 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)
  8. Just wanted to mention that self-variables can be used in move routes now using the same script calls.
  9. Is there a text control for displaying a self variable in a message???


    Like /sv[''] or something?
  10. Blue001 said:
    Is there a text control for displaying a self variable in a message???


    Like /sv[''] or something?



    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?
  11. 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.
  12. Tsukihime said:
    What do you think of these two problems?



    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[#]?
  13. Iavra said:
    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.



    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.

    Blue001 said:
    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[#]?



    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.
  14. Tsukihime said:
    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



    // 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)



    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!
  15. mimi-min said:
    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!



    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.
  16. Question:


    If I want to set a self variable to the current value of a global variable, can I do this and how?
  17. 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".