How do I get the sum of a text string?

Get help using Construct 2

Post » 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
64
S
25
G
10
Posts: 654
Reputation: 10,842

Post » 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

Post » 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
64
S
25
G
10
Posts: 654
Reputation: 10,842

Post » 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

Post » Sat Nov 07, 2015 6:35 pm

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

Image

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
64
S
25
G
10
Posts: 654
Reputation: 10,842

Post » Sat Nov 07, 2015 6:56 pm

The simplest way would be to use the Browser.execJS() expression.
B
94
S
33
G
118
Posts: 5,395
Reputation: 75,851

Post » Sat Nov 07, 2015 7:02 pm

Amazing - thank you R0J0!
B
64
S
25
G
10
Posts: 654
Reputation: 10,842

Post » 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


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 6 guests