Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

error : "cannot be an iterator block because `void' is not an iterator interface type

Discussion in 'Scripting' started by jbarrett98121, Jul 19, 2012.

Thread Status:
Not open for further replies.
  1. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    ok, so i've been trying to convert a javascript file to c#... believe i have it mostly done, only one error now, of a type that i haven't run accross yet..... any help, the error in paticular is coming from line 103 :

    error CS1624: The body of `GnomeAmmoScript.SamplePoints(UnityEngine.Transform)' cannot be an iterator block because `void' is not an iterator interface type




    line 103 : void SamplePoints ( Transform thisTransform ){

    ?

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class GnomeAmmoScript : MonoBehaviour {
    6.  
    7.     private float stationaryTime;
    8.     public bool bHasBeenShot;
    9.     public bool bHasShouted;
    10.     public AudioClip boing;
    11.     public AudioClip yipee;
    12.     public AudioClip woohoo;
    13.     public int AudioFile;
    14.     public int BounceAudioFile;
    15.     public AudioClip[] BounceAudioList;
    16.     public AudioClip[] AudioList;
    17.     private AudioSource audioSource;
    18.     public bool destroyed = false;
    19.    
    20.     // trajectory path variables
    21.    
    22.     public Material lineMaterial;
    23.     public int maxPoints = 500;
    24.     public bool continuousUpdate = true;
    25.     public GameObject ballPrefab;
    26.     public VectorLine pathLine;
    27.     public int pathIndex = 0;
    28.     public Vector3[] pathPoints;
    29.     public bool running = true;
    30.    
    31.     // Use this for initialization
    32.     void Start () {
    33.        
    34.      pathPoints = new Vector3[maxPoints];
    35.      pathLine = new VectorLine("Path", pathPoints, lineMaterial, 12.0, LineType.Continuous);
    36.    
    37.      SamplePoints (ballPrefab.transform);
    38.        
    39.        
    40.        
    41.        
    42.        
    43.        
    44.         bHasBeenShot = false;
    45.         bHasShouted = false;
    46.         audioSource = GetComponent<AudioSource>();
    47.     }
    48.    
    49.     void OnCollisionEnter(Collision collision) {
    50.         audioSource.Stop();
    51.         BounceAudioFile = Random.Range(0,BounceAudioList.Length);
    52.         audio.clip = BounceAudioList[BounceAudioFile];
    53.         audio.Play ();
    54.         //audioSource.clip = boing;
    55.         //audioSource.Play();
    56.     }
    57.     // Update is called once per frame
    58.    
    59.    
    60.  
    61.  
    62.    
    63.    
    64.  
    65.  
    66.    
    67.    
    68.    
    69.    
    70.    
    71.    
    72.    
    73.    
    74.     void Update () {
    75.         if (bHasBeenShot  !bHasShouted)
    76.         {
    77.             bHasShouted = true;
    78.             //audioSource.Stop();
    79.            
    80.             AudioFile = Random.Range(0,AudioList.Length);
    81.             audio.clip = AudioList[AudioFile];
    82.             audio.Play();
    83.             //audioSource.clip = (Random.value > 0.5f) ? yipee : woohoo;
    84.             //audioSource.Play();
    85.         }
    86.  
    87.         if (bHasBeenShot  rigidbody.velocity.magnitude < 0.2f)
    88.         {
    89.             // Don't update the stationary time
    90.             if ((Time.time-stationaryTime) > 1.0f)
    91.             {
    92.                 Destroy(gameObject);
    93.                 destroyed = true;
    94.             }
    95.         }
    96.         else
    97.         {
    98.             stationaryTime = Time.time;
    99.         }
    100.     }
    101.  
    102.  
    103.  
    104. void  SamplePoints ( Transform thisTransform  ){
    105.     running= true;
    106.     while (running) {
    107.         pathPoints[pathIndex] = thisTransform.position;
    108.         if (++pathIndex == maxPoints) {
    109.             running = false;
    110.         }
    111.         yield return new WaitForSeconds(.05);
    112.        
    113.         if (continuousUpdate) {
    114.             DrawPath();
    115.         }
    116.    
    117.     if (destroyed == true)
    118.         {
    119.        
    120.                 Vector.DestroyLine(pathLine);
    121.             }
    122.    
    123.     }
    124. }
    125.  
    126. void  DrawPath (){
    127.     if (pathIndex < 2) return;
    128.     pathLine.maxDrawIndex = pathIndex-1;
    129.     Vector.DrawLine (pathLine);
    130.     Vector.SetTextureScale (pathLine, 1.0f);
    131. }
    132.    
    133. }
     
    Last edited: Jul 19, 2012
  2. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    Westland likes this.
  3. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    so i replace void with StartCoroutine ? when i do that i get another error.....

    "The type or namespace name `StartCoroutine' could not be found. Are you missing a using directive or an assembly reference?"

    i've only used yeild in javascript so this is new to me formatting it and using it in c#...

    StartCoroutine(SamplePoints ( Transform thisTransform )) {
    etc....
    }
    causes a ton of errors.
     
    Last edited: Jul 19, 2012
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    no, you replace void with IEnumerator
     
    MushyBees and Skrollex like this.
  5. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    thanks. that seems to be working maybe.... but caused a ton more errors not related to that paticular line.... but wth

    pathLine = new VectorLine("Path", pathPoints, lineMaterial, 12.0, LineType.Continuous);

    errors like
    "
    The best overloaded method match for `VectorLine.VectorLine(string, UnityEngine.Vector3[], UnityEngine.Material, float, LineType)' has some invalid arguments
    "

    "The best overloaded method match for `UnityEngine.WaitForSeconds.WaitForSeconds(float)' has some invalid arguments"

    those did not show up when i was using void instead of IEnumerator
     
  6. kingcharizard

    kingcharizard

    Joined:
    Jun 30, 2011
    Posts:
    1,137
    Code (csharp):
    1. yield return new WaitForSeconds(.05);
    add a f after the .05

    also I cannot find VectorLine in the docs

    not saying it isn't there I just cant find it and i never used it so maybe someone else can help you farther

    That is because the function type was more important that these errors now that your type is right these errors need be addressed...
     
    Last edited: Jul 19, 2012
    MushyBees likes this.
  7. jbarrett98121

    jbarrett98121

    Joined:
    Jan 3, 2011
    Posts:
    251
    yeah i don't know really. this is all part of the vectrosity package.

    all i'm really wanting to do, as you have seen from my recent posts is destroy the trajectory line (VectorLine) that follows the ammo object. the line was handled by a js script seperate from the script that handles the trajectory path.... so after trying to pass variables between scripts un successfuly i just decides to combine the scripts into one script.... but... one was in js, and one was in c#.. so converting all the js has been a major pain in the ass, and all i'm really wanting to do is check a damn variable from an outside script.

    i've made it into way more of a hassle than it needs to be i'm pretty sure.


    here's the real problem i'm having :
    http://forum.unity3d.com/threads/144227-Checking-variable-conditions-between-seperate-script-files.

    that's all i'm trying to solve.
     
    Last edited: Jul 19, 2012
  8. dyc3

    dyc3

    Joined:
    Jan 31, 2014
    Posts:
    1
    Make the varible you want to share public and call the varible in c# like so:

    C#:
    Code (csharp):
    1. public object example = fooClass.bar;
    bar is the varible, fooClass is the JS class, example is just an example varible. you can change object to your liking.
     
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,778
    I've always assumed that necroposters were just being careless and simply didn't realize the thread was old. But here you are, aware of it, and just.... posting anyway?
     
    Sheepee, Johan_Liebert123 and Bunny83 like this.
Thread Status:
Not open for further replies.