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 Kalu · Jan 14, 2012 at 07:37 PM · c#coroutinewwwsuspend

suspend a function time to recover a data C#

I need to recover a number of furniture (by querying a MySQL database) and then use that number to run other querys on a second database. My problem now is that the first query retrieves the number of good furniture but the function continues to run while this number has not yet been returned by the php script. Suddenly, the "for" loop does not run. (n_meuble is still at '0' when 'for' try to loop) So I need help to suspend the "gal_of_library" function until the IEnumerator "get_num_meuble" returns the value of "n_meuble".

 private int n_meuble;
 private ArrayList gal_tab;
 public ArrayList gal_of_library(){
     mssg_debug = mssg_debug+" GAL_OF_LIB  =>  ";
     gal_tab = new ArrayList();
     n_meuble = 0;
     StartCoroutine(get_num_meuble());//récupére le nombre de meuble
     for(int n_mbl = 0; n_mbl < n_meuble; n_mbl++){
         mssg_debug = mssg_debug+" launch for, to getsingledatameuble ";
         StartCoroutine(get_singledata_meuble(n_mbl));//pour chaque meuble, récupére une image et un id_meuble lié à
     }                                                                    //un ensemble de planche dans une autre table
     return gal_tab;
 }
 private IEnumerator get_num_meuble(){
     string get_url = get_n_meuble;
     WWW hs_get = new WWW(get_url);
     yield return hs_get;
     if (hs_get.error != null){
         mssg_debug = mssg_debug+"There was an error getting the dataMeuble: "+hs_get.error;
     }else{
         string s_nmeuble = hs_get.text;
         n_meuble = int.Parse(s_nmeuble);//renseigne le nombre de meuble
         mssg_debug = mssg_debug+" n_meuble = "+n_meuble;
     }
 }
 private IEnumerator get_singledata_meuble(int n_mbl){
     string get_url = get_data_meuble+"?n_meuble="+n_mbl;
     WWW hs_get = new WWW(get_url);
     yield return hs_get;
     
     if (hs_get.error != null){
         mssg_debug = mssg_debug+"There was an error getting the dataMeuble: "+hs_get.error;
     }else{
         ArrayList couple_tab;
         string get_content = hs_get.text;
         string[] complete_sentence = get_content.Split('|');
         foreach (string part_sentence in complete_sentence){
             couple_tab = new ArrayList();//couple de données (image/id_meuble)
             string[] words = part_sentence.Split(',');
             foreach (string word in words){
                 mssg_debug = mssg_debug+word;
                 couple_tab.Add(word);
             }
             gal_tab.Add(couple_tab);//tab (contenant des tableaux de couple) pour générer la galerie cotés 'Main'(GUI)
         }    
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Kalu · Jan 22, 2012 at 02:44 AM

Complete with this, the function order is important, it's the second IEnumerator which call the first one. Could help someone else

 private IEnumerator get_Tabdata_meuble(){
     string get_url = get_data_meuble;
     WWW hs_get = new WWW(get_url);
     yield return hs_get;
     
     if (hs_get.error != null){
         mssg_debug = mssg_debug+"There was an error getting the dataMeuble: "+hs_get.error;
     }else{
         ArrayList couple_tab;
         string get_content = hs_get.text;
         string[] complete_sentence = get_content.Split('|');
         foreach (string part_sentence in complete_sentence){
             if(part_sentence == ""){ break; }//si le morceau de phrase analysé est vide, break
             couple_tab = new ArrayList();//couple de données (image/id_meuble/name_meuble)
             string[] words = part_sentence.Split(',');
             mssg_debug = mssg_debug+"||  données  ||";
             foreach (string word in words){
                 couple_tab.Add(word);
                 mssg_debug = mssg_debug+" |-| Words => "+word;
             }
             gal_tab.Add(couple_tab);//tab (contenant des tableaux de couple) pour générer la galerie cotés 'Main'(GUI)
         }
     }
 }
 
 public IEnumerator gal_of_library(){
     gal_tab = new ArrayList();
     n_meuble = 0;
     yield return StartCoroutine(get_Tabdata_meuble());//suspend l'execution en attendant gal_tab
     mssg_debug = mssg_debug+" || gal_tab.Complete ==> "+gal_tab.Count;
     Main otherScript = GetComponent<Main>();
     otherScript.send_galtab(gal_tab);
 }
Comment
Add comment · Share
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
0

Answer by Kalu · Jan 16, 2012 at 07:49 AM

iiiii need help! or another way to do this..

Comment
Add comment · Share
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

XElement loop through elements in IEnumerator 1 Answer

Coroutine needed here? 1 Answer

Using MiniJSON 1 Answer

WWW isDone when lost internet connection, it return true and not wait for internet connection (Andriod) 1 Answer

WWW Image Loading Fails When Directory Contains "+" Character 0 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