Slippery business with arrays

Get help using Construct 2

Post » Thu Feb 23, 2012 5:03 am

EDIT: Never mind! See second post for my dummy solution.

Specifically, with concatenating values from arrays. Look at this small capx: there's two events, one initializing three values in an array and one displaying values in a text object. It isn't behaving quite the way it should, unless I'm just not seeing what's happening here...

Array (0,0) is 5
Array (1,0) is 2
Array (2,0) is 3

I tried displaying "Array.At(0,0)&Array.At(1,0)", thinking I'd get "5" and "2" concatenated together, but instead I get... drumroll please... 1. It just says "1". Why is that?

http://dl.dropbox.com/u/19702035/arrayconcat.capx

Oddly enough, that's not even what I was trying to test with this small capx. I was going to try to display "Array.At(0,0)&Array.At(Array.At(1,0),0)", with the expected result of "53", but I didn't even get that far. (In my larger project, trying to do something like that makes the game not load in previews. In this capx, it comes out to... "1". )SullyTheStrange2012-02-23 05:10:47
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Thu Feb 23, 2012 5:09 am

AH. I see what's happening there. It's taking & to mean the logical AND rather than the concatenation I was expecting. Adding &""& in the middle seems to fix that problem.

Uhh... yeah. That solves that.
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Thu Feb 23, 2012 11:42 am

The proper way to do that is
str(Array.At(0,0))&Array.At(1,0)

You have to convert integer type into string type for the concatenation to work. Once you have a base string, all that is concatenated to it will be converted.

Also the bitwise operation 5 & 2
in binary looks lik 0101 & 0010 = 0000 not 1
1 probably means "it's not null or false" or something like that.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346


Return to How do I....?

Who is online

Users browsing this forum: luckyrawatlucky, mindragon73 and 23 guests