Author Topic: Dynamic variable creation  (Read 5116 times)

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Dynamic variable creation
« on: February 15, 2017, 09:27:20 AM »
I'm not sure how well known this technique is within the community, but I figured I would write about it anyway in case other folks might benefit.

I recently discovered that VA allows for somewhat dynamic variable naming. I was working on a command that assigned numbers to squadmates (Mass Effect 3), and I found that the following worked for creating text variables as the command looped through the process:

Code: [Select]
Set Text [{EXP:'squadmate' + {INT:squadmate counter}}] to '{TXT:answer}'

...where "squadmate counter" was a loop counter value of 1 or 2 and "answer" was a text value that held the squadmate's name (obtained via user response).

So basically this created "squadmate1" and "squadmate2" text variables that could store my squadmate name responses. Notice that I never actually explicitly defined "squadmate1" or "squadmate2" - the beauty here is that the EXP creates the variable names. And once the variables are defined I can explicitly call them in other code or repeat the above code snippet (minus assigning the value to {TXT:answer}) to call the variables more dynamically.

Clear as mud? TLDR - the EXP token can be used to dynamically define names for variables! I've only tried it with text variables, but I'm assuming it would work for other variables as well.

Cheers!

PsiQss

  • Guest
Re: Dynamic variable creation
« Reply #1 on: February 15, 2017, 11:26:56 AM »
Wow that's a great find! Good job! :D I just wonder if it's an intended feature or a side effect of sorts

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Dynamic variable creation
« Reply #2 on: February 15, 2017, 11:59:02 AM »
I just wonder if it's an intended feature or a side effect of sorts
It's intended. It was a feature request.

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Dynamic variable creation
« Reply #3 on: February 20, 2017, 09:39:48 AM »
Flipping sweet. Hopefully future versions of the help document will mention this neat functionality so other users are aware!

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: Dynamic variable creation
« Reply #4 on: February 20, 2017, 10:23:33 AM »
Hmmm... Thought that was documented.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Dynamic variable creation
« Reply #5 on: February 20, 2017, 11:44:27 AM »
Hmmm... Thought that was documented.
There's a note in the description for a number of actions:
Quote
(variable names can only contain colons if contained within a token… this would
be a good place to indicate that this input box also processes tokens).
Though that doesn't appear to be present for the "Set a Text Value" description.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: Dynamic variable creation
« Reply #6 on: February 20, 2017, 11:59:26 AM »
Ok... weird.  LOL

Thanks for checking that out, bud.

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Dynamic variable creation
« Reply #7 on: February 20, 2017, 01:14:39 PM »
Good call on that Pfeil.

Maybe I'm just being picky (or dense) but IMO discussing how it's possible to use the tokens to create dynamic variables would be a great addition to the help document. Short example maybe?

Admittedly I enjoyed my "Eureka!!" moment when I made the connection that the tokens could be used to create dynamic variables, but knowing this information beforehand would have saved me some coding trial and error time. Oh well, I'm enjoying the learning process :D


mikelimtw

  • Jr. Member
  • **
  • Posts: 51
Re: Dynamic variable creation
« Reply #8 on: February 23, 2017, 10:58:57 PM »
Oooh, I can use this to dynamically assign ship modules in EDDI to variables I can manipulate later....  thanks!