Forum BigDB Still need AS3 syntax help (save object to PlayerObjects)

Discussion and help relating to the PlayerIO database solution, BigDB.

Still need AS3 syntax help (save object to PlayerObjects)

Postby kuvi » August 4th, 2013, 4:34 pm

The following refers to library functions defined in:
http://playerio.com/documentation/refer ... erio.bigdb
http://playerio.com/documentation/refer ... baseobject

Hi guys its been several days and no substantial reply to my previous post so I'm going to present the information differently.

I am fairly new to database basics -- by looking at multiple examples on this website I am now able to successfully retrieve objects and use their properties in my game (using load()) i.e. I've completed my LogIn screen where it will search for a players name and match their stored password to the one provided.

Using that example I was even able to create a submit button (using createobject) where it will instantiate a new username.key for the table, Password property, and Experience: 0 property.

Now since I'm new to a lot of these functions I did the same thing any person would do: I picked the first one i got to work and flew with it, in this case its _client.bigDB.load("PlayerObjects", profilename, FunctionIfObjectExistsAndSendObjectAsParameter) now this is a great syntax I learned because it allows me to do a magnitude of things, but its limiting factor is its only useful for read-only applications. I now have a list of pending functions that rely on being able to save to the playerio objects database.

<THIS IS WHAT I NEED HELP WITH>
The first and easiest one I want to do is saving experience, just learning this will teach me what I need for the other functions. This will just be a simple retrieve, add 23 experience, and save to databaseobject routine. I've got a clean read-in routine setup:

_client.bigDB.load("PlayerObjects", MrSmith, onSuccess)

public function onSuccess(MrSmithObject) {
trace(MrSmithObject.Experience) //"150"
MrSmithObject.Experience += 23

/*
(Now here's the thing, there's no save on the first link provided, so I'm trying to figure out how to apply the save object method from the second link, "DatabaseObject.save" claims "Save the object to the database.", this isn't located in bigDB, but instead the .DataBaseObject library, and the definition: save(useOptimisticLocks:Boolean = false, fullOverwrite:Boolean = false, callback:Function = null, errorHandler:Function = null):void seems to lack a field to put the physical object into. The following is what i *think* should work??)
*/

dataBaseObject.save(false, false, MrSmith.Experience, null)
//if anyone could provide the correct syntax for what I'm trying to do above I would be most grateful


}
kuvi
 
Posts: 11
Joined: March 29th, 2011, 12:32 am

Re: Still need AS3 syntax help (save object to PlayerObjects

Postby Henrik » August 5th, 2013, 5:31 pm

When you load the object you get it back in the success callback, like you discovered.

The save method exists on the actual Databaseobject, and when you call that, the object is saved. You don't pass the object into the save method, or pass in properties, you just call the method, and the entire object is saved. Internally, it figures out which properties have changed and send in a small changeset that then gets written to the database.

The third and fourth parameters are callbacks, so when you've saved an object, either the success callback will be called, or the error callback gets called. If you don't care about knowing when and if the object was saved, you can just omit those.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to BigDB