Hello Chris,
I am trying to create and save a player account to a server.
I succesfully created a menu system that asks for email and password, and stores them inside global variables.
Now I'm trying to write a custom Action to call the function that posts data to a server.
I have this function working, but I need to pass some parameters and I don't know how, using Object -> send Message.
IEnumerator AddUser( string email, string password){
string hash = Utilities.Md5Sum(email + password + secretKey);
string post_url = addUserURL +
"email=" + WWW.EscapeURL(email) + "&password=" + WWW.EscapeURL(password) + "&hash=" +hash;
print (post_url);
WWW hs_post = new WWW(post_url);
yield return hs_post;
if(hs_post.error != null){
print ("There was an error adding user: " + hs_post.error);
}
}
This function is called like this:
void Run_AddUser(string email, string password){
StartCoroutine(AddUser(email, password));
}
How to call this function from AC?
Thank you
Comments
Instead, you'd have to write a custom Action that does it instead. See the tutorial here. In your Run() function, you'd call the Run_AddUser function in your other script, e.g:
myOtherScript.Run_AddUser ("email@email.com", "thepassword").
Making sure that Run_AddUser is a public function, and that myOtherScript is a reference to your custom script.
You could then replace your two string fields with e.g. global variables:
string email = GlobalVariables.GetStringValue (2); // Global variable with ID = 2
string password = GlobalVariables.GetStringValue (2); // Global variable with ID = 3
myOtherScript.Run_AddUser (email, password);
Do a test with a GameObject - no need to do anything with it in Run(), just get the UI to work. Your code follows the same structure as other Actions, so it's not apparent from your code why it doesn't work.
I tried several times, renamed the script to 'ServerScript', restarted Unity, but the reference disappears as soon as I start the game.
serverScript.GetComponent<ServerScript>().Run_AddUser(GlobalVariables.GetStringValue(11), GlobalVariables.GetStringValue(12));
}
Thank you!