Detecting files in system folder

I have a pretty advanced request. Basically I have been trying to make a module in rpg maker vx ace that detects multiple variables located in a .dll file in the system folder in the project folder. I want it so when it detects what a variable's value is in the file, whatever that variable is set to it also sets a variable in the variables tab in the editor to the same value. I understand that this isn't exactly a simple request, and it might not even be possible, but if it is, I thank you very much and you will definitely be credited in the game this will be used for. I'll keep trying to figure this out on my own until either I figure it out (in which I will post how I did it) or someone else figures it out.
Moved to: RGSS3 Script Requests
I want it so when it detects what a variable's value is in the file, whatever that variable is set to it also sets a variable in the variables tab in the editor to the same value.
I'm kinda confused here...
In which editor? Because variables can only be set with event commands or script calls in the default editor.
Or do you want to load these variables from a file and use them in the game? Because that is fairly simple to do, but somehow I doubt that you meant that.
I'm kinda confused here...
In which editor? Because variables can only be set with event commands or script calls in the default editor.
Or do you want to load these variables from a file and use them in the game? Because that is fairly simple to do, but somehow I doubt that you meant that.
Ok sorry, I thought that may have been confusing.
Basically, I want to have it so I can make some sort of script call within and event that changes a variable that is located within a file (in this case GameSetup.dll), acting as a variable that applies across all playthroughs of the game. I want it so when the variable inside the file is set to specific values it changes aspects of the game, and the values don't get reset when new game is selected from the main menu.

(I'm realizing now that there were a couple of things I forgot to mention in the initial post, sorry about that, also if it's easier instead of an external file I really just need a specific variable that doesn't get reset when new game is selected.)
Does it have to be a real dll (as in, a file written in C and can be loaded with WinApi), or a simple file with any other extension?
Working with real dlls is a bit more trickier, and one must know the code in them to do so.
Doing it with simple files is much easier. It can still have some kind of encryption if you are worried about that.

I can only help with the simple file method, since I don't know C that much to be of any use in that terrain.
Here is how the logic works here:
  1. Check if the file is existing already or not.
  2. If not, make the file (with some default data, obviously).
  3. Now that we have the file, you can load the data you need to any amount of variables (in the editor) to be used in the game later.
  4. You will have to save these variables to the created file when they are changed if you want to keep them between all players/playthroughs.
The basic code could look like this, for example:
Spoiler
Code:
  # The method to load the custom data from your file
  def load_custom_file
    # Setup the folder path and filename of your file here
    # It can have other extensions, but I always use .rvdata2
    file = "System/MyFile.rvdata2"
    begin
      # Load the file if it exists
      @my_vars = load_data(file)
    rescue
      # Initialize the data in your file here
      @my_vars = {
        'varname1' => 'somedata1',
        'varname2' => 'somedata2',
        'varname3' => 'somedata3',
        # And so on...
      }
      # Save the file with the starting values
      save_custom_file
    end
  end

  # The method to save the new data into your file
  def save_custom_file
    # This should be the same folder path and filename as above
    file = "System/MyFile.rvdata2"
    save_data(@my_vars,file)
  end
Once you executed the load_custom_file method (and you should only execute it once on game startup), the @my_vars variable will be usable in your code.
I made that to be a hash, because I use hashes pretty often (I like to name the elements in my variable, which is why I avoid arrays for this purpose if possible), but it can be any other data as well (array, string, etc). Same for the key names and data in that hash, they can be almost anything you want (the exceptions being the objects which can not be Marshal.dump-ed, such as Sprite, Bitmap, Proc and Fiber objects, for example).
From that @my_vars variable, you can get your data just like from any other hash, use the name of the keys to get the connected data.

Whenever you changed something in the @my_vars hash (your data) during the game, you should also save it to your file using the save_custom_file method.
Well, it is not really necessary all the time, it depends on what you want to use this data for. Just make sure that you don't save it constantly for no reason, because that will slow down your game (depending on the size of the data) and the HDD won't like it either.

The begin/rescue part could be replaced with a simple if File.exist?(file) check instead, but that will NOT work in encrypted folders (it will crash your game), so if you want to store your file in an encrypted folder, you must use begin/rescue instead.

Obviously, the above code example is just a pseudo-code. You can (well, should) put it in a class, and call the 2 methods from there.

You can also use a global variable instead of an instance variable, I just didn't know for what you want to use it and where, so I don't know if you need a global variable or not. But I will assume that you know how to change it to a global variable because I am getting way too sleepy to write more. 😀

I assumed that you have some coding knowledge (because you wanted to figure this out yourself according to the OP), but if you don't and don't understand something, I can write an actual script for you tomorrow.
No it definitely doesn't have to be a dll file, I just assumed that's the only file that could be used (the simplest option is better to me!) however, the global variable might be all I need. I'll try it out first thing tomorrow as I am also getting too tired to really do any more work right now but I will definitely let you know if it works or if I need the script you are talking about. Also, I would just say what I would like to use this variable for, I just don't want to let a spoiler go for the game I'm working on, maybe I could pm you or something and tell you what I need so I can get exactly what I want.

Thanks for the help so far!
Ok so the code block seems to be exactly what I need, the only parts I'm not understanding is how I can set the variables in the @my_vars area (varname1, varname 2, varname 3, etc.) cause I want each of these to be equal to specific variables in the variables tab (the variable counterpart to switches in events) so when those variables in the file are a specific value those variables in the variables tab are the same value, so when I do a conditional branch in an event to check for these variables the scene can change based on what variable is present. Also what script call do I do to change the values inside the GameSetup.rvdata2? Again, if you want, I can PM you so I can fully explain what I want with no risk of public spoilers if you don't understand what I'm asking and if you don't mind me PMing you.

(sorry for the late response, I got unexpectedly busy)
So, you want global variables which are shared between all playthroughs?
If so, here is a script for that:
Spoiler

Just setup the global variables in it, and you are good to go. Operate these variables like you would any other variables, they will get saved and loaded automatically when needed, so no extra script calls or anything is needed.
Alright, this seems perfect for what I want, just one question about the part under @data. I understand that the parts that say 10, 13, 24 are supposed to be the variables IDs under the variables tabs, but are the numbers beside those ones supposed to be replaced the variable names in the file (This only confused me cause one of them has a string while one has a number, the other is blank, and they all have different symbols surrounding them)?

@data =
10 => 15, <---- These parts
13 => 'somedata2', <----
24 => [ ], <----
Those will be the values of the variables.
I set different data types for them to show that they can store all kind of things, not just numbers like most people think.

The file itself is just that, a file which stores these variables on your HDD, so it can be saved and loaded across all playthrough.
You don't actually edit this file manually, the script does that for you automatically whenever one of the specified global variables (in the @data settings) is changed.

So, if you want Variable 12 to start with the number 100 as it's value, you would enter this in the @data settings:
Code:
12 => 100,
If you want Variable 40 to start with the string "None", you would enter this:
Code:
40 => "None",
If you want Variable 187 to be an array with some numbers at the start, you would add:
Code:
187 => [12,15,18,24],
And so on...

If you only want to save numbers into these variables, you can, of course, do that.

In the event editor, you change these variables like any other variables, use the "Control Variable" event command, or even a script call to do it, if you know how to set variables with that.
Same thing with the variable checks, just simply check for them with the "Conditional Branch" event command or, again, within script calls, if you know how to do that.
This works just perfectly! It's exactly what I needed! Thank you so much Sixth, I will make sure (if you want anyways) to give you a special thanks shout out in the script credits in any game I use this in! (also as a side note, if you already make a GameSetup.rvdata2 file, the variables just act as a normal rpg maker variable, so to fix that all that needs to be done is to delete the already existing file)

Thanks for the help!
~Spak

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/detecting-files-in-system-folder.89517/