Self Variables?

Discussion in 'Javascript/Plugin Support' started by Mistral, Nov 20, 2015.

  1. Mistral

    Mistral Villager Member

    Messages:
    18
    Likes Received:
    4
    Location:
    Canada
    First Language:
    French
    Primarily Uses:
    RMMV
    Hi!

    I guess the title is self-explanatory. Is there a way to have self variables? Using regular variables isn't really effective and rather time consuming when you have multiple events that works the same way. I'd like to just copy them without worrying about changing a bunch of variables each time, and risking to forget some or see errors arise.

    So yeah, is it possible or does it need a plugin?
     
    Last edited by a moderator: Nov 20, 2015
    #1
  2. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    855
    First Language:
    German
    It's possible, but needs a plugin. I currently don't have access to MV or my test project and i'm pretty sure some one else will have come up with a script before i get home, but i can do this in ~8 hours ^^
     
    #2
  3. Mistral

    Mistral Villager Member

    Messages:
    18
    Likes Received:
    4
    Location:
    Canada
    First Language:
    French
    Primarily Uses:
    RMMV
    That would definitely be awesome of you if you could do it! But don't worry, I'm in no rush at all, take as much time as you need :')
     
    #3
  4. Andar

    Andar Veteran Veteran

    Messages:
    28,003
    Likes Received:
    6,327
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    Just keep in mind that you can't condition self-variables directly in the editor, you'll always need a script line to access them. That is because the editor doesn't know them itself, they will only exist in the game engine - similiar to PK8's self-data-suite of Ace (that is incompatible to MV)
     
    #4
  5. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    855
    First Language:
    German
    Just calling back that i'm basically finished and adding a whole bunch of plugin commands to make it easier to interact with the container, so you don't everytime have to write

    Code:
    $gameSelfVariables.setValue([mapId, eventId, key], value);
     
    #5
  6. Mistral

    Mistral Villager Member

    Messages:
    18
    Likes Received:
    4
    Location:
    Canada
    First Language:
    French
    Primarily Uses:
    RMMV
    @Andar - Yeah, I know. To be honest, I kinda hoped it would work with Tsukihime's Custom Page Conditions, but now that you mention it I'm afraid it's not gonna be the case.

    @Iavra - That's awesome! And it's nice to add them, even if it doesn't bother me that much to use script calls. Thank you for doing it so quickly!
     
    Last edited by a moderator: Nov 21, 2015
    #6
  7. MuteDay

    MuteDay Mutation Engine Veteran

    Messages:
    253
    Likes Received:
    39
    First Language:
    English
    it will be able to be used with custom page conditions, just use a script call and a conditional branch using the script option, although takes a small understanding of programming, but very small here is image

    of how i do it using vlue's quest system

    quest with page condition.png

    as you can see with script calls you can easlily do pretty much anything :)
     
    #7
  8. Mistral

    Mistral Villager Member

    Messages:
    18
    Likes Received:
    4
    Location:
    Canada
    First Language:
    French
    Primarily Uses:
    RMMV
    Just as i hoped then! That's what I did when I was still working on a VXAce project, I shouldn't be too lost. Thanks for the heads up!
     
    #8
  9. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    855
    First Language:
    German
    So, i haven't included everything you can do with regular variables (to be exactly, the "Game Data" option. I might do, if there's enough interest, though).

    The plugin is here: http://pastebin.com/fGnQBBPB

    Parameters

    @param Container Name@desc Name of the self variables container. Default: $gameSelfVariables@default $gameSelfVariables@param Plugin Command@desc Name of the plugin command to manage self variables. Can't control whitespaces. Default: SelfVariable@default SelfVariableHow to UseAdds self variable to the game. These work similar to self switches and are uniquely identifies by a map id, an event id and a key (any string without whitespaces). This documentation assumes, that the plugin parameters "Container Name" and "Plugin Command" are set to their default values.

    Basic access to self variables is done via script commands:

    Code:
    $gameSelfVariables.setValue([mapId, eventId, key], value);$gameSelfVariables.value([mapId, eventId, key]);
    To access a self variable of the current event, the following script command can be used:
    Code:
    $gameSelfVariables.get(this, key);
    Self Variables can also be modified via plugin commands. The following operations are available:
    Code:
    =   Sets a self variable to a given value.+   Adds a given value to a self variable.-   Subtracts a given value from a self variable./   Divides a self variable with a given value.*   Multiplies a self variable with a given value.%   Sets a self variable to the remainder when dividing it with a given value (mod).
    To apply one of these operations, one of the following commands can be used:
    Code:
    SelfVariable key operation value             // Invokes an operation with a given value.SelfVariable key operation v[value]          // Invokes an operation with the value contained in a given variable.SelfVariable key operation self[value]       // Invokes an operation with the value contained in a given self variable.SelfVariable key operation (value1 ~ value2) // Invokes an operation with a random integer between 2 values.SelfVariable key operation "value"           // Evaluates the given expression as an integer and invokes the operation with it.
    Further plugin commands are:
    Code:
    SelfVariable key abs                         // Sets a self variable to its absolute value.
     
    #9
  10. MuteDay

    MuteDay Mutation Engine Veteran

    Messages:
    253
    Likes Received:
    39
    First Language:
    English
    your welcome, and hope it helps you get your game out faster :)
     
    #10
  11. Mistral

    Mistral Villager Member

    Messages:
    18
    Likes Received:
    4
    Location:
    Canada
    First Language:
    French
    Primarily Uses:
    RMMV
    Thank you so much! It works as intended, for the most part at least. Well, there're two things I can't get to work. 

    First, I don't know if I'm doing something wrong (which might be the case) but no matter what I try, plugin commands don't work. I did the following : http://i.imgur.com/6RHtjoP.png and the first condition is met but not the second, and -10 is printed to the console each time. I'm probably doing something wrong but I can't for the life of me figure what.

    The second problem is in relation to Tsukihime's Custom Page Conditions, which I mentioned earlier. It does work with a regular variable ( with the variable and script command of the conditional branch) but when I do this it doesn't. I guess it's because the two are not compatible, sadly (or I'm doing doing something wrong again). (and the first page of the event is this one, which works )

    That said, if you don't have the time to work on compatibility between the two, I'll totally understand, especially since you've already done a wonderful job doing this whole plugin D: (which I thank you again for!)
     
    Last edited by a moderator: Nov 21, 2015
    #11
  12. MuteDay

    MuteDay Mutation Engine Veteran

    Messages:
    253
    Likes Received:
    39
    First Language:
    English
    with page conditions try >10 and see if that works, i would test this but currently my game is broke due to new plugin
     
    #12
  13. MuteDay

    MuteDay Mutation Engine Veteran

    Messages:
    253
    Likes Received:
    39
    First Language:
    English
    ok fixed mine, so now ill be able to test it and see how it works
     
    #13
  14. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    855
    First Language:
    German
    Remove the '' in the plugin commands, so
    SelfVariable 'meow' + 1becomes
    Code:
    SelfVariable meow + 1
    Regarding Hime's plugin: The "get" function only works as long as "this" refers to the Game_Interpreter instance, so it won't work in this case. I'll try to find a better way to get the current event./edit: I don't think there's an easy solution, so you probably have to replace these "get" calls with "value" and build the keys :/

    //edit: This should do the same thing as Hime's Custom Page Conditions, but is compatible to my plugin (and everything else that relies on "this" in script commands): http://pastebin.com/qn7XJkmL
     
    Last edited by a moderator: Nov 21, 2015
    #14
  15. Mistral

    Mistral Villager Member

    Messages:
    18
    Likes Received:
    4
    Location:
    Canada
    First Language:
    French
    Primarily Uses:
    RMMV
    ( I planned on replying sooner but got caught up with work and chores D: )

    @MuteDay - It doesn't work either D:

    @Iavra - I was sur I did test it without, but did not have any result either. So I tested it and printed the results to the console and it kinda works, except for the addition and subtraction, it seems.

    Concerning the page condition, I almost missed your last edit :') It works like a charm! Thank you so much for taking the time to do this, it's really kind of you to help me.

    And last thing I totally forgot earlier. There's an error when trying to save (with a fresh project without other plugins nor saves) : this. (I feel bad reporting all those errors, I wish I could resolve them myself D: )
     
    #15
  16. MuteDay

    MuteDay Mutation Engine Veteran

    Messages:
    253
    Likes Received:
    39
    First Language:
    English
    lol dont feel bad, thats why you have a whole community of coders to fix the bugs you are getting
     
    #16
  17. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    855
    First Language:
    German
    The issues should be fixed now: http://pastebin.com/fGnQBBPB


    What changed:


    - Parameters weren't converted to integers and while this doesn't matter for other operations, "+" on strings will concat them. That's why "6 + 2 = 62".


    - The "-" was recognized as a special character by the regex, so i had to escape it.


    - I forgot to return the JSON object, after adding $gameSelfVariables to the save contents <.<


    /edit: I also increased the performance of my string-to-number conversions by using a 0 bit-wise shift (value >> 0) instead of parseInt(value). Although this shouldn't really matter, unless you are modifying a lot of self variables.


    I officially released this plugin (along with the port of Customt Page Conditions) here: http://forums.rpgmakerweb.com/index.php?/topic/51106-iavra-self-variables/
     
    Last edited by a moderator: Nov 21, 2015
    #17
  18. Mistral

    Mistral Villager Member

    Messages:
    18
    Likes Received:
    4
    Location:
    Canada
    First Language:
    French
    Primarily Uses:
    RMMV
    Everything works perfectly! I can't thank you enough for the work you've done. The community is lucky to have such patient and skilled members. Thank you again!
     
    #18

Share This Page