Save variables

Symbol_

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

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,039
Reaction score
10,259
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
1,048
Reaction score
328
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

I thought what I'd do was
Veteran
Joined
May 15, 2013
Messages
2,207
Reaction score
1,923
First Language
English
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()
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

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
910
Reaction score
362
First Language
Portuguese - Br
Primarily Uses
RMMV
Why dont you save the game via script call after the player plays the cassino?
 

Symbol_

Veteran
Veteran
Joined
Nov 28, 2017
Messages
105
Reaction score
14
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

Pre-Merge Boot
Global Mod
Joined
Jul 22, 2014
Messages
4,610
Reaction score
3,858
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,039
Reaction score
10,259
First Language
Czech
Primarily Uses
RMMV
$gameVariables.value(101), not getValue.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Made Custom ENEMY Information Screen
I'm having such a hard time thinking of an interesting battle system. and not being a coder, certain things I wanna do seem a lot harder lol.
Created a character outline with some code. I have no use for this. I'm....bored.....
Having lots of fun using different PS brushes to add a lil' texture to the floors and walls in my maps.

Forum statistics

Threads
93,721
Messages
914,912
Members
123,324
Latest member
ahmbor
Top