Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MitchellNZ · Nov 29, 2012 at 07:46 AM · ienumeratorstartcoroutine

StartCoroutine and IEnumerator's - Multiple usage of function

Hi guys,

I am trying to build a database using PHP as the database and C# in Unity. I am running into a problem using the StartCoroutine() function on my IEnumerator function.

Here is my code snip-it of the areas I am having trouble:

 public class GUIShopMenus : MonoBehaviour {
     void OnGUI (){
         if (checkPurchase) {
             GUI.BeginGroup( new Rect(Screen.width/2 - 100, Screen.height/2 - 50, 200, 100));
                 GUI.Box( new Rect(0,0,200,100), "");
                 GUI.Label( new Rect(45,10,110,60), "Are you sure you?");
                 
                 if (GUI.Button( new Rect(20,60,70,30), "Yes")) {
                     StartCoroutine(Database_Controller.PurchaseAttemptDatabase(Player_Controller.Character.GetUser(), item, itemType));


and the Database_Controller.PurchaseAttemptDatabase() function:

 static public IEnumerator PurchaseAttemptDatabase (string user, int item, int itemType)
     {
         string accessKey = Md5Sum(user + secretKey);
         string updateKey = Md5Sum(item + itemType + secretKey);
  
         string post_url = database + "accessKey=" + accessKey + "&user=" + WWW.EscapeURL(user) + 
             "&function=purchaseItemAttempt" + "&updateKey=" + updateKey + "&item=" + item + "&itemType=" + itemType;
  
         // Post the URL to the site and create a download object to get the result.
         WWW hs_post = new WWW(post_url);
         yield return hs_post; // Wait until the download is done
 
         if (hs_post.error != null)
         {
             Debug.Log("There was an error purchasing this item: " + hs_post.error);
         } else {
             if (hs_post.text.Length != 0) {
                 if (IsReturnCharacterInfo(hs_post.text)) {
                     string characterInfo = GetInfoFromReturn(hs_post.text);
                     SetPlayerController(characterInfo, user);
                     
                     //For testing
                     Debug.Log(Player_Controller.Character.PrintInfo());
                 } else {
                     Debug.Log(hs_post.text);
                 }
             } else {
                 Debug.Log("Not enough coins!");
             }
         }
     }

What I am trying to do is use the function Database_Controller.PurchaseAttemptDatabase() each time I want to add a new item that the use has to the database.

EDIT: I am calling the Database_Controller.PurchaseAttemptDatabase() function each time the user clicks a button, and I am passing it different parameters for each button that is clicked. But it only seems to work the first time, on the first button click. After that, nothing happens on the other button clicks.

E.G: Both use the OnGUI function above, but may pass different parameters like this:

Button One -> StartCoroutine(Database_Controller.PurchaseAttemptDatabase(user = "Bob", item = 12, itemType = 1))

Button Two -> StartCoroutine(Database_Controller.PurchaseAttemptDatabase(user = "Bob", item = 34, itemType = 4))

Is there anyway I can do this?

Any help would be much appreciated, Thanks! :)

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DeveshPandey · Nov 29, 2012 at 08:22 AM 0
Share

I am getting confused because you have written a line "and the Player_Controller.Character.GetUser() function:" but you actually paste the another function that is "PurchaseAttemptDatabase ". So clearly tell me what you want to do?

avatar image MitchellNZ · Nov 29, 2012 at 07:51 PM 0
Share

Sorry, I have updated the question to make more sense, I was talking about the function I posted, the: Database_Controller.PurchaseAttemptDatabase() function.

avatar image MitchellNZ · Nov 30, 2012 at 01:44 AM 0
Share

So I have discovered that the "Debug.Log()" functions only work once.. But my "SetPlayerController(characterInfo, user)" function is working as intended each call (even though the "Debug.Log(Player_Controller.Character.PrintInfo())" function wont output afterwards).

Why is this?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Brain exploding ... Problem with an internal Coroutine manager 3 Answers

Jerky camera when using IEnumerator 0 Answers

IEnumerator only called once 3 Answers

Non-invocable member "IEnumerator" cannot be used like a method. Start StartCoroutine from other script ?? 1 Answer

yield return M() vs yield return StartCoroutine 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges