Author Topic: Check ship's components status  (Read 110 times)

Hillgue

  • Newbie
  • *
  • Posts: 3
Check ship's components status
« on: September 16, 2018, 04:24:41 am »
Hi all,

As there is'nt API in Star citizen, I would like to set a kind of system check to define lights are off and doors closed by default.

Here is my actual light toggle command (doors command is average the same)

Code: [Select]
Begin Small Integer Compare : [light] Has Not Been Set
    Set small int (condition) [light] value to 0
End Condition
Begin Small Integer Compare : [light] Equals 0   
    Execute command, 'Toggle Lights' (by name) (and wait until it completes)
    Set small int (condition) [light] value to 1
    Play random sound (2 items) (and wait until it completes)
End Condition - Exit when condition met
Begin Small Integer Compare : [light] Equals 1
    Play random sound (2 items)
End Condition - Exit when condition met

If [light] value to 0, then the command turns lights on and says "lights on".
If [light] value to 1, then the command does nothing and says "lights are already on".

This works nice if i just entered in the ship, but if i left and lights are already on, or i died, then the command is stuck on "lights are already on".

What I would like to do is to create a new command to reset lights and doors states.
And more crazy, editing this to command when "lights already on" then VA ask me if i want to correct.

Tell me if something is not clear :p
« Last Edit: September 17, 2018, 03:49:52 am by Hillgue »

Hillgue

  • Newbie
  • *
  • Posts: 3
Re: Check ship's components status
« Reply #1 on: September 16, 2018, 03:33:37 pm »
Okay just fixed it.

Code: [Select]
Begin Small Integer Compare : [light] Has Not Been Set
    Set small int (condition) [light] value to 0
End Condition
Begin Small Integer Compare : [light] Equals 0   
    Execute command, 'Toggle Lights' (by name) (and wait until it completes)
    Set small int (condition) [light] value to 1
    Play random sound (2 items) (and wait until it completes)
End Condition - Exit when condition met
Begin Small Integer Compare : [light] Equals 1
    Play random sound (2 items)
    Pause 1,5 seconds
    Set small int (condition) [confirmValue] value to [Not Set]
    Set small int (condition) [loopCounter] value to 1
    Say, 'Shall I fix it ?'  (and wait until it completes)
    Write [Blue] 'Waiting for reply...' to log
    Marker: loopStartMarker
End Condition
Begin Small Integer Compare : [loopCounter] Is Less Than Or Equals 40
    Begin Small Integer Compare : [confirmValue] Has Been Set
        Jump to Marker: loopBreakMarker
    End Condition
    Pause 0,25 seconds
    Set small int (condition) [loopCounter] value as incremented by 1
    Jump to Marker: loopStartMarker
End Condition
Marker: loopBreakMarker
Begin Small Integer Compare : [confirmValue] Has Not Been Set
    Say, 'Take your time idiot !'
Else
    Begin Small Integer Compare : [confirmValue] Equals 1
        Execute command, 'Toggle Lights' (by name) (and wait until it completes)
        Say, 'Light state fixed.'
        Set small int (condition) [light] value to 0
    Else
        Say, 'Canceled.'
    End Condition
End Condition
« Last Edit: September 17, 2018, 05:01:21 am by Hillgue »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1570
  • RTFM
Re: Check ship's components status
« Reply #2 on: September 16, 2018, 07:01:42 pm »
Good that you found a solution.

If I may, I'd like to offer some suggestions; This should be functionally equivalent to your command:
Code: [Select]
Begin Boolean Compare : [light] Equals False
    Execute command, 'Toggle Lights' (by name) (and wait until it completes)
    Set Boolean [light] to True
    Play random sound (2 items)
Else
    Play random sound (2 items)
    Pause 1,5 seconds
    Say, 'Shall I fix it ?'  (and wait until it completes)
    Write [Blue] 'Waiting for reply...' to log
    Wait for spoken response: 'Yes;No'
    Begin Text Compare : [~response] Has Not Been Set
        Say, 'Take your time idiot !'
    Else If Text Compare : [~response] Equals 'Yes'
        Execute command, 'Toggle Lights' (by name) (and wait until it completes)
        Say, 'Light state fixed.'
        Set Boolean [light] to False
    Else
        Say, 'Canceled.'
    End Condition
End Condition

Instead of explicitly setting "light" if it hasn't been set yet, you can check the "Evaluate 'Not Set' as false" option in the Begin action so that either "Not Set" or "False" will both have the same effect.

As "light" only has two states(1 or 0), you can use a Boolean variable instead(which can only have two states, "True" or "False", which actually represent 1 and 0, respectively).

I'll assume you're using an external command for the confirmation; VoiceAttack can handle that for you within a single command natively using the "Wait For Spoken Response" action(you can set a 10 second timeout as well, after which the value of the response variable will be "Not Set").
More info on that in this topic.

This topic on control flow may also be of some use.


On the forum, you can click the # button above your post to insert code tags, between which you can post your action list, so you don't have to change your text to prevent it from turning blue ;)

Hillgue

  • Newbie
  • *
  • Posts: 3
Re: Check ship's components status
« Reply #3 on: September 17, 2018, 03:45:39 am »
Thanks for the link and for the "turning blue" tip ;)
Edited my previous posts.

You're right about command for the confirmation, i'm using :

*Affirmative*
Code: [Select]
Set small int (condition) [confirmValue] value to 1
*Negative*
Code: [Select]
Set small int (condition) [confirmValue] value to 2

Works perfectly, thank you very much.
« Last Edit: September 17, 2018, 05:06:42 am by Hillgue »