Issue with Arrays.

Discussion and feedback on Construct 2

Post » Sun Aug 31, 2014 5:09 pm

I'm really struggling with some array stuff here. I feel like I have everything setup right, but it's just not working.

Basically I have 3 arrays that store the X, Y and Type of blocks I want to create.

Image

My code, I am comparing the X value at the CurX position of the for each loop. I have the 1pblocks added in there so I can debug and comparison is never true, resulting in the 1pblocks NOT being updated to 23, never mind the blocks being created.

Here is what the array looks like I am getting the data from.
Image

I've been at this for a few hours, and I have used arrays like this in other projects so I am just not sure what I am missing here.

Thanks.
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Sun Aug 31, 2014 5:26 pm

I added in some logging:
Image

The info is showing in the browser log, it's just the subevents that don't seem to be firing. My thought was with each loop of the For Each loop, it would run through each of the sub events and do the compares. Is that not correct?
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Sun Aug 31, 2014 5:36 pm

Are the values in the Array numbers or strings? i.e. x = 1 vs x = "" & 1
B
21
S
5
Posts: 196
Reputation: 1,974

Post » Sun Aug 31, 2014 5:37 pm

Hmm, good question. I thought I tried comparing as strings earlier just in case, but i have tried so many things, who knows :).

I'll try it again.
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Sun Aug 31, 2014 5:40 pm

That seemed to be it. Thanks :)
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Sun Aug 31, 2014 5:44 pm

I had a lot of problem like this before, I might not be helping but I have developed a best practice for myself to always store value in array as string and convert them into integer when I compare values (if necessary).

You might want to check whether the value stored in your array is a string or not, commonly when this happen to me it is always the case of comparing "1"=1 which is comparing a text to integer, as the reason of condition not firing 90% of the time. This is sure to happen whenever I stored an array asJSON and load it, then I failed to fire the condition I wanted.

I admit, visually everything will always look right, it's hard to track which is numeric which is not, one of the key reason I need the debugger mode in my thread.

Edit: oh well ninja'ed
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Sun Aug 31, 2014 5:46 pm

Yup, that was exactly the problem. Looking up how to convert string to int now.
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Sun Aug 31, 2014 5:49 pm

ArcadEd wrote:Yup, that was exactly the problem. Looking up how to convert string to int now.

I have stopped using event like your Line85, I prefer using system: compare two values, by either converting both to string or both to integer, seems like a fail-proof method for me at least. Cheers!
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Sun Aug 31, 2014 5:53 pm

One of the functions that comes with my C2 Data Editor in the app store is this:
Last edited by ggibson1 on Sun Aug 31, 2014 6:16 pm, edited 2 times in total.
B
21
S
5
Posts: 196
Reputation: 1,974

Post » Sun Aug 31, 2014 6:06 pm

I am sitting here right now working on the next version of the C2 Data Editor that I hope to release this weekend that has an IsNumeric that does handle floats as well.

Here is the newest that works with float and has a bug fix...


IsNumeric.PNG
You do not have the required permissions to view the files attached to this post.
B
21
S
5
Posts: 196
Reputation: 1,974


Return to Construct 2 General

Who is online

Users browsing this forum: BadMario and 6 guests