How do I sum the values of all text boxes on a layout

Get help using Construct 2

Post » Thu Feb 25, 2016 10:48 pm

Hello,

I have a layout which has a number of form text boxes on the screen. I am looking to make it so that when any one of the boxes changes a variable is updated. The variable would contain the sum of all the boxes on the screen. I am looking to do it so that it doesn't matter how many boxes are on the screen so avoiding something like:

"Totalvariable = textbox1.value + textbox2.value"

I was hoping something simple like a "For Each textbox -> Total = Total + textbox.value" but I couldn't get anything to work =(
B
38
S
11
G
1
Posts: 204
Reputation: 4,477

Post » Thu Feb 25, 2016 11:38 pm

You need to copy the TextBox and not Clone it, or use a Family to do that.
ImageImageImage
B
71
S
22
G
259
Posts: 3,793
Reputation: 143,702

Post » Fri Feb 26, 2016 5:13 am

Hi @blackhornet

My plan is to have it as a copy rather than a clone. But for some reason I couldn't get it to add up all the boxes. It only ever seems to add the last text box edited, not all of them :(
B
38
S
11
G
1
Posts: 204
Reputation: 4,477

Post » Fri Feb 26, 2016 6:12 am

If they aren't working then you do have clones. And you said you've got textBox1, textBox2, which are clones. If you want to keep them that way, put them all in a Family and do a Foreach on the Family.
ImageImageImage
B
71
S
22
G
259
Posts: 3,793
Reputation: 143,702

Post » Fri Feb 26, 2016 3:36 pm

Hi @blackhornet

Had a try at it. (Definitely copies of text boxes). See capx example. Any chance you can have a quick look to see if you can work out the issue? I am sure it will be me doing something very silly / illogical!

https://www.dropbox.com/s/53gls1ezqs6h3 ... .capx?dl=0
B
38
S
11
G
1
Posts: 204
Reputation: 4,477

Post » Fri Feb 26, 2016 3:54 pm

http://www.blackhornettechnologies.com/ ... d_BHT.capx
Since you are in the "On text changed" event, only that one InputBox is picked. You need to "Pick all" first so you can get at all of the InputBoxes again.
ImageImageImage
B
71
S
22
G
259
Posts: 3,793
Reputation: 143,702

Post » Fri Feb 26, 2016 5:14 pm

@blackhornet

Many thanks =) Help is much appreciated. I thought it was me not understanding how it works. Cheers
B
38
S
11
G
1
Posts: 204
Reputation: 4,477


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests