Save variables

Discussion in 'JS Plugin Requests' started by Symbol_, Jun 18, 2019.

  1. Symbol_

    Symbol_ Veteran Veteran

    Messages:
    75
    Likes Received:
    14
    First Language:
    English
    Primarily Uses:
    RMMV
    Is there anyway to save variables to the game even if the player doesn't save themselves without saving the entire game? I want to stop people quitting and reloading the game to stop people cheating the casino in my game.

    Maybe a variable that saves to a separate txt doc in the folder?
     
    #1
    mathmaster74 likes this.
  2. Hyouryuu-Na

    Hyouryuu-Na . . . Veteran

    Messages:
    240
    Likes Received:
    111
    Location:
    Bangladesh
    First Language:
    Bangla
    Primarily Uses:
    RMMV
    #2
  3. Symbol_

    Symbol_ Veteran Veteran

    Messages:
    75
    Likes Received:
    14
    First Language:
    English
    Primarily Uses:
    RMMV
    #3
  4. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,654
    Likes Received:
    9,183
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Code:
    function save () {
    var fs = require ("fs");
    fs.writeFileSync ("./ba", $gameVariables.value(1));
    }
    
    function load () {
    var fs = require("fs");
    $gameVariables.setValue(1, fs.readFileSync ("./ba", "utf-8"));
    }
    Then use the script event command to call save() and load()
     
    #4
  5. ShadowDragon

    ShadowDragon Veteran Veteran

    Messages:
    386
    Likes Received:
    114
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    hime has a file save sync, so even if you save on a different save file, it basicly stays on 1, as well if possible an auto save upon spinning or using
    the casine machine.
     
    #5
  6. Galenmereth

    Galenmereth I thought what I'd do was Veteran

    Messages:
    2,200
    Likes Received:
    1,890
    Location:
    Norway
    First Language:
    English
    Primarily Uses:
    RMMV
    Be aware this won't work if you play the game in a browser from a server, whether locally or not, because node.js isn't available then.
     
    #6
  7. Eliaquim

    Eliaquim Raze: The Rakuen Zero's Guardian! Veteran

    Messages:
    570
    Likes Received:
    167
    Location:
    Brazil - Rio de Janeiro
    First Language:
    Portuguese - Br
    Primarily Uses:
    RMMV
    Why dont you save the game via script call after the player plays the cassino?
     
    #7
  8. Symbol_

    Symbol_ Veteran Veteran

    Messages:
    75
    Likes Received:
    14
    First Language:
    English
    Primarily Uses:
    RMMV
    Because I don't want the players position to be saved to the casino after they spin, my game has set points that you can only save from there. In my experience also, having savepoints in the same place as events with randomized variables has the habit of corrupting save data.
     
    #8
  9. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    3,907
    Likes Received:
    3,278
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    One way you could approach this would be to randomize the results far in advance - for example, you could dedicate 100 variables to the Casino and randomize them when the game first starts, with one additional variable cycling (in order) from 1 to 100 to track which variable should be used next.

    Whenever the player plays at the casino, it will use the results of one of those 100 variables (the one indicated by the additional variable), and then randomize and overwrite that variable afterwards (which will be used 100 plays later). An extremely long sequence would still create different results from one trial to another, but for people who want to save scum one or two results, they will never be able to because when they load, they will get the same result on those first 1 or 2 (or up to 100) tries, because whenever they last saved their game they will have also saved the results of the next 100 casino attempts.

    In other words, the random number "generator" for the casino event would look like:
    • Get the value of Variable 101 which tracks which of the first 100 Variables to use and use THAT value to determine which of the first 100 Variables to use, and get the value of that Variable (I think the script line would be: $gameVariables.getValue($gameVariables.getValue(101)); )
    • Use the value for whatever casino-related purpose you need to
    • Use Variable 102 to pick a new random number that will not be used now, but rather will be populated for later
    • Store the value of Variable 102 into the variable that you just pulled from (I think you'd use: $gameVariables.setValue($gameVariables.getValue(101), $gameVariables.getValue(102)); )
    • Increase the value of Variable 101 by 1 (and if it's greater than 100, set it back to 1)

    By the way, @Symbol_ I thought I was waiting for you on the commission, but I recently realized I was wrong, and you were actually waiting for me. Really sorry about that! Look out for a PM within the next week.
     
    #9
  10. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,654
    Likes Received:
    9,183
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    $gameVariables.value(101), not getValue.
     
    #10

Share This Page