Author Topic: Pass Variable in Execute Command  (Read 5586 times)

MalcomR

  • Newbie
  • *
  • Posts: 42
Pass Variable in Execute Command
« on: April 07, 2018, 04:32:12 PM »
I have a command that uses Dynamic variables.

[Systems;Engines;Weapons;Reset] [1..4]

I would like to execute this command from another command.

Execute command, 'Systems 3'

Systems can also be Engines or Weapons and the 3 could be any number from 1 to 4.

Can I do this and is so how.  If it can't be done with execute what's the best way to do this?

Thanks.

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Pass Variable in Execute Command
« Reply #1 on: April 07, 2018, 09:47:50 PM »
Hmm, wouldn't System 3 have to set the variable, and [Systems;Engines;Weapons;Reset] [1..4] would have to retrieve the variable when run, in place of a vocal command?

MalcomR

  • Newbie
  • *
  • Posts: 42
Re: Pass Variable in Execute Command
« Reply #2 on: April 07, 2018, 11:21:39 PM »
The command [Systems;Engines;etc] [1..4] uses the cmdseg 0 to figure out what command (Systems in the example) and comdseg 1 to find the number so if I says Systems 2 it adds 2 to the system setting, Engines 1 adds 1 to the Engines setting.  The command sets variables equal to the command name and the number.  That works fine when I say it.  What I wanted to do was call it from another command and pass the command type (Systems, Engines, etc.) and the number to it.  Kind of like calling a function and passing it the name thing to change and what to set it to as in

ExecuteCommand("System", 2).

I don't think it can be done though.

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Pass Variable in Execute Command
« Reply #3 on: April 08, 2018, 03:51:48 AM »
Code: [Select]
Set Text [Systems] to '{CMDSEGMENT:0}'
Set Text [Systems] to [Saved Value] (Set to Retrieve)
Set Text [Level] to '{CMDSEGMENT:1}'
Set Text [Level] to [Saved Value] (Set to Retrieve)

When you run System 3, You can change {Systems} variable, and {Level} to whatever you want.

Code: [Select]
Set Text [Systems] to 'Engines' (save value to profile)
Set Text [Level] to '3' (save value to profile)

I'm far from a expert on VA, but I think that would work.

(I tried it, and it worked for me.)

Hope it works for you as well. :)
« Last Edit: April 08, 2018, 04:49:42 AM by iceblast »

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Pass Variable in Execute Command
« Reply #4 on: April 08, 2018, 04:48:55 AM »
Well, I didn't think that all the way through. You could get it to work, but you couldn't use the Verbal part of the command anymore. So, I changed it.

Code: [Select]
Set Text [Systems] to [Saved Value]
    Set Text [Level] to [Saved Value]
Begin Text Compare : [Systems] Has Not Been Set
    Set Text [Systems] to '{CMDSEGMENT:0}'

Else
    Set Text [Level] to [Saved Value]
End Condition
Begin Text Compare : [Level] Has Not Been Set
    Set Text [Level] to '{CMDSEGMENT:1}'
Else
    Set Text [Level] to [Saved Value]
End Condition
Set Text [Level] to [Not Set] (save value to profile)
Set Text [Systems] to [Not Set] (save value to profile)

Put the 2 variable clears at the end of the [Systems;Engines;Weapons;Reset] [1..4] command, so it's the last thing it does.

Now you can run a command Called System 3 that sets the 2 variable.

Code: [Select]
Set Text [Systems] to 'Engines' (save value to profile)
Set Text [Level] to '3' (save value to profile)
Execute command, 'Systems 3'



MalcomR

  • Newbie
  • *
  • Posts: 42
Re: Pass Variable in Execute Command
« Reply #5 on: April 08, 2018, 12:24:42 PM »
Interesting and clever.  The more I use VA the more I'm impressed with what you can do with it and it's flexibility and power.  I discovered DoubleDee's Elite profile and learned more tricks!!

Just to be clear. The first code block (Set and clear text) go in the [Systems;Engines;...] [1..4] command and then in my calling routine I set the Systems and Level.

Thanks. That is what I needed.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: Pass Variable in Execute Command
« Reply #6 on: April 08, 2018, 02:54:59 PM »
There is no way to just pass stuff around like function parameters as we know that can be any number of values with any result type.  However, there is a feature called, 'command shared variables' (VA help doc, around page 161).  What this does is allow a variable to be scoped only to a command and to every command that is called by that command (and as every command completes, every calling command all the way back up the tree).

Some examples:

So, lets say you have command A, which calls command B.
Command A sets a command-shared variable ~~myVar to 10 (note the ~~ before the name)
A calls B
B can read ~~myVar and says (with TTS) "The value is 10".
(This simulates passing a parameter, no return value).

Second example (using commands A and B again):
Command A sets a command-shared variable ~~myVar to 10
A calls B (which is flagged to wait until finished - important for this example).
B reads ~~myVar and multiplies it by 10.
B completes and then A reads ~~myVar and says (with TTS) "The value is 100"
(This simulates passing a parameter by ref).

One more example:
Lets say you have command A, which calls command B, which calls command C.
A calls B (which is flagged to wait until finished - important).
B sets command-shared integer variable ~~myVar to 10.
B calls C (which is flagged to wait until finished - important).
C can read ~~myVar and sets integer ~~myNewVar as ~~myVar times 10.
B can also read ~~myNewVar and multiplies it times 2.
A can also read ~~myNewVar and ~~myVar and multiplies them together and gets a result of 2000.
(This simulates passing a parameter, and getting a return value somehow o_O).

I guess I've made a complicated illustration.  Sorry about that.  I needed to show how the values are shared in the same lineage even though the value originates in a subcommand.  Not a conventional way of doing things, but it is a way ;)

Hope some of that might help in some way.

MalcomR

  • Newbie
  • *
  • Posts: 42
Re: Pass Variable in Execute Command
« Reply #7 on: April 08, 2018, 03:39:06 PM »
This definitely helps.  VA is so amazing!  I'd read about scoped variables and planned to use them but never thought of them in my command.  The illustrations are fine.

Thanks.

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Pass Variable in Execute Command
« Reply #8 on: April 08, 2018, 07:07:06 PM »
Right, in your [Systems;Engines;...] [1..4] command. Systems and Level are set outside this command.

Sounds like you have this problem figured out now. ;)

MalcomR

  • Newbie
  • *
  • Posts: 42
Re: Pass Variable in Execute Command
« Reply #9 on: April 09, 2018, 02:30:02 AM »
I have a lot to think about!  Thanks to all.

MalcomR

  • Newbie
  • *
  • Posts: 42
Re: Pass Variable in Execute Command
« Reply #10 on: April 25, 2018, 11:28:26 AM »
As an update I've been using scoped variables to achieve what I want as well as the ability to use variables for key presses.  I put my key bindings in commands by category (i.e. weapons commands in key-weapons, etc.) and during initialization I run these commands so the keys are bound.  Nice easy, one place to change any mappings that  happen in the game.   Right now I'm working with Elite Dangerous but also use it for other apps.  A fantastic program.