Author Topic: Wondering about Conditional (IF Statement) Blocks.  (Read 13752 times)

KuruptU4Fun

  • Guest
Wondering about Conditional (IF Statement) Blocks.
« on: June 16, 2016, 08:21:15 PM »
Can "Conditional Blocks" go thru your previous commands and determine if something is open "true" or closed "false" like a chat window within a game?

https://www.youtube.com/watch?v=Eui7v24izhE&feature=em-upload_owner

When I say CHAT ACTION --- Dance the script opens the chat window (F12), preps it with a "/" and then types the word "dance" hits ENTER and the avatar dances. But if the window is already open, it closes the window and the script doesn't start. What I need to do is get VA to "recognize" that the window is currently open, thus skipping hitting F12 and goes to hitting (/dance - enter) can this be done with conditional blocks?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #1 on: June 16, 2016, 08:48:16 PM »
It can't "read" the actual state of the game(you could write a plugin I suppose, but that's beyond "advanced"), so unless you're the one that opened the window in the first place, you can't really detect that.

What you can do to register when you(not the game itself) open or close the window, is to set a variable that keeps track of that:
Code: [Select]
Set Boolean [ChatWindowOpen] to True


You can have a command trigger when you press "F12" on your keyboard(using "When I press keys"), that sets the variable to true, and a corresponding command that triggers when you press "Enter", to set it to false(as it can then be assumed the chat is closed).

Then, you can check that variable using a condition, to see if the key needs to be pressed:
Code: [Select]
Begin Boolean Compare : [ChatWindowOpen] Equals False
    Press F12 key and hold for 0,06 seconds and release
End Condition

Note that by design, keypresses within commands don't trigger commands for those keys, so add:
Code: [Select]
Set Boolean [ChatWindowOpen] to False
To the end of your chat commands, so the next one will work correctly.


I have something similar for another application, which uses a "timer":

When "F12" is pressed
Code: [Select]
Set decimal [ChatKeyPressed] value to the converted value of {DATETICKS}

In the command that types into the chat
Code: [Select]
Begin Text Compare : [{EXP:({DATETICKS} - {DEC:ChatKeyPressed}) >= 300000000}] Equals '1'
    Press F12 key and hold for 0,06 seconds and release
    Set decimal [ChatKeyPressed] value to the converted value of {DATETICKS}
End Condition

When "Enter" is pressed
Code: [Select]
Set decimal [ChatKeyPressed] value to 0

This way, in case the chat has been closed through other means, the command will assume it needs to press the chat key again if 30 seconds have elapsed.


You can of course add logic for "ChatKeyPressed" to that as well.
« Last Edit: June 16, 2016, 08:54:59 PM by Pfeil »

KuruptU4Fun

  • Guest
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #2 on: June 19, 2016, 05:55:57 PM »
Thank you Pfiel for your suggestion!

Ok, this is what I've got, and it still doesn't seem to work:

I've set it as a Prefix- Suffix for the window and then the avatar action

Begin Boolean Compare: [Chat Window Open] Equals False   (this is when the window is closed)
Press F12 key hand hold for 0.3 seconds and release
Press ENTER key and hold for 0.3 seconds and release
Else if Boolean Compare: [Chat Window Open] Equals True
Press ENTER key and hold for 0.3 seconds and release
Exit Condition - Exit when condition met

Now it will open the chat window if it is closed and activate the "text line" if the prefix is said. It will not however complete the suffix line like

/dance ENTER to start the avatar motion

It will close the chat window after activating the "text line" if I say the command while the chat window is already open.

Where is the misstep in my coding?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #3 on: June 19, 2016, 06:33:46 PM »
I've set it as a Prefix- Suffix for the window and then the avatar action

Begin Boolean Compare: [Chat Window Open] Equals False   (this is when the window is closed)
Press F12 key hand hold for 0.3 seconds and release
Press ENTER key and hold for 0.3 seconds and release
Else if Boolean Compare: [Chat Window Open] Equals True
Press ENTER key and hold for 0.3 seconds and release
Exit Condition - Exit when condition met

Now it will open the chat window if it is closed and activate the "text line" if the prefix is said. It will not however complete the suffix line like

/dance ENTER to start the avatar motion

It will close the chat window after activating the "text line" if I say the command while the chat window is already open.

Where is the misstep in my coding?

If I understood correctly, the intended order of operations is this:
  • Press F12 to open the chat window
  • Type "/"
  • Type "dance"
  • Press Enter to send the text and close the chat window

If you're setting "Chat Window Open" with the prefix, the suffix should contain:
Code: [Select]
Begin Boolean Compare : [Chat Window Open] Equals False
    Press F12 key and hold for 0,06 seconds and release
End Condition
Press / key and hold for 0,06 seconds and release
Quick Input, 'dance'
Press Enter key and hold for 0,06 seconds and release

KuruptU4Fun

  • Guest
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #4 on: June 19, 2016, 07:53:24 PM »
With what I have as the prefix, it will only open the window and shut it if it is open. What am I missing?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #5 on: June 20, 2016, 10:27:50 AM »
...What do you have as the Prefix? You've not mentioned what the actual command is.

The contents of "When I say" for Prefix and Suffix, and the action lists for both as well, would help immensely.

There are many ways to do this, I can't guess which one you're trying to make work.

Nagual

  • Guest
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #6 on: June 20, 2016, 12:20:55 PM »
I'm looking at your code Pfeil and I understand, nice and compact. But what is this talk of prefixs and suffixes ?


Cheers,

