@Luatee, weird it’s working fine for me. Try this code atleast for three loops, I get the same results even if the FPS drops from 60 to 12.
supportedOrientations(PORTRAIT_ANY)
function setup()
--clearLocalData()
font("Courier")
loop=0
tab1={}
tab2={}
restart=true
fps = 60
parameter.watch("fps")
NumberOfCollisions = 5
print("Number Of Collisions Before Check = 5")
print("change this value in setup if you wish too.")
print("clear LocalData if you change the value")
end
function setup2()
tab2={}
count=0
loop=loop+1
print("loop: "..loop)
if b1 then
b1:destroy()
b2:destroy()
e1:destroy()
e2:destroy()
e3:destroy()
e4:destroy()
end
WIDTH = 768
HEIGHT = 1024
e1=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
e2=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
e3=physics.body(EDGE,vec2(WIDTH,HEIGHT),vec2(WIDTH,0))
e4=physics.body(EDGE,vec2(WIDTH,0),vec2(0,0))
b1=physics.body(CIRCLE,60)
b1.gravityScale=0
b1.restitution=1
b1.linearDamping=0
b1.linearVelocity=vec2(380,700)
b1.x=200
b1.y=600
b1.friction=0
b2=physics.body(CIRCLE,60)
b2.gravityScale=0
b2.restitution=1
b2.linearDamping=0
b2.linearVelocity=vec2(620,450)
b2.x=400
b2.y=200
b2.friction=0
end
function draw()
fps = .9*fps + .1/DeltaTime
background(40,40,50)
textMode(CORNER)
if restart then
setup2() -- setup for the physics objects
restart=false
end
if loop == 3 then
for i = 1,5 do
print("Drop FPS")
end
end
noFill()
strokeWidth(4)
stroke(255)
ellipse(b1.x,b1.y,120)
ellipse(b2.x,b2.y,120)
fill(255)
text("x,y loop 1 x,y loop 2,3,4 etc.",100,1000)
text("loop "..loop,600,1000)
text("Shows the x,y position every 5 collisions for 100 collisions.",100,300)
text("Retains the values for loop 1 to compare to loops 2,3,4, etc.",100,260)
text("White fill represents that it mathches the previous value.",100,220)
text("Red fill represent the value doesnt match.",100,180)
text("Local data is saved to check values of first loop.",100,140)
for a,b in pairs(tab1) do
pushStyle()
if readLocalData("tab1x"..a) == b.x and readLocalData("tab1y"..a) == b.y then
fill(255, 255, 255, 255)
else
fill(255, 0, 0, 255)
end
text(b.x.." "..b.y,100,HEIGHT-50-a*20)
popStyle()
end
for a,b in pairs(tab2) do
pushStyle()
if b.x == tab1[a].x and b.y == tab1[a].y then
fill(255, 255, 255, 255)
else
fill(255, 0, 0, 255)
end
text(b.x.." "..b.y,300,HEIGHT-50-a*20)
popStyle()
end
text(fps, WIDTH - 100, HEIGHT - 50)
end
function collide(c)
if c.state==BEGAN then
count = count + 1
if count%NumberOfCollisions == 0 then
if loop==1 then
table.insert(tab1,vec2(b1.x,b1.y))
if readLocalData("tab1x"..#tab1) == nil then
print("Saved Values")
saveLocalData("tab1x"..#tab1, b1.x)
saveLocalData("tab1y"..#tab1, b1.y)
else
print("Checked Values")
end
end
if loop>1 then
table.insert(tab2,vec2(b1.x,b1.y))
end
end
if count==20*NumberOfCollisions then
restart=true
end
end
end