Author Topic: How to save and use variables stored in the profile  (Read 8619 times)

falstaff

  • Newbie
  • *
  • Posts: 11
How to save and use variables stored in the profile
« on: July 23, 2016, 08:13:24 PM »
I have a command that runs every time that the profile starts and it sets some values to so I can keep track the state of some important things for me. Here's an example.
I have an integer variable called Camera Mode that starts with a value of 0.
If I switch to camera style 2, I want to set the value to 1
If I switch to camera style 3, I want to set the value to 2
If I switch to the default camera, I want the value to be 0

I'm not sure how to access the variable from other commands, check it, perform a command based on the current camera mode, then set the value to selected camera mode.

What is the best way to do this?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4749
  • RTFM
Re: How to save and use variables stored in the profile
« Reply #1 on: July 23, 2016, 10:06:24 PM »
This is what you're describing, from what I can gather:

Profile start
Code: [Select]
Set small int (condition) [Camera Mode] value to 0

Camera style 2
Code: [Select]
Begin Small Integer Compare : [Camera Mode] Equals 0
    Press C key and hold for 0,06 seconds and release
Else If Small Integer Compare : [Camera Mode] Equals 2
    Press C key and hold for 0,06 seconds and release
    Press C key and hold for 0,06 seconds and release
End Condition
Set small int (condition) [Camera Mode] value to 1

Camera style 3
Code: [Select]
Begin Small Integer Compare : [Camera Mode] Equals 1
    Press C key and hold for 0,06 seconds and release
Else If Small Integer Compare : [Camera Mode] Equals 0
    Press C key and hold for 0,06 seconds and release
    Press C key and hold for 0,06 seconds and release
End Condition
Set small int (condition) [Camera Mode] value to 2

Default camera
Code: [Select]
Begin Small Integer Compare : [Camera Mode] Equals 2
    Press C key and hold for 0,06 seconds and release
Else If Small Integer Compare : [Camera Mode] Equals 1
    Press C key and hold for 0,06 seconds and release
    Press C key and hold for 0,06 seconds and release
End Condition
Set small int (condition) [Camera Mode] value to 0

That is assuming you use one key("C", in this case), to cycle through the camera styles.


                                                                                                                                                                                     


If you have something with more "modes", I've used something like this for convenience:
Code: [Select]
Set small int (condition) [Target Camera Mode] value to 0
Start Loop While [Camera Mode] Does Not Equal [Target Camera Mode]
    Press C key and hold for 0,06 seconds and release
    Begin Small Integer Compare : [Camera Mode] Is Less Than 8
        Set small int (condition) [Camera Mode] value as incremented by 1
    Else
        Set small int (condition) [Camera Mode] value to 0
    End Condition
End Loop
Set small int (condition) [Camera Mode] value to the value of [Target Camera Mode]
You set "Target Camera Mode" to whichever camera you want to switch to, and it will press C until it reaches it.

Because "Camera Mode" is zero-indexed, "Begin Small Integer Compare : [Camera Mode] Is Less Than 8" would be for a total of 9 cameras(default + 8)





If you prefer, you can use:
Code: [Select]
Set small int (condition) [Target Camera Mode] value to 0
Set small int (condition) [Camera Mode Count] value to 5
Start Loop While [Camera Mode] Does Not Equal [Target Camera Mode]
    Press C key and hold for 0,06 seconds and release
    Begin Text Compare : [{EXP:{SMALL:Camera Mode} < {SMALL:Camera Mode Count} - 1}] Equals '1'
        Set small int (condition) [Camera Mode] value as incremented by 1
    Else
        Set small int (condition) [Camera Mode] value to 0
    End Condition
End Loop
Set small int (condition) [Camera Mode] value to the value of [Target Camera Mode]
This way you can set "Camera Mode Count" to the total amount of camera modes including default.

You could set "Camera Mode Count" in your Profile start command, so you only have to edit it once should it change.





Additionally, you can merge this into a single command:
Default camera;Camera style 2;Camera style 3
Code: [Select]
Begin Text Compare : [{CMD}] Equals 'Default camera'
    Set small int (condition) [Target Camera Mode] value to 0
Else If Text Compare : [{CMD}] Equals 'Camera style 2'
    Set small int (condition) [Target Camera Mode] value to 1
Else If Text Compare : [{CMD}] Equals 'Camera style 3'
    Set small int (condition) [Target Camera Mode] value to 2
End Condition
Set small int (condition) [Camera Mode Count] value to 3
Start Loop While [Camera Mode] Does Not Equal [Target Camera Mode]
    Press C key and hold for 0,06 seconds and release
    Begin Text Compare : [{EXP:{SMALL:Camera Mode} < {SMALL:Camera Mode Count} - 1}] Equals '1'
        Set small int (condition) [Camera Mode] value as incremented by 1
    Else
        Set small int (condition) [Camera Mode] value to 0
    End Condition
    Write '[Blue] {SMALL:Camera Mode}' to log
End Loop
Set small int (condition) [Camera Mode] value to the value of [Target Camera Mode]
This is assuming you want to eventually name your camera modes(E.G. "Chase camera" or "Cinematic camera").


It also centralizes the variables, so that if a patch were to add a new camera style between default and 2 for example, you can slot it in and increment the numbers in the same edit window.

In fact, to simplify inserting new modes, you can use:
Default camera;Camera style [2..4]
Code: [Select]
Set small int (condition) [Target Camera Mode] value to 0
Begin Text Compare : [{CMD}] Equals 'Camera style 2'
    Set small int (condition) [Target Camera Mode] value to 1
Else If Text Compare : [{CMD}] Equals 'Camera style 3'
    Set small int (condition) [Target Camera Mode] value to 2
End Condition
Set small int (condition) [Camera Mode Count] value to 4
Start Loop While [Camera Mode] Does Not Equal [Target Camera Mode]
    Press C key and hold for 0,06 seconds and release
    Begin Text Compare : [{EXP:{SMALL:Camera Mode} < {SMALL:Camera Mode Count} - 1}] Equals '1'
        Set small int (condition) [Camera Mode] value as incremented by 1
    Else
        Set small int (condition) [Camera Mode] value to 0
    End Condition
    Write '[Blue] {SMALL:Camera Mode}' to log
End Loop
Set small int (condition) [Camera Mode] value to the value of [Target Camera Mode]





If you use the number, you can do away with the manual mode association:
Default camera;Camera style [2..10]
Code: [Select]
Begin Text Compare : [{CMD}] Equals 'Default camera'
    Set small int (condition) [Target Camera Mode] value to 0
Else
    Set Text [CMD] to '{CMD}'
    Set small int (condition) [Target Camera Mode] value to the converted value of {EXP:{TXTNUM:CMD} -1}
End Condition
Set small int (condition) [Camera Mode Count] value to 10
Start Loop While [Camera Mode] Does Not Equal [Target Camera Mode]
    Press C key and hold for 0,06 seconds and release
    Begin Text Compare : [{EXP:{SMALL:Camera Mode} < {SMALL:Camera Mode Count} - 1}] Equals '1'
        Set small int (condition) [Camera Mode] value as incremented by 1
    Else
        Set small int (condition) [Camera Mode] value to 0
    End Condition
    Write '[Blue] {SMALL:Camera Mode}' to log
End Loop
Set small int (condition) [Camera Mode] value to the value of [Target Camera Mode]





One more, just in case you're using this with early access/often patched software:
[Default;Chase;Cinematic;Cockpit] camera
Code: [Select]
Set small int (condition) [Target Camera Mode] value to 0
Begin Text Compare : [{CMD}] Equals 'Default camera'
    Jump to Marker: CMDMatched
Else
    Set small int (condition) [Target Camera Mode] value as incremented by 1
End Condition
Begin Text Compare : [{CMD}] Equals 'Chase camera'
    Jump to Marker: CMDMatched
Else
    Set small int (condition) [Target Camera Mode] value as incremented by 1
End Condition
Begin Text Compare : [{CMD}] Equals 'Cinematic camera'
    Jump to Marker: CMDMatched
Else
    Set small int (condition) [Target Camera Mode] value as incremented by 1
End Condition
Begin Text Compare : [{CMD}] Equals 'Cockpit camera'
    Jump to Marker: CMDMatched
