Dmc_Autostore Question?

So, firstly it seems like an  excellent library - as you’d expect from DMC :slight_smile:

 

I’m having a few troubles trying to retrieve data however, and hope somebody who’s using it might be able to help.

 

I initiate the structure in main.lua like so:

 

[lua]

 

local function initializeAutoStore()

 

    – check here to see if we’ve already initialized the data structure

    –

    if not AutoStore.is_new_file then return end

 

 

    --== new data file, initialize the data structure ==–

 

    – get a reference to the root of the data structure

    – right now ‘data’ is an empty, “magic” table, eg {}

    local data = AutoStore.data

 

    – add empty container to the tree in which to store our UFO objects

    data[‘powerups’] = {}

 

    – add some data to our new tree

    data.powerups[‘1’] = { name=“A”, id=1, quantity=0 }

    data.powerups[‘2’] = { name=“B”, id=2, quantity=0 }

    data.powerups[‘3’] = { name=“C”, id=3, quantity=0 }

    data.powerups[‘4’] = { name=“D”, id=4, quantity=0 }

    data.powerups[‘5’] = { name=“E”, id=5, quantity=0 }

    data.powerups[‘6’] = { name=“F”, id=6, quantity=0 }

    – save some app specific info

    – perhaps our data version, eg, in case the structure needs to change in the future

    – or a secret key, etc

    --data[‘app_info’] = { data_version=‘1.0’, secret={ id=“124”, key=“F5@E$sj1” } }

    – Yes, all of those changes will be automatically saved

    – and there’s no “.save()” in sight !

 

end

 

function main()

   initializeAutoStore()

end

[/lua]

 

In a later file I’m trying to retrieve it:

 

[lua]

 

local AutoStore = require( “dmc_autostore” )

 

local classPowerUp = {}

local classPowerUp_metatable = {__index=classPowerUp}

 

function classPowerUp.new()

    local powerUps = AutoStore.data.powerups

    local data = powerUps[‘1’]

    print(“STOP”)

end

 

return classPowerUp

 

[/lua]

 

However there is never the data in either powerUps or data. I’ve stepped through the library and noticed a few things:

 

a) the JSON file is being created properly and storing the data accurately.

b- it seems to be passing nil in the addPixieDust() function.  Even though I can find my data nestled deep within the structure, proxy is always being returned as nil and so this

 

[lua]

self.data = addPixieDust( json.decode( content ) )

[/lua]

 

Always comes back empty. I’ve noticed the library makes extensive use of metatables, so perhaps this is being stored in different tables - but I just can’t seem to access it. I guess I’m doing something stupid in my initialisation or attempts to retrieve the data - hoping somebody can point this out.

 

Many thanks,

hey SegaBoy !

i just happened to find this issue of yours. did you ever get it worked out ?

i was going to test your code, but though that maybe you moved on or got it sorted.

yes, there is extensive use of metatables in autostore, so you can’t just *peer* into the autostore structure. however, if the JSON file is being written out correctly then the data is there in autostore.

your code looks fine. did you ever try to just do “print( data.name, data.id, data.quantity )” where you have print(“STOP”) ?

LMK

cheers,
dmc

hey SegaBoy !

i just happened to find this issue of yours. did you ever get it worked out ?

i was going to test your code, but though that maybe you moved on or got it sorted.

yes, there is extensive use of metatables in autostore, so you can’t just *peer* into the autostore structure. however, if the JSON file is being written out correctly then the data is there in autostore.

your code looks fine. did you ever try to just do “print( data.name, data.id, data.quantity )” where you have print(“STOP”) ?

LMK

cheers,
dmc