Author Topic: Conditional block advice, please  (Read 3040 times)

jcdick1

  • Jr. Member
  • **
  • Posts: 59
Conditional block advice, please
« on: December 13, 2016, 10:33:03 AM »
I'm trying to do what in my mind would be an if/or/else block, instead of if/else if/else block for ED.  The idea is for VA to compare the various components of my ED ship (as fed by EDDi) and let me know which ones are less than 100%.  I started a whole chain of if/else with jumps, but my brain kept telling me I should ask the professionals if there's a more efficient way to do this.

Set decimal [Hull_health] value to the converted value of {DEC:Ship health}
Set decimal [Powerplant_health] value to the converted value of {DEC:Ship power plant health}
Set decimal [Thrusters_health] value to the converted value of {DEC:Ship thrusters health}
Set decimal [Frameshift_health] value to the converted value of {DEC:Ship frame shift drive health}
Set decimal [Life_support_health] value to the converted value of {DEC:Ship life support health}
Set decimal [Distributor_health] value to the converted value of {DEC:Ship power distributor health}
Set decimal [Sensors_health] value to the converted value of {DEC:Ship sensors health}
Say, 'Running preflight checks, [captain' or 'sir' or ']'
Set decimal [parts_count] value to 0 (round to 0 decimal places)
Pause 2.2 seconds
Begin Decimal Compare : [Hull_health] Is Less Than 100.00000
    Say, 'The hull,'
    Set decimal [parts_count] to [parts_count] plus 1.00000 (round to 0 decimal places)
Else
    Jump to Marker: powerplant_check
End Condition
Marker: powerplant_check
Begin Decimal Compare : [Powerplant_health] Is Less Than 100.00000
    Say, 'The powerplant,'
    Set decimal [parts_count] to [parts_count] plus 1.00000 (round to 0 decimal places)
Else
    Jump to Marker: Thruster_check
End Condition
Marker: Thruster_check
Begin Decimal Compare : [Thrusters_health] Is Less Than 100.00000
    Say, 'the thrusters,'
    Set decimal [parts_count] to [parts_count] plus 1.00000 (round to 0 decimal places)
Else
    Jump to Marker: frameshift_check
End Condition
Marker: frameshift_check
...

The [parts_count] is to have proper grammar at the end, so if [parts_count]=1 say "is" but if its >1 say "are".

If anyone can advise a better way to do this, I'd appreciate it.

Thanks!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Conditional block advice, please
« Reply #1 on: December 13, 2016, 10:57:43 AM »
Currently there is no "OR" action, but you can use the "{EXP:}" token to achieve the same functionality:
Code: [Select]
Begin Text Compare : [{EXP: 1 > 2 OR 3 < 4}] Equals '1'
End Condition

However, I'm not sure I understand how you'd use it, as you still require parts_count to go up and the TTS to speak the part name.


As an aside, unless you need fractions, decimal is overkill for a simple counter. If your value stays between    32767 and –32768 a "Small Integer (Condition) Value" will suffice. This also has the advantage of allowing "Increment value" rather than having to add 1.00000 every time.

You also have a bunch of jumps that, from what I can see, don't affect the flow of the command.
Code: [Select]
Begin Decimal Compare : [Powerplant_health] Is Less Than 100.00000
    Say, 'The powerplant,'
    Set decimal [parts_count] to [parts_count] plus 1.00000 (round to 0 decimal places)
Else
    Jump to Marker: Thruster_check