Else
    Set small int (condition) [Target Camera Mode] value as incremented by 1
End Condition
Marker: CMDMatched
Set small int (condition) [Camera Mode Count] value to 4
Start Loop While [Camera Mode] Does Not Equal [Target Camera Mode]
    Press C key and hold for 0,06 seconds and release
    Begin Text Compare : [{EXP:{SMALL:Camera Mode} < {SMALL:Camera Mode Count} - 1}] Equals '1'
        Set small int (condition) [Camera Mode] value as incremented by 1
    Else
        Set small int (condition) [Camera Mode] value to 0
    End Condition
    Write '[Blue] {SMALL:Camera Mode}' to log
End Loop
Set small int (condition) [Camera Mode] value to the value of [Target Camera Mode]
This one makes it really easy to just add the name of your new camera to the command name, and copy and paste a conditional block into the position the new camera occupies with the new name.

Don't forget to modify "Camera Mode Count" as well.
« Last Edit: July 23, 2016, 10:27:39 PM by Pfeil »

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: How to save and use variables stored in the profile
« Reply #2 on: July 23, 2016, 10:26:38 PM »
I'm starting to think Pfeil is more machine than man.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4749
  • RTFM
Re: How to save and use variables stored in the profile
« Reply #3 on: July 23, 2016, 11:07:16 PM »
I'm starting to think Pfeil is more machine than man.


falstaff

  • Newbie
  • *
  • Posts: 11
Re: How to save and use variables stored in the profile
« Reply #4 on: July 24, 2016, 04:13:57 AM »
Thanks so much, I learned a lot from that!
Unfortunately, I think I didn't frame the question properly to get the answer I needed.
Let's back up a second, I'll give you more details about what I'm trying to do.

This is a MechWarrior Online profile using the IVONA voice, Brian.
When The profile loads, I set the following variables.

CameraMode - Integer (not small) - 0
VisionMode - Integer (not small) - 0
WeaponDoorStatus - Boolean - False
UAV - Boolean - True

When I say, "External Camera" I want the following logic to fire.
If CameraMode is not equal to 1 then
press F3
say "External Camera Online"
set CameraMode to 1
exit
If CameraMode is equal to 1 then say "External Camera is already deployed"

When I say, "Cockpit View" I want the following logic to fire.
If CameraMode is not equal to 0 then
press F3
say "Returning to Cockpit View"
set CameraMode to 0
exit
If CameraMode is equal to 1 then say "Cockpit View is the current view"

When I say, "Night Vision" I want the following logic to fire.
If VisionMode is not equal to 1 then
press N
say "Night Vision Engaged"
set VisionMode to 1
exit
If VisionMode is equal to 1 then say "Night Vision is already active"

When I say, "Heat Vision" I want the following logic to fire.
If VisionMode is not equal to 2 then
press H
say "Thermal Vision Engaged"
set VisionMode to 2
exit
If VisionMode is equal to 2 then say "Thermal Vision is already active"

When I say, "Normal Vision" I want the following logic to fire.
If VisionMode is equal to 1 then
press N
say "Vision Mode Normal"
set VisionMode to 0
exit
If VisionMode is equal to 2 then
press H
say "Vision Mode Normal"
set VisionMode to 0
exit
If VisionMode is equal to 0 then say "Normal Vision is already active"

When I say, "Open Weapon Doors" I want the following logic to fire.
If WeaponDoorStatus is False then
press ?
say "Weapons are Hot"
set WeaponDoorStatus to True
exit
If WeaponDoorStatus is equal to True then say "Weapon doors are already open"

When I say, "Close Weapon Doors" I want the following logic to fire.
If WeaponDoorStatus is True then
press ?
say "Weapon Doors Closed"
set WeaponDoorStatus to False
exit
If WeaponDoorStatus is equal to False then say "Weapon doors are already closed"

When I say, "Launch Drone" I want the following logic to fire.
If UAV is True then
press F8
say "Drone deployed"
set UAV to False
exit
If UAV is equal to False then say "Drone Bay Empty"


I hope that helps you understand what I'm looking for.

