listunity-game-enginemonoboo

Boo Lists - Cast to (int)?


I attempted to follow this tutorial which was originally written for UnityScript, but to use Boo instead: http://docs.unity3d.com/Manual/Example-CreatingaBillboardPlane.html

Here's what I tried:

import UnityEngine

class CreateMesh (MonoBehaviour): 

    def Start ():
        meshFilter = GetComponent(MeshFilter)
        mesh = Mesh()
        mesh.vertices = [Vector3(0, 0, 0), Vector3(1, 0, 0), Vector3(0, 1, 0), Vector3(1, 1, 0)]
        mesh.triangles = [0, 2, 1, 2, 3, 1]
        mesh.normals = [-Vector3.forward, -Vector3.forward, -Vector3.forward, -Vector3.forward]
        meshFilter.mesh = mesh
    
    def Update ():
        pass

Unfortunately, each one of my list literals has caused problems:

Cannot convert 'Boo.Lang.List' to '(UnityEngine.Vector3)'

Cannot convert 'Boo.Lang.List' to '(int)'

Cannot convert 'Boo.Lang.List' to '(UnityEngine.Vector3)'

This is a bit disappointing - I had expected that Boo would have been able to infer the type of my lists, since all the elements within are of the same type. In any event, I think that all that should be necessary is a cast statement of some sort. I've looked around at a few other Boo examples on Unity, but none of them seem to utilize lists like I want to.

I looked into it a bit and saw that I could cast to a list of type like this:

[...] as List[of type]

So I tried that like this:

mesh.triangles = [0, 2, 1, 2, 3, 1] as List[of int]

But this still didn't work - it just changed my error message to:

Cannot convert 'Boo.Lang.List[of int]' to '(int)'.

I have no idea what it means by (int) - I had assumed that was a List which consisted only of ints but it seems I must be wrong.


Solution

  • Key point: the Mesh class expects arrays, not lists. The two types are very similar, but not identical.

    Type                 C#           Boo
    -----------------------------------------------
    List of integers     List<int>    List[of int]
    Array of integers    int[]        (int)
    Dictionary           ???          Dictionary[of key, value]
    

    This line creates a list of ints:

    mesh.triangles = [0, 2, 1, 2, 3, 1]
    

    Versus an array of ints:

    mesh.triangles = (0, 2, 1, 2, 3, 1)
    

    Note we swap [] braces for () parens.