Boo - Stuck on Lerpz Tutorial (StartMenuGui.js to Boo conversion)

Hi all,

I’m new to Unity and Boo. I’m currently following Lerpz Tutorial, trying to do the DIY bits in Boo instead of the intended UnityScript. Now I’m stuck at the chapter StartMenuGui, trying to convert from the UnityScript to Boo without any knowledge of UnityScript. I searched for UnityScript to Boo converter, but only found C# to Boo converter (I’m not even familiar with C#). So, I’m here to request hints from all the Boo coders;

Has anyone converted the StartMenuGui.js tutorial to Boo that I can take a peek at? I kinda lost at converting from this original part:

StartMenuGui.js

// Make the script also execute in edit mode
@script ExecuteInEditMode()

var gSkin : GUISkin;
var backdrop : Texture2D; // our backdrop image goes in here.
private var isLoading = false; // if true, we'll display the "Loading..." message.

function OnGUI()
{
    if (gSkin)
        GUI.skin = gSkin;
    else
        Debug.Log("StartMenuGUI: GUI Skin object missing!");

    var backgroundStyle : GUIStyle = new GUIStyle();
    backgroundStyle.normal.background = backdrop;
    GUI.Label ( Rect( (Screen.width - (Screen.height * 2)) * 0.75, 0, Screen.height * 2, Screen.height), "", backgroundStyle);

And this is my attempt for Boo glory:

StartMenuGui.boo

import UnityEngine

""" Make script executable in edit mode """
[ExecuteInEditMode]

class StartMenuGui (MonoBehaviour): 
"""
	def Start ():
		pass
"""	
	def Update ():
		gSkin = GUISkin
	
		backdrop = Texture2D
	
		isLoading = false // if true, we'll display the "Loading..." message.
	
			def OnGui():
				if gSkin:
					GUI.skin = gSkin
				else:
					Debug.Log("StartMenuGui: GUI Skin object missing!")

My confusion starts with:

StartMenuGui.js

    if (gSkin)
        GUI.skin = gSkin;

and all the way down from that. If anyone have converted the tutorial or at least the StartMenuGui.js to Boo, it’ll be a great resource for guy like me. Thanks.

It looks like your def for OnGUI is both spelled wrong (mis-capitalized) and indented too far. Also the class members should not be declared in the Update function.
Try this:

import UnityEngine

""" Make script executable in edit mode """
[ExecuteInEditMode]

class StartMenuGui (MonoBehaviour): 
	public gSkin as GUISkin
	
	public backdrop as Texture2D
	
	public isLoading = false // if true, we'll display the "Loading..." message.
	
	def OnGUI():
		if gSkin:
			GUI.skin = gSkin
		else:
			Debug.Log("StartMenuGui: GUI Skin object missing!")

Democre,

Wow thanks! Now that made sense. Actually I haven’t finished the whole StartMenuGui script yet as I’m confused with the conversion. With your correction, I think I can understand more about the comparison of both. I used BooPrimer.pdf as reference but I’m lost on Unity’s specific (eg: def Start / def Update). Do you have any Unity specific resources that I can read?

Sure thing! Those methods that are def’d are actually defined in MonoBehaviour and listed under the functions that you can override here.

In UnityScript (js), a class is automatically defined by the script it’s in. In this case the StartMenuGui.js script actually declares a class named StartMenuGui which automatically inherits from MonoBehaviour. Any statements that are not within a function block are most likely members of the class, or static initializer code.

When converting js scripts to boo scripts, you should start by replacing all keywords ‘function’ with the boo keyword ‘def’ and carry on as you have been.

Converting scripts is probably the fastest way to learn boo and js at the same time.

Democre,

I have another question to ask. How about this UnityScript part:

var backgroundStyle : GUIStyle = new GUIStyle();

Is this the correct conversion to Boo?:

public backgroundStyle as GUIStyle = GUIStyle()

Or this one?:

def GUIStyle(backgroundStyle as GUIStyle)

You could actually just do:
public backgroundStyle = GUIStyle()because of type inference.

The keyword ‘def’ is used for defining functions.

Democre,

Ah. Ok. That’s much shorter than I’ve expected (viewing from the original UnityScript code).

public backgroundStyle as GUIStyle = GUIStyle()

So is this one still consider a valid option? Thanks for your help so far.

It is shorter. Boo is supposed to be the “wrist-friendly” language for Mono. :wink:

I believe it’s still valid, just repetitive.

Democre,

Thanks! Now it’s easier for me to understand and try to do the conversion. Thank you very much. Hope to see more Boo stuff for Unity.