How to show/delete Global data?

Hello all,

How can I show all stored global data (i.e. saveGlobalData()) ?

Also what about deleting some stored global data?

In case of non jailbreaked device :slight_smile:

Try this. It will list all your global data. Tap the names you want to delete. They’ll turn red and the “Press button to delete” will turn yellow. After you selected all the ones you want to delete, tap the “Press button to delete”. It will delete all the ones you selected and turn back to green. This will have to be modified if you have a lot of global data.

EDIT: I modified the fist program to allow you to scroll the list up or down and select what to delete. Just don’t scroll up or down close to the list or you’ll select data to delete.


function setup()
    yy=0
    displayMode(FULLSCREEN)
    supportedOrientations(PORTRAIT)
    saveProjectInfo("Description", "List/Delete global data")
    w=WIDTH/2
    listGlobal()
end

function listGlobal()
    dataTab={}
    yTab={}
    selTab={}
    for x,y in pairs(listGlobalData()) do
        table.insert(dataTab,y)
        table.insert(yTab,980-x*45)
        table.insert(selTab,false)
    end
end

function draw()
    background(40, 40, 50)
    fill(255)
    text("Select global data to delete",w,1000)
    text("- - - - - - - - - - - - - - - - - - - - -",w,970)
    toDelete=0
    for z=1,#dataTab do
        fill(255)
        if selTab[z] then
            toDelete=1
            fill(255,0,0)
        end
        str=readGlobalData(dataTab[z])
        text(dataTab[z].."  "..str,w,yTab[z]+yy)
    end
    fill(0, 244, 0, 255)
    if toDelete==1 then
        fill(245, 255, 0, 255)
        text("Press button to delete",130,880)
    end
    rect(100,900,50,50)
end

function touched(t)
    if t.state==MOVING then
        yy=yy+t.deltaY
    end
    if t.state==BEGAN then
        if t.x>100 and t.x<150 and t.y>900 and t.y<950 then
            for z=1,#dataTab do
                if selTab[z] then
                    saveGlobalData(dataTab[z],nil)
                end
            end
            if toDelete then
                listGlobal()
            end
        end
        for z=1,#yTab do
            if t.y-yy>yTab[z]-20 and t.y-yy<yTab[z]+20 and t.x>250 and t.x<500 then
                selTab[z]=not selTab[z]
            end
        end
    end
end

If you want to see all your global data, this will show it. To delete global data, just use saveGlobalData(name,nil) where name is the global data key you want to delete.


function setup()
    a=listGlobalData()
    for x,y in pairs(a) do
        print(y,readGlobalData(y))
    end
end

Thank you, very clear

@aosama - I did a tute on this a while ago as well: http://codeatuts.blogspot.com.au/2012/09/tutorial-17-simple-file-manager-for.html