Save variables

Symbol_

Veteran
Veteran
Joined
Nov 28, 2017
Messages
116
Reaction score
18
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?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
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()
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
2,948
Reaction score
1,053
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.
 

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,158
First Language
English
Primarily Uses
N/A
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()
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.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,710
Reaction score
1,127
First Language
Portuguese - Br
Primarily Uses
RMMZ
Why dont you save the game via script call after the player plays the cassino?
 

Symbol_

Veteran
Veteran
Joined
Nov 28, 2017
Messages
116
Reaction score
18
First Language
English
Primarily Uses
RMMV
Why dont you save the game via script call after the player plays the cassino?
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.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,635
Reaction score
5,116
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.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
$gameVariables.value(101), not getValue.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,547
Members
137,835
Latest member
yetisteven
Top