A Parse.com Module for Corona SDK

I followed the Avatar tutorial and keep receiving an error:

Runtime error: mod_parse.lua:348: type ‘function’ is not supported by JSON

The function in the mod_parse.lua that the error line is on is:

function Parse:buildRequestParams( withDataTable, masterKey )
  local postData = json.encode( withDataTable )

  return self:newRequestParams( postData, masterKey ) --for use in a network request

end

I printed the fileObjId and it comes out to a really long string:

dc21190f-f7a0-4979-9dc3-971c6cba525b-exImage.png

The Parse side saves the userID, username and the password but the avatar is still undefined.

I do have the image in the Resource Directory also.

Thanks for the quick response on the last comment btw.

Thanks scottshaw3d, I’ll take a look. You can file bug reports here as well: https://bitbucket.org/develephant/mod_parse/issues/new

Cheers.

Figured it out… Now you also need the fileObjURL in parse:linkFile… not shown in the video.

fileObjId = event.response.name

fileObjURL = event.response.url

print( userObjId )

print( fileObjId )

print( fileObjURL )
       

local function onFileLinked( event )
    if not event.error then
         print( “Yeah” )
    end

end

parse:linkFile( parse.USER, userObjId, “avatar”, fileObjId, fileObjURL, onFileLinked )

@scottshaw3d Yes, that was just recently updated in the latest version.

 

I guess I need to update the video as well.  Thanks for pointing that out.  My apologies for the confusion.

 

Cheers.

Thanks! It will be disable/enabling ads globally. Basically I want to be able to release paid apps with ads embedded (but turned off in the ad dashboard) Then later I want to set the app free (so to get a spike in DL) At that time, of course I will turn the ad ON (from the ad network dashboard) so people who downloaded the app for free are shown  ads. BUT of course in this case the people who paid for the app will be shown ad also which is a NO NO!

Not sure I make any sense!

Mo

Can you please add userLogout method to your module?

Regards,

Damir.

Hi, first off this module looks fantastic! I plan on trying it out once I’m done my current project.

When do you think you’ll be doing a turn-based multiplayer tutorial?

Hi spowell83,

The issue is no ability to enable push on Android via the Parse REST API at this time.  Without a persistent connection, we need to have an ability to ping the user.  A lazy poll is too expensive to run on an API that has a limit.  So, it’s on hold for now.

Best.

Hey Develephant…

Quick question on mod_parse that I hope you might be able to help with - also before I forget to say, excellent module.

I’m trying to save data to Parse upon the user exiting the app - however I fear that it’s not completing before the app is closed.

I’ve debugged through the code and I just want to make sure where the actual request to Parse.com is made. I have noticed that my code gets through to Parse:updateObject() and ultimately Parse:sendRequest() - the latter of which I can see the network.request is stored in a table. Is the request made here, or is that table called later?

Unfortunately the callback from the request isn’t made before the app is closed - and the Parse object doesn’t appear to be updated. I’m presuming the network request isn’t being made where I assume it to be, however I’m a little bit stumped on creating a workaround at the moment.

Any help would be appreciated…

Hi SegaBoy,

Yes, the network request is made when it’s entered into the table.  Once the request finalizes, the request id is searched for in the originating table, and then the callback is triggered.

I’m guessing that once the app starts to exit, the network calls are blocked?, though I don’t know this for certain.

I assume you’re attempting to save the data on an “applicationExit” system event? Let me know where you’re calling it and I can take a look.

Cheers.

Hey Develephant - yeah its on an applicationExit, I’m trying to save game state. I think your suggestion is probably correct, so might have to think of a different solution if that’s the case.

I have a function in my GameController class, which is called upon applicationExit:

[lua]

function Game:saveDataToParse()
    print(“saveDataToParse”)
    self.m_pMap:saveToParse()
    self.m_ItemManager:saveItems()
end

[/lua]

The interesting thing is that the call to saveItems (executed after the Parse call) is a save that does so to a local file, all of these save as expected - so I have two assumptions: it’s either not making the network request in time, or as you’ve suspected then network calls have been disabled.

Ultimately I’m trying to replicate the functionality of games such as The Simpsons: Tapped Out, where game state is saved regardless of how the user exits the app.

Thanks again for looking into this for me…

Hi SegaBoy,

Well oddly when just calling the module directly in the system event listener it’s saving fine.

[lua]local function onSystemEvent( event )
  if event.type == “applicationExit” then
    parse:createObject( “State”, { [“user”] = “Jimbo” } )
  elseif event.type == “applicationSuspend” then
    parse:createObject( “State”, { [“user”] = “Timbo” } )
  end
