Author Topic: Plugin or VA variables  (Read 6912 times)

PsiQss

  • Guest
Plugin or VA variables
« on: January 30, 2017, 01:39:08 PM »
This is my first post here, so hello everyone! :)

I'll be starting to build my new profile soon and I'm in the process of planning everything out. An here comes the technical question, regarding resource efficiency and such. I'm going to have quite a lot of variables, mostly integers, stored in XML files. Is it generally a better idea to pass those variables to VA or keep them within plugin and pass to VA when needed? Or should I just scratch the idea and just keep them in VA variables that are saved/retrieved in profile?

They will potentially have to be modified with each executed command, not all the variables at once but pretty much every command will alter one or few of those variables. What is the best approach to minimize the memory/CPU load. Or is there no difference at all?

Thanks in advance!

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: Plugin or VA variables
« Reply #1 on: February 01, 2017, 07:10:27 AM »
First of all, if you don't have problems dealing with plugins, I would keep your values in XML/<whatever convenient> external files, which are more flexible than using the integrated profile storage, easier to manipulate outside VA and to share between multiple profiles

Now, unless you have thousands and thousands of them, memory is usually not a factor, so one approach to reduce overhead when actually using the profile, which is when you want VA to be as responsive as possible, is simply to load all the variable from the XML to VA at profile load (you can create a single function in your plugin that does this at once), update them in memory as you go and store them back as XML when finished.

You might even code a simple check inside the plugin that auto-saves all the variables at fixed intervals
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin

PsiQss

  • Guest
Re: Plugin or VA variables
« Reply #2 on: February 01, 2017, 09:56:05 AM »
Well I'm not going to have thousands of them, but I'm kind of a perfectionist type :P And I want to get good programming habits. Anyways, I'm going to store those in XML, to be able to change into the new release of profile without affecting those variables (I don't think you can easily pass profile-stored variables to another one). The idea is, those variables will affect a "pool" of response phrases used by the AI, so I think I can either read those from XML to VA directly, then a plugin will access the VA variables, do the math and output to the VA responses string, or read from XML to plugin, do the math and just pass the variables to VA when needed.

I guess my real question is, is there really any difference? If not from performace perspective then from code simplicity, maybe? Thinking of it, the change in the available responses does not have to be immediately accessible, it's just something to have effect in the long run. With that in mind, it might be better to store them within VA while running, for the sake of responsiveness (those precious milliseconds!).

Another, although related, question. Because you seem to be really experienced with VA plugins ;) In general, if something is doable within VA itself, should I do it with VA commands or pass it to the profile and let VA focus on executing commands? Something tells me that this is dependent on many other factors, but what is.. well, a generally good practice?

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: Plugin or VA variables
« Reply #3 on: February 01, 2017, 03:52:25 PM »
The idea is, those variables will affect a "pool" of response phrases used by the AI, so I think I can either read those from XML to VA directly, then a plugin will access the VA variables, do the math and output to the VA responses string, or read from XML to plugin, do the math and just pass the variables to VA when needed.

I guess my real question is, is there really any difference? If not from performace perspective then from code simplicity, maybe?

keeping the bulk of variable only within the plugin code and just pushing back to VA those needed might be slighly more efficient; on the other hand, it will also make your profile code a bit more obscure, since you can't tell at a glance what each command do (you'll see a bunch of generic 'execute plugin' actions), and maybe harder to mantain

Another, although related, question. Because you seem to be really experienced with VA plugins ;) In general, if something is doable within VA itself, should I do it with VA commands or pass it to the profile and let VA focus on executing commands? Something tells me that this is dependent on many other factors, but what is.. well, a generally good practice?
I think as long as the logic is not too complex, doing it with VA commands is more straightforward; like above, I'm mainly thinking about further manteinance and reusability of a profile in the future.

If/when you start noticing that you are doing some awkward stuff within the profile, like commands set as loops to refresh data around, too much token manipulation to combine bits and pieces of information from variables or stuff like that, that's when you might want to consider shifting the logic inside a plugin (or the new inline functions), which will grant you a more powerfull, and fast when compiled, programming language

Also, anything related to accessing resources from anywhere else, be that external files or web pages or whatever, even if it can be done to some extent directly in VA, I personally find it better put inside plugins code  regardless, where you have much more control and chance of optimize
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin

PsiQss

  • Guest
Re: Plugin or VA variables
« Reply #4 on: February 02, 2017, 03:41:21 AM »
Thank you so much!

That did indeed clarify the stuff about the things :)