Translating to Boo, need help

Hey I’ve wrote some JS scripts but because I’m interested in Boo I decided to take some of my JS scripts and translate them to Boo and then compare them.

I’m having trouble with something I know has a super-simple solution. Here is what I can’t seem to translate to Boo without an error:

var othercube:GameObject;
othercube=GameObject.Find("OtherCube");

This is what I wrote when I tried to translate it to Boo:

othercube:GameObject
othercube=GameObject.Find("OtherCube")

I need to know what the proper translation is…

Thanks for the help. Sorry to bother the forums with something that must be very simple.

othercube as GameObject
othercube = GameObject.Find("OtherCube")

However, that’s unnecessarily verbose…in JS you’d just write

var othercube = GameObject.Find("OtherCube");

and Boo is

othercube as GameObject = GameObject.Find("OtherCube")

–Eric

Ok I did it how you said but I’m still getting this error:

UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.
If you are using C# don’t use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function.

BooGetOtherCube…ctor () (at Assets\BooGetOtherCube.boo:3)

Here is the entire set of code that gets the error, what’s wrong with it?

The error is line 3

import UnityEngine
class BooGetOtherCube(MonoBehaviour): 
	othercube as GameObject = GameObject.Find("OtherCube")
	def Awake():
		for i in range(100):
			othercube.transform.Rotate(0,1,0)
			yield WaitForSeconds(0.01)

This code isn’t meant for anything, it’s just a bunch of random nonsense I wrote to see how things work in Boo.

Thanks

I’ve been reading the Support section of Unity3d.com (Manual, Reference, Scripting, and other such sections) for 3-4 days straight now. I’ve probably read 100-200 pages and I think that’s a low estimate. But I just can’t find enough Boo documentation to fix this problem.

I didn’t realize that code was outside any functions. Generally outside functions you should stick to declaring variables only, and “do stuff” (like GameObject.Find) inside functions.

	othercube as GameObject

	def Awake():
		othercube = GameObject.Find("OtherCube")

–Eric

That makes sense, thanks for the tip.

But I still have a problem. These two bits of code should do the same thing when I run the game:

Java:

function Awake(){
	Rotate_Self();
	}
function Rotate_Self(){
	var othercube:GameObject=GameObject.Find("OtherCube");
	for(i=0;i<1000;i++){
		othercube.transform.Rotate(0,3,6);
		yield WaitForSeconds(0.01);
		}
	}

Boo:

import UnityEngine
class BooRotate(MonoBehaviour): 
	def Awake():
		Rotate_Self()
	def Rotate_Self():
		othercube as GameObject=GameObject.Find("OtherCube")
		for i in range(1000):
			othercube.transform.Rotate(0,3,6)
			yield WaitForSeconds(0.01)

When I attach the Javascript version to a GameObject and run the game, the game object ‘OtherCube’ starts rotating. When I replace the Javascript version with the Boo version, I run the game and…Nothing happens. There are no errors it’s just that no rotation occurs.

Got any help for me? Thanks.

Note: I even put print(“Rotate Self Called”) in the top of Rotate_Self() in the Boo code, and it doesn’t even print that, so Rotate_Self() isn’t even getting called. If I put a print() in the top of def Awake() it does show that. I’m confused.

Coroutines in Boo are like C#, in that they’re more complicated to use compared to JS:

import UnityEngine
import System.Collections

class BooRotate(MonoBehaviour): 
   def Awake(): 
      StartCoroutine(Rotate_Self())
   def Rotate_Self() as IEnumerator: 
      othercube as GameObject=GameObject.Find("OtherCube") 
      for i in range(1000): 
         othercube.transform.Rotate(0,3,6) 
         yield WaitForSeconds(0.01)