Arrays of Arrays

Get help for the alpha version of AutoHotkey v2 here. Please state the v2 version you are working with in the title when making a new topic.
xroot
Posts: 17
Joined: 21 Jun 2019, 08:45

Arrays of Arrays

22 Jul 2020, 11:36

In the following code from ver. a118 help docs under Arrays of Arrays

Code: Select all

class Array2D extends Array {
    __new(x, y) {
        this.Length := x * y
        this.Width := x
        this.Height := y
    }
    __Item[x, y] {
        get => base[this.Width * (y-1) + x]
        set => base[this.Width * (y-1) + x] := value
    }
}

grid := Array2D.new(4, 3)
grid[4, 1] := "#"
grid[3, 2] := "#"
grid[2, 2] := "#"
grid[1, 3] := "#"
gridtext := ""
Loop grid.Height {
    y := A_Index
    Loop grid.Width {
        x := A_Index
        gridtext .= grid[x, y] || "-"
    }
    gridtext .= "`n"
}
MsgBox gridtext
I get this:
  • Warning: This variable appears to never be assigned a value.

    Specifically: local base

    Line#
    000: }
    023: {
    024: this.Length := x * y
    025: this.Width := x
    026: this.Height := y
    027: }
    029: {
    ---> 029: Return base[this.Width * (y-1) + x]
    029: }
    030: {
    030: Return base[this.Width * (y-1) + x] := value
    030: }
    034: grid := Array2D.new(4, 3)
    035: grid[4, 1] := "#"
    036: grid[3, 2] := "#"
What is the best way to fix this.
Thanks
swagfag
Posts: 4126
Joined: 11 Jan 2017, 17:59

Re: Arrays of Arrays

22 Jul 2020, 13:04

base should be super

Return to “AutoHotkey v2 Help”

Who is online

Users browsing this forum: No registered users and 2 guests