storing multiple values as one string

0 favourites
  • 6 posts
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • Hi everybody, I need to store several values as a single string separated by commas.

    I have a screen with multiple selections... for example, if I select options 1, 4 and 7, I need to store that as a string value "1,4,7", later I plan to use that value inside a choose() expresion.

    also if I deselect one, of course delete it from the string, so "1,4" or "4,7" and so on.

    Another thing is that, if I only select one, the choose() expresion won't work.

    Any idea, or a different workaround for that?

  • Well you can use a text variable or even a text, and either:

    obj.options & "1," on option 1 selected

    obj.options & "2," on option 2 selected etc

    or append text

    And to deselect one, use replace to find the value of the option and replace it with an empty string.

    As for choose, instead of using one value for each option, use twice the same.

  • Thanks, I had already tried that, but the problem is that the last value ends with a comma, so if I select 1 and 2, I get "1,2,". Dont'know how to get rid of that last comma.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • If you're using tokenat, it shouldn't be an issue though.

  • Thanks Kaisirak, the choose() didn't work, but the tokenat() did!!

  • No problem, as for the choose, what I meant was instead of having choose(1,2,3,4) try using choose(1,1,2,2,3,3,4,4). That way even if there is only one option there will actually be two.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)