# How do I get the sum of a text string?

Get help using Construct 2

### » Sat Nov 07, 2015 6:10 pm

I have a text string that changes at run time (it's an equation) - I have a second variable (number) that I'd like to make the sum of this string.

Is this possible? It's got me!
B
68
S
27
G
12
Posts: 696
Reputation: 12,253

### » Sat Nov 07, 2015 6:12 pm

What is the string/text?
Would it be possible to make the string text display variables and do the math with those?
If not can the string/text be parsed in an easy way?
If not can it be parsed in a hard way?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Sat Nov 07, 2015 6:17 pm

The string is an equation that has operators and values appended to it at run time. Parsing is exactly what I want to do, but I've never done it - ideally I just want an expression that has the value of the string.
B
68
S
27
G
12
Posts: 696
Reputation: 12,253

### » Sat Nov 07, 2015 6:22 pm

Why use the string if you have the values?

But like I said if you want to use the string it would be nescessary to know what the string looks like..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Sat Nov 07, 2015 6:35 pm

Sure thing - the string is basically "number" "operator" "number" (1+11 for example)

Quick example - the names were chosen poorly, but it demonstrates the idea that string changes at run time thanks to appends.

A hypothetical string would be - "1+12+2-4*8"
B
68
S
27
G
12
Posts: 696
Reputation: 12,253

### » Sat Nov 07, 2015 6:56 pm

The simplest way would be to use the Browser.execJS() expression.
B
100
S
38
G
134
Posts: 5,555
Reputation: 85,323

### » Sat Nov 07, 2015 7:02 pm

Amazing - thank you R0J0!
B
68
S
27
G
12
Posts: 696
Reputation: 12,253

### » Sat Nov 07, 2015 7:31 pm

I'd create the string dynamically to be able to use things like controlling the decimals, etcetera:

https://dl.dropboxusercontent.com/u/48563442/Maths.capx
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775