Hi everybody!
I just started developing a turn-based game with corona. I have created a simple game logic that first creates a match using a matchmaking system and then throws the users to another screen with a button, that ends their respective turns when they have taken their respective decissions. I’m having a few drawbacks in the execution:
First off, I’m using corona to develope my game client and a lua based web service to attend my server side. I have two web services, one for the matchmaking system and the other to check whose turn is. The server handles all the data via a mongoDB with JSON namespaces.
The matchmaking simply searches any created game with only one player. If it doesn’t find any searching player then it creates a match with the searching player as the first player, and waits untill another player starts searching. Once a match has been found, the clients show the other screen where the “pass turn” button is. The fist player is marked as the active player, and while one player is active, the other is polling the database for feedback of his turn, then it is notificated to the player via a native.showAlert dialog.
The fact is, that the time it takes to end one player’s turn and send the notification to the other is taking much more than expected in some cases. I have detected that sometimes during execution the servers registers some slow queries (and it really it shouldn’t, I’m querying a very small database with few parameters).
Here is the code to my Turn web service:
function main(web, req) local params = web:params() local msg = "" local cutoff = os.time() + 2 if(params["player"] ~= nil) then if(params["gameID"] ~=nil) then if(params["check"] == "turncheck") then moai.logger:debug("Turn is checked") while os.time() < cutoff do local cursor = mongodb:query('currentGames',{game_id=tonumber(params.gameID),active_player=params.player}) if(cursor:has_more()) then msg = "ctns" break end -- the sleep is put here so you don't hammer the database. posix.sleep(1) end elseif(params["check"] == "turnover") then moai.logger:debug("Turn is over") mongodb:update('currentGames',{game_id=tonumber(params.gameID)},{['$set']={active_player=params.player}},false,false) msg = "ctnn" posix.sleep(1) end end end web:page(json.encode(msg),200,'OK')end[/code]Thanks in advance for your help, it's really much appreciated. [import]uid: 193170 topic_id: 33233 reply_id: 333233[/import]