DIM vs CreateObject

Hi all. Nice forum. Thanks for all the great posting.

I’ve been playing around with brightScript and have, what I hope is, a minor question. When I create an “object” in bScript, I can create simple instance variables and methods without issue. However, the multi-dimensional arrays are causing issues. Example of what I would like to do:

Function newSomeObject() AS object

    this = {}

    this.Init()
    return this

    this.init = function()

        DIM m.theData[8, 5]

        m.fe = 0
        m.fi = 0
        m.theData[1,2] = 42
    end function

    this.andThatFunction = function(foo as integer)
     ......
    end function
end function

I obviously can’t DIM the data array like this (syntax error). Of course, it works fine at function/global scope without the “m.”. So how do I create an instance variable (multi-dim array) for an object? The manual didn’t explain that part very well. If I use createObject(), I need to create an array of arrays? What’s the syntax for that?

Then I can have

obj1 = newSomeObject()
obj2 = newSomeObject()

obj1.theData[1,2] = 3
obj2.theData[4,5] = 6

All this works fine except for the DIM line. Does this make sense or am I way off (new to BScript)???

Thanks in advance for the help!

EDIT: P.S. I can probably use createObject and create a single dimension array and multiply the indices out properly, but I would like to use the multi-dim syntax if possible.

You can’t use DIM directly with the m. object. You’ll need to DIM the array, then set it to a variable in the m. object…

Dim data[8, 5]
m.theData = data

Cool. You sleep don’t you? (or are you an AI bot? WATSON meets TheEndless…lol). That’s a fast response.

I guess the DIM creates the object, but it would go “out of scope” and have a ref count of zero, but the m.theData = data gives it a reference count of 1 and it stays… and I now have an instance reference to it. Makes sense. OK.

Thanks!