Need help with simple user creation script.

0 votes

I'm brand new to this and I followed the documentation but idk what I did wrong -

 

.81640625using UnityEngine;

using UnityEngine.SocialPlatforms;

using System.Collections;

using System.Collections.Generic;

using System.Net;

using System;

using com.shephertz.app42.paas.sdk.csharp;

using com.shephertz.app42.paas.sdk.csharp.user;

using AssemblyCSharp;

 

 

public class Users : App42CallBack  

{  

private string userName; 

private string pwd;  

private string emailid;

 

 

    public void OnSuccess(object response)

    {  

        User user = (User) response;  

        /* This will create user in App42 cloud and will return User object */    

        App42Log.Console("userName is " + user.GetUserName());  

        App42Log.Console("emailId is " + user.GetEmail());   

    }  

 

    public void OnException(Exception e)  

    {  

        App42Log.Console("Exception : " + e);  

    }  

 

void OnGUI(){

 

userName = GUI.TextField(new Rect(30, 30, 300, 50), "Username");

pwd = GUI.TextField(new Rect(30, 80, 300, 50), "Password");

emailid = GUI.TextField(new Rect(30, 130, 300, 50), "Email");

if(GUI.Button(new Rect(100, 30, 100, 50), "Create Account"))

{

userService.CreateUser(userName, pwd, emailId,new UnityCallBack());  

}

}

}

All I want right now is to figure out how to create a user, I get this error 

 

error CS0103: The name `userService' does not exist in the current context

asked Feb 23, 2014 in App42 Cloud API-BaaS by JoeCrill (25 points)

1 Answer

0 votes

Here is a complete script for the same. Also, use UserResponse file for call back response. 

Place your API_KEY and SECRET_KEY  at line # 30 (sp = new ServiceAPI ("YOUR_API_KEY","YOUR_SECRET_KEY");) to initialize it.

using UnityEngine;
using UnityEngine.SocialPlatforms;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System;
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.user;
using AssemblyCSharp;
 
public class UserTest : MonoBehaviour
{
ServiceAPI sp = null;
UserService userService = null; // Initializing User Service.
User createUserObj = null;
 
public string success;
UserResponse callBack = new UserResponse ();
 
#if UNITY_EDITOR
public static bool Validator (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{return true;}
#endif
void Start ()
{
#if UNITY_EDITOR
ServicePointManager.ServerCertificateValidationCallback = Validator;
#endif
sp = new ServiceAPI ("YOUR_API_KEY","YOUR_SECRET_KEY");
}
 
 
void OnGUI ()
{
 
if (Time.time % 2 < 1) {
success = callBack.getResult ();
}
 
// For Setting Up ResponseBox.
GUI.TextArea (new Rect (10, 5, 1300, 175), success);
 
//=========================================================================
if (GUI.Button (new Rect (50, 200, 200, 30), "Create User")) {
userService = sp.BuildUserService (); // Initializing UserService.
string userName  = "App42TestUser";
string password = "password";
string email = "App42TestUser@shephertz.com";
userService.CreateUser (userName, password, email, callBack);
}
 
}
}
 

 

answered Feb 23, 2014 by ajay123 (899 points)
edited Feb 23, 2014 by ajay123
Ok thanks now I'm getting this error :/

A field initializer cannot reference the nonstatic field, method, or property `Users.serviceAPI'
I don't know what half that stuff means, I just want them to be able to make a username password and email, nothing else. and in the unity editor when I run that script nothing gets written in the text field and I get errors when I click any button.
I have edited my post for required script
Alright cool, it created the user. Now where should I go from here to make a login screen, and if I want to implement these users in with my photon networking
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...