Arrays of Arrays

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
xroot
Posts: 40
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: 6222
Joined: 11 Jan 2017, 17:59

Re: Arrays of Arrays

22 Jul 2020, 13:04

base should be super

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: -Garfle-, Descolada, Draken and 56 guests