Can array's cause lag?

Discussion and feedback on Construct 2

Post » Sun Nov 15, 2015 7:38 pm

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?
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Sun Nov 15, 2015 8:33 pm

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)
B
16
S
8
Posts: 127
Reputation: 1,928

Post » Mon Nov 16, 2015 12:36 am

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.
B
94
S
33
G
118
Posts: 5,395
Reputation: 75,851

Post » Mon Nov 16, 2015 11:00 pm

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
B
22
S
8
Posts: 203
Reputation: 2,059


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 9 guests