Author Topic: How do I create a random output?  (Read 1120 times)

kamiofice

  • Newbie
  • *
  • Posts: 4
How do I create a random output?
« on: July 12, 2022, 09:57:15 PM »
Okay, so maybe this has been answered and maybe it hasn't. I have been using Voice Attack for years after discovering it for Elite Dangerous, and now it's slowly expanding into a much larger project on my computer. I use it in basically every game and even for work to help manage frequently typed phrases.

I am looking to update my phrases a little bit. What I would like to do is create a command so that, when spoken/triggered, it provides a random output. So if I were to say "Rock, paper, scissors, shoot!" it gives me either "Rock or Paper or Scissors." I've been fiddling with command lines for two days, but I admit I am not a programmer. Any help that someone would be willing to provide to get me rolling would be very much appreciated.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do I create a random output?
« Reply #1 on: July 13, 2022, 02:28:56 AM »
There are a number of ways to randomize certain aspects of commands, E.G.:

Doing so within the "Say Something with Text-To-Speech" action is detailed in the official documentation (press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer, which contains information on VoiceAttack's features), so I'll assume you're aware of that already.

The "{TXTRANDOM:}" token can be used with the Quick Input action, if you're looking to type (partially) randomized text

And, of course, the "Play a Random Sound" action is intended to do exactly what its name suggests.


If you want to randomize which action, or set of actions, is executed, the simplest way may be to use the "A random value" option of the "Set an Integer Value" action, combined with a set of conditions.

E.G.
Code: [Select]
Set integer [~randomValue] value as random from 1 to 3
Begin Integer Compare : [~randomValue] Equals 1
    Press A key and hold for 0.01 seconds and release
Else If Integer Compare : [~randomValue] Equals 2
    Press B key and hold for 0.01 seconds and release
Else
    Press C key and hold for 0.01 seconds and release
End Condition


These topics may also be of use, in addition to the official documentation, if you'd like to understand the features utilized in the example:
Control flow (If, Else, ElseIf, Loop, Jump) basics
Variables and tokens summed up

kamiofice

  • Newbie
  • *
  • Posts: 4
Re: How do I create a random output?
« Reply #2 on: July 14, 2022, 07:57:26 PM »
Okay, so to my eye that is how I currently have the macro set up. I'll include a photo attachment of what I have going in VA. I can get these commands to execute when I just declare "Rock" or "Paper" or "Scissors" but when I give the full command it doesn't seem to do anything.


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do I create a random output?
« Reply #3 on: July 14, 2022, 07:59:21 PM »
Have you read the documentation on variables?

You're setting one variable, then checking the value of three different variables, none of which are the one you've set.

kamiofice

  • Newbie
  • *
  • Posts: 4
Re: How do I create a random output?
« Reply #4 on: July 14, 2022, 08:28:57 PM »
I have read it, I am not sure I processed it in a usable way.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: How do I create a random output?
« Reply #5 on: July 14, 2022, 09:03:29 PM »
The core principle you need to understand in this case is that a variable is a place you reserve in memory, in which you can store information. A place which is identified by a name.

So if you store a number into that reserved place, and you want to look at the number later on, logically you'll want to look in the same place.

Imagine these places in memory pages of a notebook. You've written something on one page, but then when you're trying to read what you've written down, you're looking at three completely different pages.


What you need to do to get this command working, is to look in the same place you put the information.

kamiofice

  • Newbie
  • *
  • Posts: 4
Re: How do I create a random output?
« Reply #6 on: July 17, 2022, 10:00:04 AM »
Okay, just giving an update to say that I finally got it working. In my dense head, I was thinking that me naming a variable was just me giving it a name to the part. I had a second source point out to me that the naming area was how the variables were tied together, and that in my naming things with different parts (a/b/c/d) I was making four different parts that were entirely unrelated. I do understand now that was what you were telling me with your first response to me. After I renamed things to A/A/A/A it worked perfectly.