Can array's cause lag?

0 favourites
  • 4 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • So I want to keep track of the average temperature in my game and allow players to view that data whenever so every 10-30 seconds whatever I decide it will save the average temperature to the array and add a new space on the array for the next temperature. Before I get too far into it will this eventually cause lag?

  • While my experience with C2 is extremely limited I can say this. One of my first experiments was creating a 5,148 element array (72x72), filling that array with random numbers (1-5), reading back that array and assigning sprites to the background based on the random number, refilling the array with random numbers and then using a different sprite to create a parallax background and... it was fast.

    Arrays are old programming structures. They've been around for years so the code to work with any array in any language is pretty well optimized. But, with any programming, it depends on how large the array is, how often you access it and whether you're reading through the entire array or accessing one cell.

    The problem you're going to have with an array is defining the size of the array at the start and then tracking which cells you've updated and what to do when you reach the end of the array (I don't think C2 has dynamic arrays where you can change the size, I may be wrong)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • C2 does have dynamic arrays, and like anything if you increase the number of things to process over time it will eventually be more than the pc can handle quickly.

    Back to the op: if you're just using the array as a list and adding to the list over time then that alone won't affect performance, just increase memory use over time. Accessing individual values from an array is just as fast if the array is tiny or gigantic. What would affect performance is if you're looping over the array when it's gigantic.

    Will this be an issue for your game? If you're only adding more values every 10 seconds tops then it would take 13 hours to get to 5000 values which still isn't an issue to loop over.

  • I'm making a simulation of an atmosphere/planet so I probably would have about 5 things I'd wanna keep track of and put down there average in the array every 10 seconds or so and if you checked recent you'd see the latest 10 kind of like that so I wouldn't need to access more than 50 values at any given time

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