GGData Question

I’ve just moved over to analysing GGData - seems straight and to the purpose, so thumbs up from me.

However I’m struggling to get my data stored as I need it.

I essentially want the data to be stored like this:

Episode 1
-----> Unlocked - true
------------>levelNum - 1
----------------->fileName - “game1”
----------------->highScore - “999”
------------>levelNum - 2
----------------->fileName - “game2”
----------------->highScore - “999”

Episode 10
-----> Unlocked - false
------------>levelNum - 91
----------------->fileName - “game91”
----------------->highScore - “999”
------------>levelNum - 92
----------------->fileName - “game92”
----------------->highScore - “999”

However with the following code I’m not getting quite what I need:

for i=1,10 do  
 local unlocked = "false"   
 if ( i==1 ) then unlocked = "true" end --ensure that the first world is unlocked on creation  
 for j=1,10 do  
 box:set("episode"..i, {  
 unlocked = unlocked,  
 levelNum = j,  
 fileName = "game"..j,  
 highScore = 0  
 })  
 end  
 unlocked = false  
end  

I can understand why I’m getting the flatter data then what I need, but I can’t seem to work out how to fix it. Hopefully Graham (awesome libraries) or somebody au-fait with GGData/JSON might be able to shed some light.

UPDATE

Looking at the GGData library I’m not even certain whether I can use this multi-nested data structure, as it seems as though it’s setup for a simple key/value approach. [import]uid: 33275 topic_id: 34964 reply_id: 334964[/import]

Seem to have got it fixed using the following code:

for i=1,10 do  
 local unlocked = "false"   
 if ( i==1 ) then unlocked = "true" end --ensure that the first world is unlocked on creatio  
  
  
 for j=1,10 do  
 levels =   
 {  
 levelNum = j,  
 fileName = "game"..j,  
 highScore = 0  
 }  
  
 data[j] =   
 {  
 unlocked = unlocked,  
 levelData = levels  
 }  
 end  
  
 box:set("episode"..i, data)  
  
 unlocked = false  
end  

If somebody thinks that looks wrong, please let me know. [import]uid: 33275 topic_id: 34964 reply_id: 138995[/import]

If it works, it’s not wrong :slight_smile:

What you could do as a test is hard code some data exactly how you want it and try to store that out, see if it works as expected. [import]uid: 119420 topic_id: 34964 reply_id: 139002[/import]

Thanks Graham - I’m kind of getting there, facing the issue of the lack of order with associative arrays in Lua now. I’m trying to create a stage select screen from the data structure, but the lack of a guaranteed order is really biting me in the bum.

Think I might have to restructure the data and perhaps rather then have things under “episode1”, keep to a simple array structure that I can iterate over reliably. It’s obviously not as nice when debugging, but I can’t think of anyway around it.

P.S did I say how amazing these libraries are :slight_smile: [import]uid: 33275 topic_id: 34964 reply_id: 139005[/import]

For the order issues could you give things an index value or something then you can always sort the resulting tables based on that.

Glad you like them, we have more coming as and when we create them :slight_smile: [import]uid: 119420 topic_id: 34964 reply_id: 139068[/import]

Seem to have got it fixed using the following code:

for i=1,10 do  
 local unlocked = "false"   
 if ( i==1 ) then unlocked = "true" end --ensure that the first world is unlocked on creatio  
  
  
 for j=1,10 do  
 levels =   
 {  
 levelNum = j,  
 fileName = "game"..j,  
 highScore = 0  
 }  
  
 data[j] =   
 {  
 unlocked = unlocked,  
 levelData = levels  
 }  
 end  
  
 box:set("episode"..i, data)  
  
 unlocked = false  
end  

If somebody thinks that looks wrong, please let me know. [import]uid: 33275 topic_id: 34964 reply_id: 138995[/import]

If it works, it’s not wrong :slight_smile:

What you could do as a test is hard code some data exactly how you want it and try to store that out, see if it works as expected. [import]uid: 119420 topic_id: 34964 reply_id: 139002[/import]

Thanks Graham - I’m kind of getting there, facing the issue of the lack of order with associative arrays in Lua now. I’m trying to create a stage select screen from the data structure, but the lack of a guaranteed order is really biting me in the bum.

Think I might have to restructure the data and perhaps rather then have things under “episode1”, keep to a simple array structure that I can iterate over reliably. It’s obviously not as nice when debugging, but I can’t think of anyway around it.

P.S did I say how amazing these libraries are :slight_smile: [import]uid: 33275 topic_id: 34964 reply_id: 139005[/import]

For the order issues could you give things an index value or something then you can always sort the resulting tables based on that.

Glad you like them, we have more coming as and when we create them :slight_smile: [import]uid: 119420 topic_id: 34964 reply_id: 139068[/import]