end

Runtime:addEventListener( “system”, onSystemEvent )[/lua]

Perhaps there are too many “hops” to the Parse call and the event “tick” is closing before it gets there?

Seems strange…

Can you please add userLogout method to your module?

Regards,

Damir.

Hey Develephant…

Quick question on mod_parse that I hope you might be able to help with - also before I forget to say, excellent module.

I’m trying to save data to Parse upon the user exiting the app - however I fear that it’s not completing before the app is closed.

I’ve debugged through the code and I just want to make sure where the actual request to Parse.com is made. I have noticed that my code gets through to Parse:updateObject() and ultimately Parse:sendRequest() - the latter of which I can see the network.request is stored in a table. Is the request made here, or is that table called later?

Unfortunately the callback from the request isn’t made before the app is closed - and the Parse object doesn’t appear to be updated. I’m presuming the network request isn’t being made where I assume it to be, however I’m a little bit stumped on creating a workaround at the moment.

Any help would be appreciated…

Hi SegaBoy,

Yes, the network request is made when it’s entered into the table.  Once the request finalizes, the request id is searched for in the originating table, and then the callback is triggered.

I’m guessing that once the app starts to exit, the network calls are blocked?, though I don’t know this for certain.

I assume you’re attempting to save the data on an “applicationExit” system event? Let me know where you’re calling it and I can take a look.

Cheers.

Hey Develephant - yeah its on an applicationExit, I’m trying to save game state. I think your suggestion is probably correct, so might have to think of a different solution if that’s the case.

I have a function in my GameController class, which is called upon applicationExit:

[lua]

function Game:saveDataToParse()
    print(“saveDataToParse”)
    self.m_pMap:saveToParse()
    self.m_ItemManager:saveItems()
end

[/lua]

The interesting thing is that the call to saveItems (executed after the Parse call) is a save that does so to a local file, all of these save as expected - so I have two assumptions: it’s either not making the network request in time, or as you’ve suspected then network calls have been disabled.

Ultimately I’m trying to replicate the functionality of games such as The Simpsons: Tapped Out, where game state is saved regardless of how the user exits the app.

Thanks again for looking into this for me…

Hi SegaBoy,

Well oddly when just calling the module directly in the system event listener it’s saving fine.

[lua]local function onSystemEvent( event )
  if event.type == “applicationExit” then
    parse:createObject( “State”, { [“user”] = “Jimbo” } )
  elseif event.type == “applicationSuspend” then
    parse:createObject( “State”, { [“user”] = “Timbo” } )
  end
end

Runtime:addEventListener( “system”, onSystemEvent )[/lua]

Perhaps there are too many “hops” to the Parse call and the event “tick” is closing before it gets there?

Seems strange…

Our team is new to Corona, just have a quick question we are getting the error below when we try to insert and get Objects, but we are able to insert. 

Super thanks in advance :slight_smile:

 Runtime error

/Users/joeleya/Desktop/parse/mod_parse.lua:881: attempt to concatenate global ‘err’ (a table value)

stack traceback:

/Users/joeleya/Desktop/parse/mod_parse.lua:881: in function ‘onResponse’

/Users/joeleya/Desktop/parse/mod_parse.lua:772: in function </Users/joeleya/Desktop/parse/mod_parse.lua:772>

May 20 00:22:59.058: Runtime error

/Users/joeleya/Desktop/parse/mod_parse.lua:881: attempt to concatenate global ‘err’ (a table value)

stack traceback:

/Users/joeleya/Desktop/parse/mod_parse.lua:881: in function ‘onResponse’

/Users/joeleya/Desktop/parse/mod_parse.lua:772: in function </Users/joeleya/Desktop/parse/mod_parse.lua:772>

Thank you for the module. 

I am also getting an error of all things json.decode. This is an example of a response that returns an error inside the mod_parse as invalid response. It is valid json according to two online validators. Also if I run this same string through json.decode any place else in the code it works. Any help would be appreciated.

{  
   “authData”:{  
      “facebook”:{  
         “access_token”:"<myAccessToken>",
         “expiration_date”:“2015-07-20T03:20:49.000Z”,
         “id”:"<myId>"
      }
   },
   “createdAt”:“2015-05-21T03:20:55.697Z”,
   “objectId”:“FLPwNVUndI”,
   “sessionToken”:“r:<sessiontoken>”,
   “updatedAt”:“2015-05-21T18:36:05.180Z”,
   “username”:"<myUsername>"
}