Combining multiple different variables into one piece of a list.

Malphas
10 Sept 2022, 16:36

Hello, I was trying to see if it's possible to combine multiple variables into a list as one piece so for example the first thing of the list would list all variables together.

list add (player.list, {player.one} +{player.two} +  {player.three} +  {player.four} + {player.five})

All the variables are defined but when I run this piece of code it reads "+ {player.two}" as a function and not a variable.

Also might be worth mentioning that the variables are not values that needed to be added up to eachother but just need to appear next to eachother so it also could work with words for example.

Any help or ideas would be greatly appreciated!

Thanks in advance.


mrangel
12 Sept 2022, 11:57

Why have the variable names got {} around them? You only need to put {} around a variable name if you're using it in the text processor.

Not quite sure what your intention is here, so I'll give an answer for each of the possibilities I can see.
For this example, I'm assuming that the object named player has attributes one, two, and three with values "Red", "Green", and "Blue".

  1. If you want to add the string "RedGreenBlue" to a list:
    • Using expressions: list add (player.list, player.one + player.two + player.three)
    • Using text processor: list add (player.list, ProcessText ("{player.one}{player.two}{player.three}"))
  2. If you want to add the string "Red + Green + Blue" to a list:
    • Using expressions: list add (player.list, player.one + " + " + player.two + " + " + player.three)
    • Using text processor: list add (player.list, ProcessText ("{player.one} + {player.two} + {player.three}"))
  3. If you want to add the string "{player.one} + {player.two} + {player.three}" to the list (so it will display "Red + Green + Blue" when it is printed, but won't actually have that value):
    • list add (player.list, "{player.one} + {player.two} + {player.three}")
  4. If you want to add the three variables to the list separately:
    • list add (player.list, player.one)
      list add (player.list, player.two)
      list add (player.list, player.three)
    • Or slightly more efficiently:
      foreach (attr, Split("one;two;three")) list add (player.list, GetAttribute (player, attr))

If none of these is what you want, maybe you could give an example of what you want it to do.