saveGlobalData question

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.

function setup()
gt = GhostTracker()
at = Atom(WIDTH/2,HEIGHT/2)

function draw()
    background(40, 40, 50)


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

function Atom:draw()
if Atom_State == 0 then
    Atom_Incremental = Atom_Incremental + 1
    if Atom_Incremental == 300 then
        spritePos = vec2( WIDTH-100, 50 )
        translate(spritePos.x, spritePos.y)
            if Angle_Incremental < 3 then
                Angle_Incremental = Angle_Incremental + 0.01
        Angle = Angle + 1 + Angle_Incremental
        if Angle >= 360 then
            Angle = 0
        sprite("Planet Cute:Tree Short", 0, 0,60)

        text("Saving level information",spritePos.x,spritePos.y+50)

function Atom:Show()
    Atom_State = 0
function Atom:Hide()
    Atom_State = 1

GhostTracker = class()
local TextPosLoop = 0
local SaveDone = 0
local postcontent = ""
local cnt = 0
function GhostTracker:init()
    self.level1 = {}
    self.level2 = {}

function GhostTracker:draw(x,y,b,f)

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.."|" 

    SaveDone = 1

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

it sounds as though the saving operation is taking a while. How big is your string? Does it really need to be so big? Can you split it into several strings and spread the saving over several draw operations?

Hi @Ignatz, thanks for your reply. As I asked time ago here in the forum, I was on the need to record each, and every player movement while playing a certaing level. And the code I wrote seems doing it quite fine fine, exept for the freezing thing whilst saving. Once the table is filled with the string, I use it afterwards to read other player movements to display a ghost player on the screen. So to reply your question, yes the string happens to be quite huge as it keeps players coordinates on the screen in the form of a csv. If I split it I have to put my hands on the read mechanism that currently runs flawlessly :frowning:
But I believe you’re right ( as usual )

The quick solution I thought : saving without any animation running in the background :slight_smile:

ps. Today I’ll be trying to get a sample of the first level csv to post it here.

@deactive - why don’t you save the string in pieces? For example, you could add to the string normally, and when it reaches a certain size, eg 5,000 characters, you save the first 5,000 characters, and remove them from the string. You could use the same name for all the saved pieces, with a number on the end, eg Save001, Save002, …

This means your string stays small, and saving it is quick. When you need to read the string back into memory, you can read in one piece at a time in sequence, and as you get to the end, you can read the next piece. This should make reading it back quicker as well.


why didn’t I think of this before? I’m deffo going to give this a try today.
I expect several but shorter freezes while saving.

thanks, @Ignatz

@deactive Have you thought about using a file. You can append each move to the file which wouldn’t take any time at all. No need to keep track of string size or multiple names.