storing multiple values as one string

Get help using Construct 2

Post » Mon Oct 08, 2012 7:15 am

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?
Image
B
42
S
11
G
5
Posts: 269
Reputation: 10,790

Post » Mon Oct 08, 2012 2:33 pm

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.
B
5
S
1
G
1
Posts: 39
Reputation: 1,128

Post » Mon Oct 08, 2012 4:43 pm

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.
Image
B
42
S
11
G
5
Posts: 269
Reputation: 10,790

Post » Mon Oct 08, 2012 6:45 pm

If you're using tokenat, it shouldn't be an issue though.
B
5
S
1
G
1
Posts: 39
Reputation: 1,128

Post » Wed Oct 10, 2012 3:07 am

Thanks @kaisirak, the choose() didn't work, but the tokenat() did!!
Image
B
42
S
11
G
5
Posts: 269
Reputation: 10,790

Post » Wed Oct 10, 2012 5:42 am

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.
B
5
S
1
G
1
Posts: 39
Reputation: 1,128


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests