Good evening everyone,
I’m facing an issue I couldn’t find anything about on the forum. As usual I’m pretty sure I’m doing something wrong, somewhere.
I need to locally store a huge string with saveGlobalData. The code I wrote seems working fine, but whatever is displayed while it saves, it freezes. Once the storing operation has completed then it turns running fine at 60fps. In this case, I made a simple rotating loader. but it freezes either way
I admit it : it is not a big issue that the screen freezes for a bunch of seconds, but since I’m learning I’m also willing to know if there’s anything wrong I am doing.
I’m posting here the code, even though i think it may be pointless as it does not contains the table self.level1 content that makes it freezing ( as it is filled in at run time while the first level is being played).
However, is there anything you notice that could be wrong in the first place?
Sorry for the long post and thank you for your valuable time.
Regards
function setup()
gt = GhostTracker()
at = Atom(WIDTH/2,HEIGHT/2)
at:Show()
end
function draw()
background(40, 40, 50)
at:draw()
end
Atom = class()
local Atom_State = 1
local Intro_Timer = 0
Intro_Status = 0
local Atom_Incremental = 0
local Angle = 0
local Angle_Incremental = 0
local Check_Step = 0
local Intro_Cantouch = 0
function Atom:init(x,y)
self.x = x
self.y = y
end
function Atom:draw()
if Atom_State == 0 then
Atom_Incremental = Atom_Incremental + 1
if Atom_Incremental == 300 then
self:Show()
gt:SaveTracker()
self:Hide()
end
spritePos = vec2( WIDTH-100, 50 )
pushMatrix()
translate(spritePos.x, spritePos.y)
if Angle_Incremental < 3 then
Angle_Incremental = Angle_Incremental + 0.01
end
Angle = Angle + 1 + Angle_Incremental
if Angle >= 360 then
Angle = 0
end
rotate(Angle)
sprite("Planet Cute:Tree Short", 0, 0,60)
popMatrix()
pushStyle()
fill(255,255,255,255)
text("Saving level information",spritePos.x,spritePos.y+50)
popStyle()
end
end
function Atom:Show()
Atom_State = 0
end
function Atom:Hide()
Atom_State = 1
end
GhostTracker = class()
local TextPosLoop = 0
local SaveDone = 0
local postcontent = ""
local cnt = 0
function GhostTracker:init()
self.level1 = {}
self.level2 = {}
end
function GhostTracker:draw(x,y,b,f)
table.insert(self.level1,GhostProperties(x,y,b,f))
end
function GhostTracker:SaveTracker()
if SaveDone == 0 then
for i,v in ipairs(self.level1) do
cnt = cnt + 1
postcontent = postcontent..v.x..";"..v.y..";"..v.b..";"..v.f.."|"
end
saveGlobalData("lv1",postcontent)
end
tint(255,255,255,255)
text(cnt,WIDTH/2,HEIGHT/2)
SaveDone = 1
end
GhostProperties = class()
function GhostProperties:init(x,y,b,f)
self.x = x -- posX
self.y = y -- posY
self.b = b -- shootbullet?
self.f = f -- frame
end