Issue with Arrays.

0 favourites
  • 10 posts
  • 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.

    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.

    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.


  • I added in some logging:

    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?

  • Are the values in the Array numbers or strings? i.e. x = 1 vs x = "" & 1

  • 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.

  • That seemed to be it. Thanks

  • 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

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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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!

  • One of the functions that comes with my C2 Data Editor in the app store is this:

  • 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...


Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)