End Condition
Marker: Thruster_check
A command is executed from top to bottom, so when the "Powerplant_health"condition ends the "Thruster_check" condition will run, and so forth, unless you use the "When this block is reach, exit command" options for the End block(Which the text suggests you're not).

Unless you use those markers later on in a portion of the command you've omitted, you can leave them out altogether:
Code: [Select]
Begin Decimal Compare : [Hull_health] Is Less Than 100.00000
    Say, 'The hull,'
    Set decimal [parts_count] to [parts_count] plus 1.00000 (round to 0 decimal places)
End Condition
Begin Decimal Compare : [Powerplant_health] Is Less Than 100.00000
    Say, 'The powerplant,'
    Set decimal [parts_count] to [parts_count] plus 1.00000 (round to 0 decimal places)
End Condition
Begin Decimal Compare : [Thrusters_health] Is Less Than 100.00000
    Say, 'the thrusters,'
    Set decimal [parts_count] to [parts_count] plus 1.00000 (round to 0 decimal places)
End Condition

jcdick1

  • Jr. Member
  • **
  • Posts: 59
Re: Conditional block advice, please
« Reply #2 on: December 13, 2016, 11:19:54 AM »
I just assumed an "if" required an "else".  Thanks for that clarification!

So this is probably the best way to go about this:

Code: [Select]
Set decimal [Hull_health] value to the converted value of {DEC:Ship health}
Set decimal [Powerplant_health] value to the converted value of {DEC:Ship power plant health}
Set decimal [Thrusters_health] value to the converted value of {DEC:Ship thrusters health}
Set decimal [Frameshift_health] value to the converted value of {DEC:Ship frame shift drive health}
Set decimal [Life_support_health] value to the converted value of {DEC:Ship life support health}
Set decimal [Distributor_health] value to the converted value of {DEC:Ship power distributor health}
Set decimal [Sensors_health] value to the converted value of {DEC:Ship sensors health}
Say, 'Running preflight checks, [captain' or 'sir' or ']'
Set small int (condition) [parts_count] value to 0
Pause 2.2 seconds
Begin Decimal Compare : [Hull_health] Is Less Than 100.00000
    Say, 'The hull,'
    Set small int (condition) [parts_count] value as incremented by 1
End Condition
Begin Decimal Compare : [Powerplant_health] Is Less Than 100.00000
    Say, 'The powerplant,'
    Set small int (condition) [parts_count] value as incremented by 1
End Condition
Begin Decimal Compare : [Thrusters_health] Is Less Than 100.00000
    Say, 'the thrusters,'
    Set small int (condition) [parts_count] value as incremented by 1
End Condition
Begin Decimal Compare : [Frameshift_health] Is Less Than 100.00000
    Say, 'the frameshift drive,'
    Set small int (condition) [parts_count] value as incremented by 1
End Condition
Begin Decimal Compare : [Life_support_health] Is Less Than 100.00000
    Say, 'life support,'
    Set small int (condition) [parts_count] value as incremented by 1
End Condition
Begin Decimal Compare : [Distributor_health] Is Less Than 100.00000
    Say, 'the power distributor,'
    Set small int (condition) [parts_count] value as incremented by 1
End Condition
Begin Decimal Compare : [Sensors_health] Is Less Than 100.00000
    Say, 'the sensors,'
    Set small int (condition) [parts_count] value as incremented by 1
End Condition
Marker: final_component_check
Begin Small Integer Compare : [parts_count] Equals 1
    Say, 'is [needing repair' or 'less than optimal' or 'not at 100%], [captain' or 'sir' or '].  That is only one component.'
Else If Small Integer Compare : [parts_count] Is Greater Than 1
    Say, 'are [less than optimal' or 'needing repair' or 'not 100%], [captain' or 'sir' or '].  That is {DEC:parts_count} components.'
Else If Small Integer Compare : [parts_count] Equals 0
    Say, 'All ship components are in optimal condition.'
End Condition

Thanks so much for the help!

ralf44

  • Newbie
  • *
  • Posts: 41
Re: Conditional block advice, please
« Reply #3 on: December 13, 2016, 12:03:03 PM »
This is a great idea. I have some suggestions...

Even if these numbers are coming in as decimals, you don't need that level of precision. I would rather have my AI say "twenty percent" than "20 point 5 5 9 percent!" So in your first lines I would set INTs for Hull_health etc.

The logic flow looks to me like you are going to get output that sounds like, "The hull, the powerplant, the frameshift drive..." first - without the word "and" anywhere - and then one overall summary.

Wouldn't it be more useful to get the condition of each damaged system as they are named? "The sensors are at {TXTNUM:Sensors_health} percent," etc?

Then at the end all you'd need to check for is if parts_count Equals 0 and in that case Say, "All systems are in optimal condition," as the script would have said nothing else in that case.

This also eliminates the grammatical problems like needing an extra case for only one system being damaged and missing the word "and" before the last item in a list.

Whichever way you'd like the results announced, you don't need the jump marker for final_component_check now that you've got rid of the Else statements.

I am not sure but it looks like you have some syntax errors with single quote marks where you are intending varied responses. The syntax for random responses is given in the Voice Attack manual as using semicolons rather than the word "or." To have it say either "Captain," "Sir," or nothing you can just type [Captain;Sir;] and this works both in voice command inputs and text-to-speech responses.

Hope this helps, Captain/Sir ;)