Author Topic: Code review please for a toggle setting that's tracked.  (Read 1324 times)

Forlarren

  • Guest
Code review please for a toggle setting that's tracked.
« on: October 17, 2018, 07:05:11 PM »
How do I clean up my working but messy scripts?

I posted this on reddit but I'm also looking for help here.

https://old.reddit.com/r/X3TC/comments/9p0wmq/seta_how_do_you_say_that/


I just started playing X3AP. And there is a setting to accelerate time with the "j" key.

But I wanted a natural language interface synchronized state tracking between the game and VA.

https://drive.google.com/open?id=1_xrnBVYkW_V8FtoObho8SfCUajRzzoE8

There is voice feedback and log reports for debugging, you don't need the game to play it, just notepad so you can see when the "j" key is being pressed or not.

I'd like to know where I can improve the speed/efficiency of the scripts. And have I done the spoken commands correctly?

Everything technically works as I wanted it to, so the basic logic is sound, but I'm sure there are better ways.

Hopefully this will lead to a full X3AP Profile.

Thank you for your time.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Code review please for a toggle setting that's tracked.
« Reply #1 on: October 17, 2018, 10:18:01 PM »
One change to make is to use "Else If" and "Else" instead of individual conditional blocks for each check.

E.G.
Code: [Select]
Begin Boolean Compare : [SETABool] Equals True
    Write [Green] 'SETA On' to log
    Say, 'Time compression, is set to on.'
End Condition - Exit when condition met
Begin Boolean Compare : [SETABool] Equals False
    Write [Red] 'SETA Off' to log
    Say, 'Time compression, is set to off.'
End Condition - Exit when condition met
Begin Boolean Compare : [SETABool] Has Not Been Set
    Write [Yellow] 'SETA Not Set' to log
    Say, 'Time compression, is not set.'
End Condition
Becomes
Code: [Select]
Begin Boolean Compare : [SETABool] Equals True
    Write [Green] 'SETA On' to log
    Say, 'Time compression, is set to on.'
Else If Boolean Compare : [SETABool] Equals False
    Write [Red] 'SETA Off' to log
    Say, 'Time compression, is set to off.'
Else
    Write [Yellow] 'SETA Not Set' to log
    Say, 'Time compression, is not set.'
End Condition
As a boolean value can only have three states, you can check for two of those states, and by eliminating those possibilities, it can only be the remaining state.

This is more efficient as you eliminate a check, and VoiceAttack has to process fewer actions for the same end result. It's also easier to read(once you're familiar with the concept), as it clearly shows which actions belong to the same conditional chain.


You also have a few commands where the last action is
Code: [Select]
End Condition - Exit when condition met

This is unnecessary, as a command will stop when the end of the action list is reached(provided no "Repeating" options are used, which are off by default).


It may be worth having a look at this topic, which attempts to explain some of these concepts.