I’m working in an OpenFeint solution to VC storage. But I would like for Corona to have the option, in the upload and download Blob, for listeners for both failed and succeeded actions.
I use the propertybag( http://developer.anscamobile.com/code/propertybag-class-coronasdk ) for local storage and create this default values:
[lua]propertyBag:getProperty ( “OFVC_first”, “true” ) --false after making the first OF connection
propertyBag:getProperty ( “VC_in”, “0” ) --the VC to be added at sync.
propertyBag:getProperty ( “VC_out”, “0” ) --the VC to be taken at sync. [/lua]
And then I just call my OFVC() function to sync.
[lua]--------------------------------------
– OFVC OpenFeint Virtual Currency
function OFVC()
if propertyBag:getProperty ( “OFVC_first” ) == “true” then --First time of device using OFVC
local check_OFVC_firstListener = function(event)
if event.blob ~= 0 then – if there’s previously saved online VC
propertyBag:setProperty ( “FP”, event.blob ) – replace local VC. I call it FP. I think there’s going to be some problems if users play a lot and then they have their local VC replaced. A window asking which one of the states is preferred mabe? Showing the VC and items in each account?
propertyBag:SaveToFile()
end
propertyBag:setProperty ( “OFVC_first”, “false” )
propertyBag:SaveToFile()
notification.notify(“FP From the Cloud”,“OFVC_first = false”); --just for simple device debugging
return true
end
gameNetwork.request( “downloadBlob”, “ofFP”, check_OFVC_firstListener ) – download to see if there’s any previously saved online VC
elseif propertyBag:getProperty ( “OFVC_first” ) == “false” then – Not first time using OFVC
local function cleanVC_in_out() --resets VC so we don’t double upload. Could really use the listeners for failed upload
propertyBag:setProperty ( “VC_in”, “0” )
propertyBag:setProperty ( “VC_out”, “0” )
propertyBag:SaveToFile()
end
–We use updatedINOUT to added it to our downloaded VC.
local updatedINOUT = propertyBag:getProperty ( “VC_in” )-propertyBag:getProperty ( “VC_out” )
local updateOFVCListener = function(event)
local updatedOFVC = event.blob + updatedINOUT --We add(in) and take(out) VC to end up with the same local and online VC.
if updatedINOUT > 0 then
gameNetwork.request( “uploadBlob”, “ofFP”, updatedOFVC )
performAfterDelay( 0.2, cleanVC_in_out, 1, true, “cleanVC_in_out”) – This should only be called if the upload was succesful. Which is very likely to happen when updateOFVCListener is only called once the downloadBlob is done.
notification.notify(“OpenFeint saved”,“your VC is saved in your OF account!”);
end
return true
end
gameNetwork.request( “downloadBlob”, “ofFP”, updateOFVCListener ) --1. Download total VC from OF. I call it ofFP.
end–OFVC_first
end --OFVC function[/lua]
So imagine this scenario:
- You download the game, login into OF and make VC=250.
- You delete the game, lose local info and then reinstall.
- You login into OpenFeint, download.Blob updates your local VC to 250.
– I realize here we should maybe ask the user if they want to recover VC from online backup and lose everything else.
- You play offline, and get VC_in=200 from playing or IAP, and VC_out=150 (saved with propertybag) from buying items.
So your localVC= 250 +200-150 =300
- OFVC function downloads the previous VC=250 and adds up 200-150=50. Then uploads.Blob the new 300VC. We don’t upload the total local VC, so we don’t lose VC gained from other devices(Pad). I still don’t update the localVC if this happens, we need the option to set listeners for both failed and succeded uploads of blobs.
I’m missing many scenarios, It would be really helpful if I could get feedback on several problems that may occur given certain actions.
PS. Using http://developer.anscamobile.com/code/notification-popup for notifications
[import]uid: 10426 topic_id: 13920 reply_id: 58492[/import]