Iavra Self Variables

Discussion in 'JS Plugin Releases (RMMV)' started by Iavra, Nov 21, 2015.

  1. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    Description


    Adds self variables to the game, that work similar to self switches.


    Author


    Iavra


    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 SelfVariable




    How to Use


    Adds self variables 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:


    $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:


    $gameSelfVariables.get(this, key);
    $gameSelfVariables.set(this, key, value);


    Self Variables can also be modified via plugin commands. The following operations are available:


    = 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:


    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:


    SelfVariable key abs // Sets a self variable to its absolute value.




    Terms of Use


    Free to use for both commercial and non-commercial games. Please give credit.


    Download


    http://pastebin.com/fGnQBBPB


    Notes


    The plugin originated from this request: http://forums.rpgmakerweb.com/index.php?/topic/51012-self-variables
     
    Last edited by a moderator: Feb 1, 2016
    #1
    Eliaquim, LittleSY, Ste and 8 others like this.
  2. Neo Soul Gamer

    Neo Soul Gamer Veteran Veteran

    Messages:
    614
    Likes Received:
    332
    Location:
    Nova Scotia, Canada
    First Language:
    English
    Primarily Uses:
    N/A
    This was actually one of my wishes for the next RPG Maker. Finally, something to minimize that extensive list of variables. Thanks a lot for this!
     
    #2
  3. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    Added a "set" script command, that can be used to set a self variable on the current event.


    Apart from the basic operations listed above, MV variables can also be set to game data, like "hp of actor 1" or "current map id". This is already possible using the script commands, but not via plugin commands. I could add this, if needed, since it's mainly a lot to write.


    Performance will go down for these, though, since i have to first test for all basic functions, which involves a fair amount of regexes.
     
    #3
  4. Lyson

    Lyson Potholders! Veteran

    Messages:
    91
    Likes Received:
    35
    Location:
    USA
    First Language:
    English
    Local variables for events?! What is this madness?

    This is so handy!
     
    #4
  5. Capri

    Capri Villager Member

    Messages:
    7
    Likes Received:
    1
    First Language:
    German
    It doesn't seem to work with loaded games.

    (New game: Trigger event & do stuff with SelfVariables. Do happy dance, because it works! Save game. Exit. // Load Game. Trigger same event => "Type Error - undefined is not a function".)

    Any ideas?
     
    #5
  6. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    Could you post the whole stack trace? (press F8 for console). Also, please post a screenshot of your event, so i can recreate it.


    /edit: I fixed the issue. Looks like JSON.stringify/JSON.parse can't deal with classes defined in an anonymous function, so i had to export the Game_SelfVariables class to the public scope.
     
    Last edited by a moderator: Nov 23, 2015
    #6
  7. Capri

    Capri Villager Member

    Messages:
    7
    Likes Received:
    1
    First Language:
    German
    Just when I was about to post my screens XD /jk
    Thanks for fixing it so fast! :) Your script is awesome, btw.
     
    #7
  8. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    A small update: Tsukihime's Custom Page Conditions has been updated to use a Game_Interpreter instance, instead of a custom function, so there's no need to use my ported plugin, anymore (you can still do so, though, it's not like it suddenly stopped working ^^).
     
    #8
  9. ramza

    ramza Lunatic Coder Veteran

    Messages:
    550
    Likes Received:
    304
    Location:
    Nova Scotia, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    Despite the fact that the help information says a key can be any string, the plugin doesn't seem to work unless I use an integer value for the key (in my case, I used the number 1). This added a layer of confusion to setup for this, as I was constantly plagued by undefined errors when I was using a string.


    Is there a way to force the plugin to define itself on an old save? If I load an old save after installing this, it doesn't work. Is there a workaround?
     
    #9
  10. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    It should work with any string, not just numbers. Since the plugin needs to store data in savefiles, it's not compatibe with saves created before using it.
     
    #10
  11. ramza

    ramza Lunatic Coder Veteran

    Messages:
    550
    Likes Received:
    304
    Location:
    Nova Scotia, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    Unfortunately it definitely doesn't work with a string.


    with number.png


    The above image causes a working event, which counts down 20 seconds real time before turning off it's self switch. the 'key' is the number 1.


    with a 3.PNG


    This is an attempt at using a string, the letter A. I had also tested with a number of words, in case single letter choices weren't viable for some reason.


    This causes the following error when attempting to use it.


    with A 1.png


    with a 2.png


    Interesting thing to note, is that is the same error it throws on an old save with or without the numbers. As you can imagine, it added some confusion to figuring out what the true cause of the issue was, when I was first trying it on an old save, and would get that error no matter what I put in, then attempted a fresh save to continue to get the error until I switched to using numbers.


    Either way though, it works. Just a heads up, maybe there's a mistake in the code somewhere, or some documentation needs to change. :)


    edit: I'm an idiot, strings need to be 'in single quotes' to work. My bad. Sorry for wasting your time XD
     
    Last edited by a moderator: Jun 30, 2016
    #11
  12. Martin

    Martin Veteran Veteran

    Messages:
    119
    Likes Received:
    26
    First Language:
    swe
    Primarily Uses:
    RMMV
    Hello @Iavra


    Thanks for awesome plugin!





    I have everything in place and working nice on the testmap, except when I copy my events out to the game-map using OrangeCustomEvents.


    TypeError: Cannot read property "value" of undefined.


    How can this be`?
    :D
     
    #12
  13. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    Please link to the other plugin and post a screenshot of the whole error message. There will always be incompatibilities between plugins, but i'll see if i can fix this.
     
    #13
    Martin likes this.
  14. Martin

    Martin Veteran Veteran

    Messages:
    119
    Likes Received:
    26
    First Language:
    swe
    Primarily Uses:
    RMMV
    Last edited by a moderator: Sep 3, 2016
    #14

Share This Page