I have been implementing the multiplayer cloud and have been running into a limitation in the multiplayer handler. I want to be able to run different code blocks from the handler based on the calling code block… I have not figured out a good way to do this… #1 option I came up with was to use a global variable, which I would rather not do. The second option was to modify corona_cloud_code.lua to accept a variable event.type so that I can have custom event.type’s for each calling code block… This is what I did:
I added the source parameter to the cloud core… This lets me run a differerent event.type for each code block…
function coronaCloudController.getRecentMoves(matchID, limit, source) local params = "auth\_token="..coronaCloudController.authToken local path = "matches/"..matchID.."/get\_recent\_moves.json" -- Force get all moves params = params.."&criteria=all" -- Check if limit provided, if so add param if (limit ~= nil) then params = params.."&move\_count="..limit end -- set currentUser when it gets it local function networkListener(event) if (event.isError) then if coronaCloudController.debugEnabled then print(coronaCloudController.debugTextPrefix .. "Network Error") print(coronaCloudController.debugTextPrefix .. "Error: "..event.response) end return false else if coronaCloudController.debugEnabled then print(coronaCloudController.debugTextPrefix .. "Recent Match Moves: "..event.response) end local response = json.decode(event.response) -- Decode content - Convenient! -- TODO: Need to made it iterate through all moves, -- not just one. if (response[1] ~= nil) then if coronaCloudController.debugEnabled then print(coronaCloudController.debugTextPrefix .. "Decoding Content") end response[1].content = \_b64dec(response[1].content) end if source == nil then Runtime:dispatchEvent({name="Multiplayer", type="RecentMoves", results=response}) else Runtime:dispatchEvent({name="Multiplayer", type=source, results=response}) end end end \_getCC(path, params, networkListener) end
Obviously I don’t want to have to keep track of changes to this file as corona updates it…
#1, does anyone have a better idea?
#2, This would seem to be an easy to make addition to all of these functions to make them move flexible. Corona?