I tried doing the UAV one myself but when I hit the execute command to test it, nothing happens.
Here are some screenshots from my Google Drive
https://drive.google.com/open?id=0B0LdH-fKpAKeVUk1QjNaSXpyUWM
https://drive.google.com/open?id=0B0LdH-fKpAKeNDdWWFgydWxKcDg


By the way,

What are the new features in the current Beta?
I'd like to help test it but I'm not sure what is different than the stable version.








« Last Edit: July 24, 2016, 04:35:21 AM by falstaff »

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: How to save and use variables stored in the profile
« Reply #5 on: July 24, 2016, 07:45:27 AM »
I tried doing the UAV one myself but when I hit the execute command to test it, nothing happens.
Here are some screenshots from my Google Drive
https://drive.google.com/open?id=0B0LdH-fKpAKeVUk1QjNaSXpyUWM
https://drive.google.com/open?id=0B0LdH-fKpAKeNDdWWFgydWxKcDg
As long as you actually did initialize all the required variable at profile load (remember, they all start as 'Not Set' if not stored persistently and/or initialized explicitly), the above command shoud work... this is a slighly simplified version, but the logic is the same
Code: [Select]
Begin Boolean Compare : [UAV] Equals True
    Say, 'UAV Deployed'
    Press F8 key and hold for 0,18 seconds and release
    Set Boolean [UAV] to False
Else
    Say, 'Dronebay empty'
End Condition
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4749
  • RTFM
Re: How to save and use variables stored in the profile
« Reply #6 on: July 24, 2016, 12:55:23 PM »
CameraMode - Integer (not small) - 0
VisionMode - Integer (not small) - 0
You don't have to use small, I just prefer to if the value is within 32,767 and -32,767 as it would use less memory, but that's not really something you should worry about.


When I say, "External Camera" I want the following logic to fire.
If CameraMode is not equal to 1 then
press F3
say "External Camera Online"
set CameraMode to 1
exit
If CameraMode is equal to 1 then say "External Camera is already deployed"

External Camera
Code: [Select]
Begin Integer Compare : [Camera Mode] Does Not Equal 1
    Press F3 key and hold for 0,06 seconds and release
    Say, 'External Camera Online'
    Set integer [Camera Mode] value to 1
Else
    Say, 'External Camera is already deployed'
End Condition

You don't have to check the value of the variable again when it can only have two states(or if you've already checked all the other states), so you can use "Else".

Other than that, you look to be on the right track.



When I say, "Normal Vision" I want the following logic to fire.
If VisionMode is equal to 1 then
press N
say "Vision Mode Normal"
set VisionMode to 0
exit
If VisionMode is equal to 2 then
press H
say "Vision Mode Normal"
set VisionMode to 0
exit
If VisionMode is equal to 0 then say "Normal Vision is already active"

Normal Vision
Code: [Select]
Begin Integer Compare : [Vision Mode] Does Not Equal 0
    Begin Integer Compare : [Vision Mode] Equals 1
        Press N key and hold for 0,06 seconds and release
    Else
        Press H key and hold for 0,06 seconds and release
    End Condition
    Say, 'Vision Mode Normal'
    Set integer [Vision Mode] value to 0
Else
    Say, 'Normal Vision is already active'
End Condition

This is how I would do it, however, there is rarely a "best way", so use the structure that feels logical to you.



By the way,

What are the new features in the current Beta?
I'd like to help test it but I'm not sure what is different than the stable version.
The changelog for the latest beta can be found here, however, it may not contain new features so much as bugfixes(at present).

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: How to save and use variables stored in the profile
« Reply #7 on: July 24, 2016, 09:08:13 PM »
https://www.youtube.com/watch?v=KSr3PETjEVQ

Is that you?

Good video... I played Mechwarrior a lot back in the day.  Love that game.

falstaff

  • Newbie
  • *
  • Posts: 11
Re: How to save and use variables stored in the profile
« Reply #8 on: July 25, 2016, 09:46:04 PM »
Thanks to everyone for helping!
I've learned a lot from doing this.
I'm in the middle of using all this advice to complete my profile.
I will post it for those who are interested when it's complete.
Thanks for the heads up on the beta as well.
Yes, that video is me testing and showing it to a friend so they could buy the software.