Author Topic: "Save value to profile": questions  (Read 4908 times)

Technomancer

  • Jr. Member
  • **
  • Posts: 98
  • I have a bad feeling about this...
"Save value to profile": questions
« on: May 07, 2021, 06:08:03 PM »
1. I'm assuming this function overwrites the variable if it already exists?

2. Also, within reason, how many variables can you save before VA gets "bloated/sluggish"...if at all.

3. Any chance of constantly writing to the profile will eventually corrupt it?  This is just a curiosity question, I only plan on saving at the end of game sessions.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4786
  • RTFM
Re: "Save value to profile": questions
« Reply #1 on: May 07, 2021, 07:33:25 PM »
1. I'm assuming this function overwrites the variable if it already exists?
Saving to the profile overwrites the value previously stored there, if any. Retrieving a value from the profile will overwrite the value of the VoiceAttack variable you're retrieving to, regardless of whether a value was actually stored in the profile (in that case, the variable would be Not set)

2. Also, within reason, how many variables can you save before VA gets "bloated/sluggish"...if at all.
The amount of values is much less relevant than the amount of data you're actually storing. If you're storing sections of text, for example, that'll take up a lot more space than a few Booleans.

The most likely effect of database bloat would be longer profile loading times, as profile data is cached in memory

3. Any chance of constantly writing to the profile will eventually corrupt it?  This is just a curiosity question, I only plan on saving at the end of game sessions.
VoiceAttack only writes saved values to the profile database either when VoiceAttack is shut down gracefully, or when a change to a profile is saved manually (from the "Edit a Profile" window), so the chances are very slim (of course that does mean that data can be lost until it has actually been written to the database).

Technomancer

  • Jr. Member
  • **
  • Posts: 98
  • I have a bad feeling about this...
Re: "Save value to profile": questions
« Reply #2 on: May 07, 2021, 08:48:41 PM »
3. Any chance of constantly writing to the profile will eventually corrupt it?  This is just a curiosity question, I only plan on saving at the end of game sessions.
VoiceAttack only writes saved values to the profile database either when VoiceAttack is shut down gracefully, or when a change to a profile is saved manually (from the "Edit a Profile" window), so the chances are very slim (of course that does mean that data can be lost until it has actually been written to the database).

Oh Shazzam!  I thought it did it at command execution.

So, if I change the value of a variable multiple times VA will only save the last value at (graceful) shutdown?  That was pretty smart.  Got hand it to that Gary guy.  :P

Technomancer

  • Jr. Member
  • **
  • Posts: 98
  • I have a bad feeling about this...
Re: "Save value to profile": more questions
« Reply #3 on: May 14, 2021, 01:09:58 PM »
I noticed that variables can have "Save value to profile" AND "Retrieve saved value" BOTH ticked at the same time.

How does that work?  I mean, I know there is some user work that needs to be done.  I'm not complaining about having to set up variables and populating them.  It's just that if you're creating a new variable and you tick both of those buttons, there's no way to set your value.  This is an obvious "no go" situation, I realize that. 

So, would you set up the values in a same-named variable in another command and this one would (and this is another question) save and/or retrieve the values???  (And here's the other question)  How would this variable know if it's supposed to save or retrieve?

One last question (for now :P), do you have to execute the command the variable is in to get it to save/retrieve?  That's what I've been doing, executing the command on closing and opening VA, but I was wondering is some flag is set and then VA scours the profile for those flags and performs the appropriate action (save or retrieve) on close or open.

Sorry for the long-winded post.




Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4786
  • RTFM
Re: "Save value to profile": questions
« Reply #4 on: May 14, 2021, 01:19:54 PM »
I noticed that variables can have "Save value to profile" AND "Retrieve saved value" BOTH ticked at the same time.

How does that work?
If both options are chosen, the value would theoretically be retrieved, then that same value that was just retrieved would be immediately saved to the profile again. There is no real point to doing so (assuming you're not performing operations on that value, which the "Set a Text Value" action, specifically, can).

So, would you set up the values in a same-named variable in another command and this one would (and this is another question) save and/or retrieve the values???  (And here's the other question)  How would this variable know if it's supposed to save or retrieve?
What? A variable can't "know" anything. It's a piece of data stored in memory, it doesn't do anything by itself.

Are you confusing the action that sets the variable (I.E. writes the data into memory) with the actual variable (I.E. the data stored in memory)?


Saving a value to a profile serializes a copy of that data and stores it in the profile database (technically it caches it in memory so it can be saved later, as mentioned, but the principle is the same). At that point, there is the actual variable that exists in memory, and copy of the data stored in that variable in the database.

Those are two separate entities; making a change to the variable without again saving it to the profile will result in different data existing in memory, and in the database.

E.G. if you set a text variable to "A", and save that to the profile, your variable will contain "A", and the copy stored in the database will contain "A".
If you then set that same text variable to "B", without saving it to the profile, you variable will contain "B", while the copy in the database will still contain "A".
If you retrieve the data from the database at that point, your variable will be set to "A", as that was the value stored in the database.


do you have to execute the command the variable is in to get it to save/retrieve?
Yes.

Technomancer

  • Jr. Member
  • **
  • Posts: 98
  • I have a bad feeling about this...
Re: "Save value to profile": questions
« Reply #5 on: May 14, 2021, 02:37:43 PM »

What? A variable can't "know" anything. It's a piece of data stored in memory, it doesn't do anything by itself.


I think you took that way too literally.  That question was in the context of having both "Save" and "Retrieve" ticked at the same time. 

I was wondering if when the command was executed, VA look to see if the variable was Not Set (at VA start-up or whatever other reason) and then do a "retrieve" only.  If the variable was populated, then it would perform a "save" only.  Again, this is all in the context of both radio buttons being ticked.  Things are, obviously, much simpler when only one is ticked. 

Hopefully, that explains why I asked how it would (metaphorically) "know". I was wondering if Gary had coded something to that effect to tell VA what to do in a given situation.

Thanx for the explanation.  As always, your promptness is extremely helpful, as usually I'm waiting for a response to move forward with whatever issue is in question.  :)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4786
  • RTFM
Re: "Save value to profile": more questions
« Reply #6 on: May 14, 2021, 03:14:38 PM »
I was wondering if when the command was executed, VA look to see if the variable was Not Set (at VA start-up or whatever other reason) and then do a "retrieve" only.  If the variable was populated, then it would perform a "save" only.  Again, this is all in the context of both radio buttons being ticked.  Things are, obviously, much simpler when only one is ticked. 

As mentioned, saved values are entirely separate from their actual variables. Even if a variable was assigned a value already, the value stored with the profile would still need to be retrieved regardless of that current value.

The value stored with the profile always overwrites the current value of the target variable, so the retrieval must always happen.
Saving that same value to the profile again is what's redundant.

However, given that (aside from in very specific cases with the "Set a Text Value" action) there is no logical reason for a user to choose both options, there is no reason to optimize that.
Even if there were, as mentioned, everything is cached in memory anyway, so the performance impact of any optimization would be infinitesimally small under normal circumstances.
« Last Edit: May 14, 2021, 05:27:33 PM by Pfeil »