Author Topic: How do I input a number from the user?  (Read 11525 times)

netkingcol

  • Newbie
  • *
  • Posts: 28
How do I input a number from the user?
« on: May 25, 2016, 02:57:43 AM »
I want to capture a number from the user which I will save in the profile as a small integer. My first attempt uses dictation, as the following image shows:



The Set small int command attempts to convert the contents of the dictation buffer:



Sometimes this works and sometimes it doesn't:



So my question is: is there another way of reliably allowing the user to input a number to the profile? A method that uses keystrokes would be ideal, but I don't see that ability anywhere.

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: How do I input a number from the user?
« Reply #1 on: May 25, 2016, 08:23:15 AM »
So my question is: is there another way of reliably allowing the user to input a number to the profile? A method that uses keystrokes would be ideal, but I don't see that ability anywhere.
A bit tricky, but this should work:

Create in your profile a (silent) command for each digit, set the corresponding numeric key as a shortcut, and use these actions

Code: [Select]
(when i press 1)
Begin Integer Compare : [Quantity] Has Been Set
    Set integer [Quantity] value to the converted value of {EXP: {INT:Quantity} * 10 + 1}
End Condition

(when i press 2)
Begin Integer Compare : [Quantity] Has Been Set
    Set integer [Quantity] value to the converted value of {EXP: {INT:Quantity} * 10 + 2}
End Condition

(when i press 3)
Begin Integer Compare : [Quantity] Has Been Set
    Set integer [Quantity] value to the converted value of {EXP: {INT:Quantity} * 10 + 3}
End Condition

and so on for every number... don't forget to UNCHECK the option 'do not allow key to be passed through', otherwise the user will lose the ability to use the number keys for actual game commands

When you want to request for the user input, use
Code: [Select]
...
Say, 'How many elements?'
Set integer [Quantity] value to 0
Pause 3 seconds
Begin Integer Compare : [Quantity] Is Greater Than 0
    Say, 'Ok, Quantity set to {INT:Quantity}'
End Condition
Set integer [Quantity] value to [Not Set]
...
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin

netkingcol

  • Newbie
  • *
  • Posts: 28
Re: How do I input a number from the user?
« Reply #2 on: May 25, 2016, 08:58:38 AM »
Antaniserse,

Thanks; I see how that code works, but if the numeric keys are bound to game actions and the key presses are passed through, won't there be all those side-effects of the user typing a number?

Rhaedas

  • Jr. Member
  • **
  • Posts: 72
Re: How do I input a number from the user?
« Reply #3 on: May 25, 2016, 09:45:14 AM »
I would think based on your first posted code that you wouldn't want them passed through, especially if they are also tied to other commands. If you're only asking for input when running the first command, then the number keys are going to be in a different mode in and out of that command. Normally they'd do nothing or the other ones assigned to them, but when that command is called, they are strictly for numerical input and nothing else. The input command basically locks them out until it gets the final input.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4757
  • RTFM
Re: How do I input a number from the user?
« Reply #4 on: May 25, 2016, 09:50:19 AM »
I see how that code works, but if the numeric keys are bound to game actions and the key presses are passed through, won't there be all those side-effects of the user typing a number?

It would, but you can work around that:

Code: [Select]
(when i press 1)
Begin Integer Compare : [Quantity] Has Been Set
    Set integer [Quantity] value to the converted value of {EXP: {INT:Quantity} * 10 + 1}
Else
    Press 1 key and hold for 0,06 seconds and release
End Condition

And set the keypress to "Do not allow key to be passed through".

Alternatively, to allow long press/holding keys:
Code: [Select]
(when i press 1)
Begin Integer Compare : [Quantity] Has Been Set
    Set integer [Quantity] value to the converted value of {EXP: {INT:Quantity} * 10 + 1}
Else
    Press down 1 key
    Start Loop While : [{STATE_KEYSTATE:1}] Equals '1'
    End Loop
    Release 1 key
End Condition
« Last Edit: May 25, 2016, 10:15:56 AM by Pfeil »

netkingcol

  • Newbie
  • *
  • Posts: 28
Re: How do I input a number from the user?
« Reply #5 on: May 26, 2016, 02:50:31 AM »
Thank you for showing me how to capture a number through keypresses. I looked at Bunny's post in the Profile Upload section: http://voiceattack.com/SMF/index.php?topic=51.0 and realised I could return to spoken numbers. I've adapted that technique to my profile requirements and thought I would share the results.

