I require a database with about 12 custom db columns for my game. Being a newbie to this world can you provide me with step by step instructions on how to achieve the same along with script templates? Please help.
Why do you need to add fields in the database instead of using the customData hashtable?
You can easily create your own class inheriting from User and internally use customData for your properties, click here for a sample code.
After you have called Authenticate<YourUserClass> then you can safely cast CombuManager.localUser to YourUserClass later.
FRANCESCO CROCETTI @ SKARED CREATIONS
Can you please give me step by step instructions to do the same? I am total scripting noob.
Another thing, how many simultaneous connections does combu need to have with the database?
The link I posted above already contains a detailed explanation and a sample code of a custom class derived from User (section "Create your User class" in that page). You will find the demo class CombuDemoUser also in the Combu package (under /Combu/Demo/Scripts).
About database connection, well it depends on your traffic but since the connections are opened and closed pretty quickly in the web services then you shouldn't have any issue about it.
FRANCESCO CROCETTI @ SKARED CREATIONS
Thanks, will try it out.
// Authenticate userCombuManager.platform.Authenticate <CombuDemoUser> ( "username", "password", (bool success, string error) => {if (success)Debug.Log("Success");elseDebug.Log("Failed: " + error);});// Create new userCombuDemoUser newUser = new CombuDemoUser();newUser.userName = "username";newUser.password = "password";newUser.myProperty1 = "Value";newUser.myProperty2 = 100;newUser.Update( (bool success, string error) => {// NB: registration does not make the user loggedif (success)Debug.Log("Save success: ID " + newUser.id);elseDebug.Log("Save failed: " + error);});
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SocialPlatforms;
using Combu;public class CombuPlayer: MonoBehaviour {
public class CombuPlayerDetails : Combu.User
{
string _Name = "";
int _Age = 0;
string _School = "";
string _Class = "";
string _Address = "";
string _Gender = "";
string _guardianName = "";
string _guardianEmail = "";public string Name
{
get { return _Name; }
set { _Name = value; customData["Name"] = _Name; }
}public int Age
{
get { return _Age; }
set { _Age = value; customData["Age"] = _Age; }
}public string School
{
get { return _School; }
set { _School = value; customData["School"] = _School; }
}public string Class
{
get { return _Class; }
set { _Class = value; customData["Class"] = _Class; }}
public string Gender
{
get { return _Gender; }
set { _Gender = value; customData["Gender"] = _Gender; }
}public string guardianName
{
get { return _guardianName; }
set { _guardianName = value; customData["guardianName"] = _guardianName; }
}public string guardianEmail
{
get { return _guardianEmail; }
set { _guardianEmail = value; customData["guardianEmail"] = _guardianEmail; }
}public CombuPlayerDetails()
{
_Name = "";
_Age = 0;
_School = "";
_Class = "";
_Address = "";
_Gender = "";
_guardianName = "";
_guardianEmail = "";
}public override void FromHashtable(Hashtable hash)
{
// Set User class properties
base.FromHashtable(hash);
// Set our own custom properties that we store in customData
if (customData.ContainsKey("Name"))
_Name = customData["Name"].ToString();
if (customData.ContainsKey("Age"))
_Age = int.Parse(customData["Age"].ToString());
if (customData.ContainsKey("School"))
_School = customData["School"].ToString();
if (customData.ContainsKey("Class"))
_Class = customData["Class"].ToString();
if (customData.ContainsKey("Address"))
_Address = customData["Address"].ToString();
if (customData.ContainsKey("Gender"))
_Gender = customData["Gender"].ToString();
if (customData.ContainsKey("guardianName"))
_guardianName = customData["guardianName"].ToString();
if (customData.ContainsKey("guardianEmail"))
_guardianEmail = customData["guardianEmail"].ToString();
}
}
}
This is the custom script I have created but I cant understand hot to post the data to the database.
No you shouldn't put CombuPlayerDetails inside a Monobehavior, because CombuPlayerDetails should be only a class container and not being attached to a gameobject. So just delete the line "public class CombuPlayer: MonoBehaviour {" and the latest "}" so that it becomes similar to the demo class CombuDemoUser.
About where to place the Authenticate code, well you need to call it where your game/app requires the authentication, for example as click handler of a UI button etc. If you look at the demo scene CombuDemo then you'll see that it's called in the method CombuDemo.UserLogin that is attached to the "On Click" event of the UI button "Button Login" (hierarchy: Canvas/Login/SettingsWindow/Button Login).
FRANCESCO CROCETTI @ SKARED CREATIONS
And how do I post the custom data to the database? If the script is not attached to a gameobject how do add it to my submit button?
To store the properties in the database you need to call Update on the user object, for example after you have authenticated the user with Authenticate (through a login UI) you can access the local authenticated user with:
// Cast localUser to your custom class, requires to have called Authenticate() var myUser = (CombuPlayerDetails)CombuManager.localUser; myUser.Name = "Hercules"; myUser.Age = 18; myUser.Update( (bool success, string error) => { Debug.Log("Save success: " + success); });
I didn't understand the other question about "submit button", but for login you have to create a script with a public method where you call Authenticate (similar to CombuDemo.UserLogin) and assign this method to your button "On Click". I mean this is standard UI management, if you're new to Unity then I'd suggest to follow some tutorials about Unity UI and usage of Text and Button components.
FRANCESCO CROCETTI @ SKARED CREATIONS
Actually I want to collect the user submitted data in my database. After a couple of fields there is a submit button. But is capturing the data possible only after authentication?
Think of it as an elaborate Registration process.
The point of my post was: if you need to edit the profile then you need to Authenticate first and then use the Update on your localUser like the code I put above, while if you're registering a new account then instantiate a new CombuPlayerDetails() object in the first line of that code instead of casting localUser (of course you'll need to set also the username and password besides the other properties during registration, that your player will use later in the login form).
FRANCESCO CROCETTI @ SKARED CREATIONS
All apologies, my mistake, I was not precise enough in the description of my requirements. Thanks for all the help you extending.