Author Topic: Passing parameters to/from a script.  (Read 2413 times)

stabby_dave

  • Newbie
  • *
  • Posts: 14
Passing parameters to/from a script.
« on: April 19, 2021, 11:14:54 AM »
Hi.

I'm writing a script (lets call it "ModuleFitted")to be used for ED as a callable object by other scripts. The script will be used in the format: "if ModuleFitted then...". You pass it a parameter ie "docking computer" and, if fitted, it'll return a value of true, else false.

I've got the code already written and I know how to pass the parameter to the script, but how do I get a true/false value back from it? All I can think of is to have the script set a global bool to show the result. It'll work, but ideally, I'd like it to pass the parameter back directly.

Is this even possible? If so, how do I do it?

Cheers.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Passing parameters to/from a script.
« Reply #1 on: April 19, 2021, 11:21:30 AM »
"script"? Are you referring to a VoiceAttack command?

If you're using the "Execute Another Command" action to call that command as if it were a function, you can use command-shared scope variables (prefixed with ">>") to return any values you need, as they will be available in the calling command, provided you enable the "Wait until this command completes before continuing" option for that action.

stabby_dave

  • Newbie
  • *
  • Posts: 14
Re: Passing parameters to/from a script.
« Reply #2 on: April 19, 2021, 11:56:26 AM »
Yes, it's a VoiceAttack command.

Command scoped variables are my fallback position. If I use them, the syntax would be along the lines of "call command", then "check result". If I can get the called command to pass it back, either directly or by reference, I can do "if 'command' = true". That's (for me) is a more preferable way of doing it, but if it isn't possible, then at least I can still do what I intended.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Passing parameters to/from a script.
« Reply #3 on: April 19, 2021, 11:59:54 AM »
Commands can't directly return a value in that sense, no.

stabby_dave

  • Newbie
  • *
  • Posts: 14
Re: Passing parameters to/from a script.
« Reply #4 on: April 19, 2021, 12:26:01 PM »
Ok. Thought that might be the case.

Thanks for the help.  :)