I have a Full Command which listens for spoken numbers between zero and 300 (the maximum size of the Materials store in Elite Dangerous Horizons). When a number in that range is spoken, the value is stored in a variable. For some reason, numbers zero to nine are not converted to digits, so I need the following action sequence:

Code: [Select]
(when I say, 'zero;one;two;three;four;five;six;seven;eight;nine;[10..300]')
Begin Text Compare : [{CMD}] Equals 'zero'
    Set small int (condition) [EDSIQuantity] value to 0
Else If Text Compare : [{CMD}] Equals 'one'
    Set small int (condition) [EDSIQuantity] value to 1
Else If Text Compare : [{CMD}] Equals 'two'
    Set small int (condition) [EDSIQuantity] value to 2
.
.
.
Else If Text Compare : [{CMD}] Equals 'nine'
    Set small int (condition) [EDSIQuantity] value to 9
Else
    Set small int (condition) [EDSIQuantity] value to the converted value of {CMD}
End Condition

I can now use the following dialogue to capture the quantity of a given material, in this case Arsenic:

Code: [Select]
    Set small int (condition) [EDSIQuantity] value to [Not Set]
    Say, 'How many units of {TXT:EDSIElement} do you have in stock?'  (and wait until it completes)
    Start Loop While [EDSIQuantity] Has Not Been Set
        Pause 4 seconds
        Begin Small Integer Compare : [EDSIQuantity] Has Not Been Set
            Say, 'I didn't get that. Please say again.'  (and wait until it completes)
        End Condition
    End Loop
    Set small int (condition) [EDSI_Arsenic_Qty] value to the value of [EDSIQuantity] (save value to profile)
    Say, 'Quantity of {TXT:EDSIElement}  set to {SMALL:EDSI_Arsenic_Qty}'  (and wait until it completes)

In that 4 second pause I can speak a number. If what I say isn't recognised as a number, the dialogue loops until a value is found.

netkingcol

  • Newbie
  • *
  • Posts: 28
Re: How do I input a number from the user?
« Reply #6 on: June 03, 2016, 06:44:12 AM »
VoiceAttack doesn't seem to recognise numbers very well when they are defined as full commands. However, when they are defined in the context of a prefix-suffix group, the recognition is much more reliable. I've replaced my previous code with this:

When I say 'Stock' as a prefix

Code: [Select]
Set small int (condition) [EDSIQuantity] value to [Not Set]

followed by: 'zero;one;two;three;four;five;six;seven;eight;nine;[10..99]' as a suffix

Code: [Select]
Begin Text Compare : [{SUFFIX}] Equals 'zero'
    Set small int (condition) [EDSIQuantity] value to 0
Else If Text Compare : [{SUFFIX}] Equals 'one'
    Set small int (condition) [EDSIQuantity] value to 1
Else If Text Compare : [{SUFFIX}] Equals 'two'
    Set small int (condition) [EDSIQuantity] value to 2
Else If Text Compare : [{SUFFIX}] Equals 'three'
    Set small int (condition) [EDSIQuantity] value to 3
Else If Text Compare : [{SUFFIX}] Equals 'four'
    Set small int (condition) [EDSIQuantity] value to 4
Else If Text Compare : [{SUFFIX}] Equals 'five'
    Set small int (condition) [EDSIQuantity] value to 5
Else If Text Compare : [{SUFFIX}] Equals 'six'
    Set small int (condition) [EDSIQuantity] value to 6
Else If Text Compare : [{SUFFIX}] Equals 'seven'
    Set small int (condition) [EDSIQuantity] value to 7
Else If Text Compare : [{SUFFIX}] Equals 'eight'
    Set small int (condition) [EDSIQuantity] value to 8
Else If Text Compare : [{SUFFIX}] Equals 'nine'
    Set small int (condition) [EDSIQuantity] value to 9
Else
    Set small int (condition) [EDSIQuantity] value to the converted value of {SUFFIX}
End Condition
Say, '{SMALL:EDSIQuantity}'

When I say 'Stock 26' for example, and follow this with: 'Set stock of Vanadium' then I find I can reliably manage stock levels in Elite Dangerous. It's a bit clumsy, but much less frustrating. I posted about this in the Frontier Developments forum, offering up version 1.0 of my profile: https://forums.frontier.co.uk/showthread.php?t=259538