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

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 ){

?

using UnityEngine;
using System.Collections;

public class GnomeAmmoScript : MonoBehaviour {

	private float stationaryTime;
	public bool bHasBeenShot;
	public bool bHasShouted;
	public AudioClip boing;
	public AudioClip yipee;
	public AudioClip woohoo;
	public int AudioFile;
	public int BounceAudioFile;
	public AudioClip[] BounceAudioList;
	public AudioClip[] AudioList;
	private AudioSource audioSource;
	public bool destroyed = false;
	
	// trajectory path variables 
	
	public Material lineMaterial;
	public int maxPoints = 500;
	public bool continuousUpdate = true;
	public GameObject ballPrefab;
	public VectorLine pathLine;
	public int pathIndex = 0;
	public Vector3[] pathPoints;
	public bool running = true;
	
	// Use this for initialization
	void Start () {
		
	 pathPoints = new Vector3[maxPoints];
	 pathLine = new VectorLine("Path", pathPoints, lineMaterial, 12.0, LineType.Continuous);
	
	 SamplePoints (ballPrefab.transform);
		
		
		
		
		
		
		bHasBeenShot = false;
		bHasShouted = false;
		audioSource = GetComponent<AudioSource>();
	}
	
	void OnCollisionEnter(Collision collision) {
		audioSource.Stop();
		BounceAudioFile = Random.Range(0,BounceAudioList.Length);
		audio.clip = BounceAudioList[BounceAudioFile];
		audio.Play ();
		//audioSource.clip = boing;
		//audioSource.Play();
	}
	// Update is called once per frame
	
	


	
	


	
	
	
	
	
	
	
	
	void Update () {
		if (bHasBeenShot  !bHasShouted)
		{
			bHasShouted = true;
			//audioSource.Stop();
			
			AudioFile = Random.Range(0,AudioList.Length);
			audio.clip = AudioList[AudioFile];
			audio.Play();
			//audioSource.clip = (Random.value > 0.5f) ? yipee : woohoo;
			//audioSource.Play();
		}

		if (bHasBeenShot  rigidbody.velocity.magnitude < 0.2f)
		{
			// Don't update the stationary time
			if ((Time.time-stationaryTime) > 1.0f)
			{
				Destroy(gameObject);
				destroyed = true;
			}
		}
		else
		{
			stationaryTime = Time.time;
		}
	}



void  SamplePoints ( Transform thisTransform  ){
	running= true;
	while (running) {
		pathPoints[pathIndex] = thisTransform.position;
		if (++pathIndex == maxPoints) {
			running = false;
		}
		yield return new WaitForSeconds(.05);
		
		if (continuousUpdate) {
			DrawPath();
		}
	
	if (destroyed == true)
		{
		
				Vector.DestroyLine(pathLine);
			}
	
	}
}

void  DrawPath (){
	if (pathIndex < 2) return;
	pathLine.maxDrawIndex = pathIndex-1;
	Vector.DrawLine (pathLine);
	Vector.SetTextureScale (pathLine, 1.0f);
}
	
}

yield requires IEnumerator, not void. You call it using StartCoroutine ( SamplePoints() ).

http://docs.unity3d.com/Documentation/ScriptReference/index.Coroutines_26_Yield.html

1 Like

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.

no, you replace void with IEnumerator

2 Likes

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

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…

1 Like

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.

Make the varible you want to share public and call the varible in c# like so:

C#:

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.

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?

3 Likes