KuruptU4Fun

  • Guest
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #7 on: June 20, 2016, 03:44:48 PM »
Prefix
Suffix

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #8 on: June 20, 2016, 10:06:42 PM »
The contents of "When I say" for Prefix and Suffix

Either way, I still have no idea what you're trying to do here. What you've told VoiceAttack to do is the following:

If ChatWindowOpen Equals False
  • Press F12 to open the chat window
  • Press Enter, which would close the chat window again, I assume
  • Press Enter again, without the chat window open
  • Press /
  • Press d
  • Press a
  • Press n
  • Press c
  • Press e
  • Press Enter one more time, still without the chat window open
  • Press F12, to open the chat window

If ChatWindowOpen Equals True
  • Press Enter, without the chat window open
  • Press Enter again, still without the chat window open
  • Press /
  • Press d
  • Press a
  • Press n
  • Press c
  • Press e
  • Press Enter one more time, still without the chat window open

If this is indeed correct:
If I understood correctly, the intended order of operations is this:
  • Press F12 to open the chat window
  • Type "/"
  • Type "dance"
  • Press Enter to send the text and close the chat window

You'd have to state whether the chat window is open or closed in the Prefix:

"[Open;] Chat action" (I.E. if the chat is already open you'd say "Open Chat action dance", this way you can formulate the command concisely)
Code: [Select]
Begin Text Compare : [{PREFIX}] Does Not Start With 'Open'
    Set Boolean [Chat Window Open] to False
Else
    Set Boolean [Chat Window Open] to True
End Condition

And the Suffix, as before:

"dance"
Code: [Select]
Begin Boolean Compare : [Chat Window Open] Equals False
    Press F12 key and hold for 0,06 seconds and release
End Condition
Press / key and hold for 0,06 seconds and release
Quick Input, 'dance'
Press Enter key and hold for 0,06 seconds and release


That's one way to do it, however, as pressing F12(or not) is only done at the start, from what I understand at least, you may prefer the following:

"[Open;] Chat action"
Code: [Select]
Begin Text Compare : [{PREFIX}] Does Not Start With 'Open'
    Press F12 key and hold for 0,06 seconds and release
End Condition
Press / key and hold for 0,06 seconds and release

"dance"
Code: [Select]
Quick Input, 'dance'
Press Enter key and hold for 0,06 seconds and release

This does away with the variable, and repeats the fewest actions for multiple Suffixes.


Now, personally, I tend to underutilize Prefixes and Suffixes, so I would use:

"[Open;] Chat action dance"
Code: [Select]
Begin Text Compare : [{CMD}] Does Not Start With 'Open'
    Press F12 key and hold for 0,06 seconds and release
End Condition
Press / key and hold for 0,06 seconds and release
Quick Input, 'dance'
Press Enter key and hold for 0,06 seconds and release

I've looked into it, and it is possible Prefixes and Suffixes pass a similar structure to the speech engine(Gary?), rather than complete phrases(which is apparently possible according to SAPI documentation), but I don't know what the performance implications of that would be.

The main reason to use a Prefix/Suffix structure is to save on editing multiple commands when you want to change something. E.G. if the chat key changes from F12 to something else, you only have to edit one Prefix instead of all the commands using that key. You should decide which method seems more sensible to you.

Nagual

  • Guest
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #9 on: June 21, 2016, 04:44:56 AM »
Ooo. Now that is useful indeed. I was wanting to know about this months ago, but didn't know the correct terminology to ask. Throw in some variables and you can have a slightly 'smarter' style of command structure.

KuruptU4Fun

  • Guest
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #10 on: June 21, 2016, 04:56:20 AM »
Ok, that's where the miscommunication is happening, my apologies, I should have been more clear:

Pressing enter after F12 opens the text window (where you can type), the entire chat window will not close again until your hit F12 a second time.

So Boolean ChatWindowOpen equals false would simply need to determine the state that the chat window is currently closed then command the following:

Chat Action / Prefix
False: Press F12 to open the chat window (opens the window) And ENTER to open the text window.
True: Press ENTER to open the text window.

Dance / Suffix

/dance

Press ENTER to activate the action and close the text window.
Press F12 to close out the window.

Odds are I'm not going to be using the chat window much, so it will remain closed most of the time. But would like to have VA know when the Chat window happens to be open. and will then skip the F12 to open chat window line.

Again I thank you for your assistance!
« Last Edit: June 21, 2016, 04:59:46 AM by KuruptU4Fun »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #11 on: June 21, 2016, 08:31:02 AM »
would like to have VA know when the Chat window happens to be open.
Without communicating with the game directly, it can't know.
That's why you yourself have to look at the screen, and speak the appropriate command; "Chat action dance" if the chat is not already open, or "Open Chat action dance" when the chat is open.

"[Open;] Chat action"
Code: [Select]
Begin Text Compare : [{PREFIX}] Does Not Start With 'Open'
    Press F12 key and hold for 0,06 seconds and release
End Condition
Press Enter key and hold for 0,06 seconds and release
Press / key and hold for 0,06 seconds and release

"dance"
Code: [Select]
Quick Input, 'dance'
Press Enter key and hold for 0,06 seconds and release


I don't own the game you're trying to make this work with,so I can't test it myself, but from what you've said the above should work.

KuruptU4Fun

  • Guest
Re: Wondering about Conditional (IF Statement) Blocks.
« Reply #12 on: June 21, 2016, 04:46:53 PM »
Thanks very much Pfeil, I appreciate your attention and assistance!