@SemlerPDX, would you mind helping me in the right direction for the coding of something like that above? I don't expect you to share all your secrets and full code. But having some examples def. goes a long way.
Thanks in any case in advance!
How you proceed will depend on options you choose, how it will be executed (inline function code or from a plugin you create), and what you are capable of learning.
1. Choose whether you will execute this code from an inline or plugin
2. Decide on the data storage structure you will execute (text file, XML, JSON, even SQL, etc.)
3. Learn how to write and read entries in this structure
4. Build and test your functions for save all/save one/load all/load one (however you feel is best)
5. Implement your design and find some beta tester that is NOT on your local machine (this matters!!)
The basic "game loop" of learning to code is this: study -> try -> fail -> learn -> repeatData structures such as a flat text file can be as simple as using a "name=value{NEWLINE}" structure. Loading involves reading all lines, splitting those lines at the "Environment.Newline" separating them, and then splitting each line at the "=", which provides access to the name and value which you can easily use such as 'VA.SetText(name, value)`. Just know that such a flat text file system has limitations and drawbacks including replacing symbols such as "=" with some keyword you can replace after you have finished splitting the line at the "=" separating the name and value, else such a symbol in the value would throw off your parsing system. Use TryParse (or just Parse) methods to get values such as Integers, Decimals, or Booleans back into their correct data type from strings for setting VA variables.
// For example, if we had the string value from the file reading as "true":
string nameValue = "MyVarName";
string stringValue = "true";
bool booleanValue;
if (bool.TryParse(stringValue, out booleanValue))
{
VA.SetBoolean(nameValue, booleanValue);
}
else
{
// Conversion failed, handle the error case
}
If you use something like JSON or XML, you can read the file using systems that already have methods for iterating through and acquiring data values from each entry (such as `entry.Name` or `entry.Value` for a deserialized JSON file which contains fields of 'Name' and 'Value' for each entry), and so might be more structured and easy to work with. The benefit of these file types is that they are still human readable and can be manually opened in any Notepad to review their contents and values, or even manually change them. These can become a pain to load in any Notepad or read into memory programmatically when their size grows to the realm of thousands or tens of thousands of entries. A plugin would be required for JSON, but you
could get away with parsing an XML in an inline alone.
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
/// ...then in your class/method:
// Assuming you have a JSON file at the given file path
string filePath = @"path\to\your\file.json";
// Read the JSON file contents
string json = File.ReadAllText(filePath);
// Deserialize the JSON into a Dictionary<string, object>
Dictionary<string, object> deserializedObject = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
...then you could iterate through each key/value pair in the `deserializedObject` dictionary and cast each value as the appropriate type while setting them to the appropriate VA.Set methods for that entry type.
SQL is a database structure which doesn't allow us to manually view the contents of the file without an interface of some kind. A plugin would be required for any sort of SQL. I prefer EntityFramework because it is perfectly suited for working with .NET objects as we already are in C# plugins for VoiceAttack. This type has the benefit of being able to grow in size to limits only dictated by the machine it runs on and other factors on such a massive scale that for tiny users like us could be considered limitless. It is extremely fast to query for an entry based on its key value, which is typically a unique integer but can be changed to any data type through annotation [Key] such as a string, so long as each entry has a unique string for this field (much like a save file would, no variable name is the same as another).
Explore what works best for you, and use google and/or ChatGPT to help explain concepts you are not familiar with - using the prompt qualifier "Explain this like I'm 5:" before your question can help ChatGPT form basic analogies to help with the learning curve - just don't expect it to be able to write all your code for you, it makes mistakes and assumptions frequently and should be used to get you started but only to proceed with private testing and appropriate modifications/alterations on your part before implementation.
Best wishes and good luck!!