So I have experienced a minor problem, easy fix. But I just wanted to get it out before I forget it.
I have been experiencing problems with loops lately, espesually for loops. The most recent one I have located was that the draw() function runs too often(?!).
This occurs when the
for index,element in pairs(myTable) do
loop has an index above 2^24 (16’777’216).
This usually is not a problem, but I stumbled upon it and thought I would share it.
Poor example but I hope you get the gist.
I do not know how to report this so I report it as a bug, I am mostly telling you this so you can watch out for it too.
Haha well I have tried making my first “game” wich includes making circles at the touch of the user. Very simple and for the people I have viewed this for they could sit with it for a good 15min.
Anyways, I got a variable called TotalRings, wich is as its name prefers: it holds the number of rings ever created since the app started. (When a ring is created: TotalRings = TotalRings + 1)
I also used this for my index of each ring.
function touched(touch)
TotalRings = TotalRings + 1
table.insert(circles,TotalRings,{"ring, wich x,y pos and more"})
end
(The touched() function is a bit more complex in the original code)
This makes so when I draw it using a “for each pair” loop it draws them, as requested.
But if TotalRings is above 2^24 then each index will also be, so the for loop apperently fucks up, in one way or another.
This makes the rings instead of expanding like they should they just show up as dots, dosent have time to expand. Or maybe they expand faster then I can see. It’s really hard to test.
Now using the console I could easily change the TotalRings as I wanted (TotalRings=anynumber).
And I found out that this acting started when TotalRings are above 16’777’216 (found that out with a lot of testing ).
It must be something with either the start number of total rings or how you increment it. If as you say the rings are created on touch, and let’s say for each touch you create 100 rings.
So some simple maths would suggest I can create 100 rings per frame at 60 frames per second for just over 44 minutes before this would blow up. I’m sure your app could be refactored to avoid this even, assuming you don’t leave all rings ever on screen, but I’m sure your increment is happening a lot more than just on touch.
@spacemonkey This will clear some things up for ya! http://youtu.be/XKdoV3md5UU
The video is currenly being controlled, but when it’s finished you can see how the mechanics works.
The game creates a ring at the touch of the user with a color generated with the touch id as seed. The ring got a certain variable of life left until it evaporates (disappears). As this and the opacity decreases the size expands. When the “life” left is below zero, it’s destroyed.
I also added a pause function, just for fun. I will soon add stuff like color selection or to choose the speed of wich the rings destroy in.
I got loads of plant, but this is a bug report, so I’ll leave this subject a bit.
@akaJag so just to check, you’ve flagged a bug, do you still have an issue with this in your app? If so I could suggest some strategies based on your video, if not… keep on coding
@spacemonkey I have not yet fixed it, so if someone sits there and makes circles for a little more then 2 days then the game will start to act differently, therefore the “bug”. And that is with 1 finger.
Alternately, if you do destroy the items out of the table, which I assume you do otherwise your performance would die before the integer does, just reset the integer at 1 million back to 1, it’ll start filling the table from entry 1 again. And by the time it reaches a million I’m sure your early circles will already be gone.