Problem with interface implementation or I simply dont get it

“I simply don’t get it”, because I lack of programming background and no matter how hard I searched for a workaround, I didn’t manage to figure it out. So I probably need to do much more reading, but in case there is a straightforward answer, I’d be glad to know it and proceed further, instead of digging into these stuff that I barely understand in order to know where to focus exactly.
The problem appears when I try to translate this C# class into Unityscript:

   using UnityEngine;
    
    public class TilePrefab : MonoBehaviour, IDFVirtualScrollingTile
    {
        ....
    public int VirtualScrollItemIndex { get; set; }
        ....
    }

where the IDFVirtualScrollingTile interface is also written in C# as:

public interface IDFVirtualScrollingTile
{
	int VirtualScrollItemIndex { get; set; }
        ....
}

So far, among other approaches, I have tried this:

#pragma strict

public class TestTilePrefab extends MonoBehaviour implements IDFVirtualScrollingTile
{
     //I don't know how to translate the get, set line
}

but it has thrown different kinds of warnings and errors with the more popular to be:

BCE0141: Duplicate parameter name
‘value’ in
'TestTilePrefab.set_VirtualScrollItemIndex(int,
int)
when for example I don’t include the before-mentioned line or
BCW0011: WARNING: Type
‘TestTilePrefab’ does not provide an
implementation for
‘IDFVirtualScrollingTile.VirtualScrollItemIndex’,
a stub has been created.
when I used some syntax of the javascript getter/setter method I found elsewhere. I even experimented to get the interface as Component, but I failed there too.
Any kind of help is welcome.

The VirtualScrollItemIndex is a property. Specifically what you see inside your “TilePrefab” class is called an auto-property since it automatically creates a private “backing” field and the get and set methods for it.

As you can see over here UnityScript now also supports properties. The syntax is quite a bit different and (as far as i know) it doesn’t support autoproperties. So you need to create the backing field and the get and set method yourself.

In C# it would look like this:

private int m_VirtualScrollItemIndex;
public int VirtualScrollItemIndex
{
    get {
        return m_VirtualScrollItemIndex;
    }
    set {
        m_VirtualScrollItemIndex = value;
    }
}

In UniyScript it would look like:

private var m_VirtualScrollItemIndex : int;

public function get VirtualScrollItemIndex() : int
{
    return m_VirtualScrollItemIndex
}

public function set VirtualScrollItemIndex(value : int)
{
    m_VirtualScrollItemIndex = value;
}

I don’t use UnityScript, so i can’t tell if that works along with using an interface. UnityScript has poor support for some programming concepts.

I would redefine your interface so that it is also javascript.

AFAIK, properties don’t exist without specific implementation in javascript. Properties are just syntactic sugar for get and set functions (which are later generated by the compiler).

public int MyProperty { get; private set; }

is replaced with something like

private int m_BackingField;

public int get_MyProperty()
{
    return m_BackingField;
}

private int set_MyProperty(int value)
{
    m_BackingField = value;
    return value;
}