Hi!
I just got the Unity trial yesterday and have been cramming it into my brain. I’m familiar with python, but I never got into Java-types or C-types, so I figure I’ll be more comfortable with Boo.
Unfortunately, as is well known, all of the example scripts are in Javascript, and while I’m able to translate a good amount of it into Boo, I’m still not completely fluent in boo, so I miss things.
which gives a variable exposed in the inspector that you can drag an object onto, to reference.
I translated that into this for boo:
import UnityEngine
class Camscript (MonoBehaviour):
public test as GameObject;
def Start ():
pass
def Update ():
test.transform.Translate(0,1,0);
Which seems to work fine, apart from the fact that it gives me the error “UnityException: You are not allowed to call this function when declaring a variable.”
Can anyone tell me why that error pops up, and how I can fix it? The script doesn’t seem to run improperly.
Thats the full console exception. I’ve been able to largely ignore it since it doesn’t hinder runtime, but I’ve hit another obstacle caused by it. As of now, it refers to line six in the following code:
After a while of paying no mind to the error, I couldn’t figure out why my ‘zpos’ toss was returning an empty vector to the higher powers. I fiddled with the process a bit, broke the position grab to a second line, and only recently discovered that the error found on line 6 would prevent the transform from being found, much less moved along the variables.
A more confusing matter to me is this: in debugging, I added the ‘chcount’ variable to count children (of which there are two), and it’s always read as 0. So this object, for whatever reason, does not accept the responsibility of parenthood.
This isn’t an insurmountable problem, since the ‘zpos’ I’m going for is really only +(0,20,0) consistently, so I can throw that static variable up instead… but I expect that it’d only be delaying an inevitable impasse if I can’t find a true solution.
p.s.
While the chcount shows no children, the broadcast does find its way to them. the chcount declaration is probably errored in the same way as the zoomtarget declaration… =P
Basically, when declaring global variables, you just want to stick to declaring them and not “run code” on them. You’d write that as
class sc_sselect (MonoBehaviour):
zoomtarget as Transform
def Start ():
zoomtarget = transform.Find("zoom")
And generally you don’t want to ignore errors. If you click on the error (which will only be the most recent one), it will bring up the console which shows all errors.
While I had hoped that boo retained the ease of instant declaration that python has, I thought it might be something like that, what with a few warnings here and there in Unity about constructor fields and the start() field, so I rearranged things like so:
import UnityEngine
class sc_sselect (MonoBehaviour):
zpos as Vector3 //<----- same error
chcount as int
clicked as bool
selected as bool
def Start():
zpos = transform.Find("zoom").position
chcount = transform.childCount
clicked = false
selected = false
def OnMouseDown():
clicked = true;
def Update():
if clicked:
SendMessageUpwards("CamZoom",zpos)
BroadcastMessage("CamZoom")
clicked = false;
selected = true;
zoomout = Input.GetKey("space")
if zoomout:
selected = false
SendMessageUpwards("CamReset")
BroadcastMessage("CamReset")
if selected:
SendMessageUpwards("StarLock",zpos)
I still get the error, referring me to the zpos declaration.
When I get rid of variables, trying to make it simpler, it’ll even point the error to the bool declarations. Once it pointed to a blank line between the pass of the start(), and the def update(). All in all I’m starting to feel rather gullible, like the code is teasing me :roll:.
I tried with semicolons, and without. I’ll bet it’s something right in front of my nose. Thank you for all your effort!
So I think a lot of that was me looking up the same error, after it was fixed.
you’re absolutely right, and it seems to work just fine now. Thanks so much!