Add two single digits from an array into a double digit

Get help using Construct 2

Post » Tue Apr 07, 2015 2:15 pm

Hi guys,

How do I add two single digit numbers from an array into a single double digit or more number? For example, array 0 = 5, array 1 = 2, and I want to get the value 52.

I thought the code below would work, but it didn't.

(array.at(0)) & (array.at(1))

I would think it is something close to this, and I am missing something in the syntax.
B
39
S
18
G
30
Posts: 680
Reputation: 19,431

Post » Tue Apr 07, 2015 2:25 pm

If you multiply the first number by 10 you could just add them up..
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 » Tue Apr 07, 2015 2:28 pm

The & operator is a bit touchy. Used with numbers, it acts as a logical AND. You probably should convert your array entry to strings using the str() function so & actually acts as a concatenation operator again.

str(array.at(0)) & str(array.at(1))
B
59
S
24
G
23
Posts: 928
Reputation: 17,491

Post » Wed Apr 08, 2015 2:54 am

@LittleStain, haha that is so devious, it is almost evil!

@Magistross, thank you! That worked perfectly!
B
39
S
18
G
30
Posts: 680
Reputation: 19,431


Return to How do I....?

Who is online

Users browsing this forum: JoshSenpai, tetuan and 11 guests