Author Topic: Global Variable (Text) / How to set?  (Read 1564 times)

Starblue7

  • Full Member
  • ***
  • Posts: 131
Global Variable (Text) / How to set?
« on: April 22, 2023, 09:02:40 PM »
Hi,

On profile load I'm running a command that verifies if the MODE has already been set or not.
If it hasn't been set, then set it.
If there's already a mode set for the variable, then state what it is currently.

In testing, the JSG_MODE has not been set, but the below line in RED does not perform the following commands if true, and simply skips to the (ELSE) condition with telling me it hasn't been set.  (duh  haha).

Could anyone help with this?  Thanks muchos!

Code: [Select]

Begin Text Compare : [JSG_MODE] Has Not Been Set    <-----------ISSUE....
    Set text [JSG_MODE] to 'ONFOOT'
    Press Right Ctrl+NumPad 3 keys and hold for 0.05 seconds and release
    Say, 'ON FOOT MODE SET'  (and wait until it completes)
Else
    Say, 'Current Mode Is {TXT: JSG_MODE}'  (and wait until it completes)
End Condition


After the above, the command loads a different profile.  Commands from THIS profile are included in the newly loaded profile so that I can request a confirmation verbally what the current mode is (in case it's changed).


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: Global Variable (Text) / How to set?
« Reply #1 on: April 22, 2023, 09:04:41 PM »
You're having the "{TXT:}" token return the value of a variable named " JSG_MODE", not "JSG_MODE". Whitespace matters.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: Global Variable (Text) / How to set?
« Reply #2 on: April 22, 2023, 09:22:10 PM »
Thanks @Pfeil   

Need a debugging mode for sillies like me.  heh...

On the side, I wish there was a way to call up a command automatically in another profile from the one what loads initially.

Anything funky to deal with above?  I don't have access to the HCL voicepack profile in order to create something within it...


[EDIT]...

So what I'm currently doing is loading up my own custom profile first, kicking of the command automatically, and THEN loading up the HCL Voicepack profile.  I'd rather not do it this way.. if possible..

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: Global Variable (Text) / How to set?
« Reply #3 on: April 22, 2023, 09:32:36 PM »
There is currently no built-in method to execute a command when an included profile loads, if you can't edit the active profile.


A plugin can execute a command whenever a profile is loaded, if it subscribes to the "ProfileChanged" event.
One thing to note about that event is that it won't trigger when VoiceAttack is started initially (I.E. when the first profile is loaded), so you'd want to explicitly trigger the method you're using to execute the command from the "VA_Init1()" method.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: Global Variable (Text) / How to set?
« Reply #4 on: April 22, 2023, 09:40:27 PM »
Hmmm I'm willing to go down this rabbit hole a bit if you'd be my Mad Hatter.

If you could point me to any plugins already around so the wheel wouldn't need to be fully re-created?
Maybe something like this already exists that will either do or can be mod'ed without too much beheading?



Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: Global Variable (Text) / How to set?
« Reply #5 on: April 22, 2023, 09:47:33 PM »
Do you have experience with C# (technically VB.NET is also an option, however the documentation and the majority of the userbase uses C#)?

There is an example project included with VoiceAttack, (in the subfolder of the installation directory literally named "Plugin Samples").


Learning C# is outside of the scope of VoiceAttack itself, however; this would only be relevant if you are either already at least semi-fluent, or able to read and understand the documentation.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: Global Variable (Text) / How to set?
« Reply #6 on: April 22, 2023, 09:53:19 PM »
A long time ago I've done Pascal and learned some C++, but predominantly have worked with VBA.

I might be able to get the gist of things.

Though it's really a simple command on the high level:

On Profile X Load (due to profile switching event)
Pause Profile X
Run Command from Profile B
Resume Profile X

I mean, I suppose just hardcoding the names of the profiles could be done.
Though some interface to change that may serve a wider purpose.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: Global Variable (Text) / How to set?
« Reply #7 on: April 22, 2023, 11:26:02 PM »
If you do want to give it a go, here's how the plugin I slapped together years ago to do pretty much the same thing is set up:

Code: [Select]
private static dynamic VA;
public static void VA_Init1(dynamic vaProxy)
{
VA = vaProxy;
VA.ProfileChanged += new Action<Guid?, Guid?, string, string>(ProfileChanged);
ProfileChanged(null, null, "", "");//Profile changing/changed events don't run when VoiceAttack starts, so this makes sure commands run for the initial profiles's included profiles
}
As mentioned, you'd want to call the method explicitly for the initially loaded profile, which doesn't cause ProfileChanged to be triggered.

Code: [Select]
public static void VA_Invoke1(dynamic vaProxy)
{
VA.WriteToLog("The VoiceAttack Included Profile Initialization plugin does not need to be invoked, it works automatically when you switch profiles", "red");
}
This isn't necessary for the plugin to function, but I included it at the time just in case I were to release the plugin at some point.

Code: [Select]
public static void ProfileChanged(Guid? FromInternalID, Guid? ToInternalID, string FromName, string ToName)
{
foreach (string profileName in VA.ProfileNames())//There is no method for getting only loaded profiles, so all profiles in the database are checked; Those that aren't included into the active profile would not have their initialization command available, so those will not be executed needlessly
{
string initCommandName = profileName.Replace("[", "").Replace("]", "") + " Initialization";
if (VA.Command.Exists(initCommandName))
{
if (profileName != VA.Profile.Name())//Don't execute the initialization command for the active profile
{
VA.Command.Execute(initCommandName, true);//Execute and wait for command to complete
}
}
}
}
Instead of setting up the plugin so it only works in a very specific scenario, I designed it so no modification to profiles should be necessary after the initial creation of their initialization command.

So this plugin looks for a command with the name of the profile, followed by " Initialization", E.G. "My Profile Initialization", and executes it for any included and global profiles.

Requiring the profile name as part of the command name should ensure that all commands are uniquely named, with a name that's unlikely to be used unintentionally (I.E. the command is intended to be executed when the profile isn't the active profile), and so multiple profiles don't use the same command name (as only one command with the same name can exist).

I will note that I don't use version numbers in the names of my profiles. If your profiles do, you would of course need to rename the command to match.


Removing the brackets is necessary in case they're part of the profile name, as they will automatically be removed by VoiceAttack when they're used in a command name (as they're part of the dynamic command sections syntax).



All other plugin methods are either empty, or return basic properties like the name, description, or GUID (which should be unique; never reuse the GUID from the example project. You can use the "{GUID}" token to generate one if needed)

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: Global Variable (Text) / How to set?
« Reply #8 on: April 23, 2023, 06:10:18 AM »
Thanks for all the useful information.

I'm to take it that once I've got something workable, I need to compile into a .dll and then add to Voice Attack as a plugin?

I think without a full library from VA and what those functions do, I might still be a tad lost about this.
Will need to give big thought.

Thanks so much!

** Currently I'm on a mission to determine within VA what key presses and joystick buttons/actions are made in a polling routine in order to set modes automatically.  I think I need to use the CMDACTION, but unsure about how to deal with Modifier & Key, Double Taps, Double Tap & Hold.  Not sure that's possible or how. **

It should be its own thread if there's a specific question. Which I hope to avoid anything more than what I said above, but certainly welcome your direction.

Thanks!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: Global Variable (Text) / How to set?
« Reply #9 on: April 23, 2023, 06:22:33 AM »
I'm to take it that once I've got something workable, I need to compile into a .dll and then add to Voice Attack as a plugin?

I think without a full library from VA and what those functions do, I might still be a tad lost about this.
Yes, you need to compile to a .NET Framework (specifically; not a different variation of .NET) library. The example project would already have the appropriate settings configured.

Documentation on the proxy methods and plugins in general can be found in VoiceAttackHelp.pdf, as with other VoiceAttack features.


** Currently I'm on a mission to determine within VA what key presses and joystick buttons/actions are made in a polling routine in order to set modes automatically.  I think I need to use the CMDACTION, but unsure about how to deal with Modifier & Key, Double Taps, Double Tap & Hold.  Not sure that's possible or how. **
If you're polling, that implies a loop, so presumably you wouldn't then be triggering a command, so the "{CMDACTION}" token (or proxy method) would not apply.

If you're actually triggering commands, "{CMDACTION}" can certainly provide information on the triggering method, and there are tokens for double tap and hold invocation, however it is not currently possible to combine double tap, hold, and single tap triggers (only two of the three can apply to any input); you'd need to implement that yourself.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: Global Variable (Text) / How to set?
« Reply #10 on: April 23, 2023, 06:29:11 AM »
You're right, and I think I'm back around to STATE_KEYSTATE (Perhaps) to try to solve this.
Unless you have a silver bullet (likely you do and likely my question is maybe trivial).

 :D

EDIT:

Let me move the question to new thread and explain it better.  Perhaps you have some easy advice.