1. Join other hivers in a friendly concept-art contest. The contestants have to create a genie coming out of its container. We wish you the best of luck!
    Dismiss Notice
  2. The Melee Mapping Contest #4: 2v2 - Results are out! Step by to congratulate the winners!
    Dismiss Notice
  3. We're hosting the 15th Mini-Mapping Contest with YouTuber Abelhawk! The contestants are to create a custom map that uses the hidden content within Warcraft 3 or is inspired by any of the many secrets within the game.
    Dismiss Notice
  4. The 20th iteration of the Terraining Contest is upon us! Join and create exquisite Water Structures for it.
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice

[vJASS] Vexorian Table 3.1 in a 2D array, need help!

Discussion in 'Triggers & Scripts' started by redscores, Dec 25, 2018.

  1. redscores

    redscores

    Joined:
    Aug 9, 2006
    Messages:
    2,157
    Resources:
    12
    Maps:
    5
    Spells:
    6
    Template:
    1
    Resources:
    12
    Hello, I am currently trying to make a system that saves a certain ressource to the Table 3.1 made by vexorian.

    Code (vJASS):

    library MatrixCoreMechanic requires Table

    globals
        private Table tMatrixInformation
        private constant integer iMaximumCore = 100
    endglobals

        private keyword Initialization
        public keyword SetMatrixCoreForUnit
     
        public function MatrixCoreMaxReached takes unit CoreUnit returns boolean
            local integer Temp
            set Temp = tMatrixInformation["TEST"][GetHandleId(CoreUnit)]
            return Temp >= iMaximumCore
        endfunction
     
        public function MatrixCoreZeroReached takes unit CoreUnit returns boolean
            return tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] <= 0
        endfunction
     
        public function InitMatrixCoreForUnit takes unit CoreUnit returns nothing
            set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = 0
        endfunction
     
        public function AddToMatrixCore takes unit CoreUnit, integer AddedSparks returns nothing
            set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] + AddedSparks
            if MatrixCoreMaxReached(CoreUnit) then
                set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = iMaximumCore
            endif
            if MatrixCoreZeroReached(CoreUnit) then
                set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = 0
            endif
        endfunction
     
        public function SetMatrixCore takes unit CoreUnit, integer Sparks returns nothing
            set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = Sparks
            if MatrixCoreMaxReached(CoreUnit) then
                set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = iMaximumCore
            endif
            if MatrixCoreZeroReached(CoreUnit) then
                set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = 0
            endif
        endfunction
     
        private module Initialization
            private static method onInit takes nothing returns nothing
                set tMatrixInformation = Table.create()
            endmethod
        endmodule
     
     
     
    endlibrary


    This gives me many errors in the areas where the 2D Table Array is used.

    I have searched high and low in the web and I have not found a proper manual on Tables 3.1 or an tutorial.

    I used the exact syntax described in the documentation of vexorian.

    If someone could help me, I would really appreciate that!
     
    Last edited by a moderator: Dec 26, 2018
  2. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,243
    Resources:
    6
    Models:
    1
    Icons:
    1
    Spells:
    3
    JASS:
    1
    Resources:
    6
    Code (vJASS):

    library MatrixCoreMechanic requires Table

    globals
        private Table tMatrixInformation
        private constant integer iMaximumCore = 100
    endglobals

        private keyword Initialization
        public keyword SetMatrixCoreForUnit
     
        public function MatrixCoreMaxReached takes unit CoreUnit returns boolean
            local integer Temp
            set Temp = tMatrixInformation["TEST"][GetHandleId(CoreUnit)]
            return Temp >= iMaximumCore
        endfunction
     
        public function MatrixCoreZeroReached takes unit CoreUnit returns boolean
            return tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] <= 0
        endfunction
     
        public function InitMatrixCoreForUnit takes unit CoreUnit returns nothing
            set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = 0
        endfunction
     
        public function AddToMatrixCore takes unit CoreUnit, integer AddedSparks returns nothing
            set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] + AddedSparks
            if MatrixCoreMaxReached(CoreUnit) then
                set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = iMaximumCore
            endif
            if MatrixCoreZeroReached(CoreUnit) then
                set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = 0
            endif
        endfunction
     
        public function SetMatrixCore takes unit CoreUnit, integer Sparks returns nothing
            set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = Sparks
            if MatrixCoreMaxReached(CoreUnit) then
                set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = iMaximumCore
            endif
            if MatrixCoreZeroReached(CoreUnit) then
                set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = 0
            endif
        endfunction
     
        private module Initialization
            private static method onInit takes nothing returns nothing
                set tMatrixInformation = Table.create()
            endmethod
        endmodule
     
    endlibrary
     


    It would appear to be the case that you are treating the Table instance as a class object. A simple solution is to omit the string key from the Table instance
    tMatrixInformation
    .

    It would end up looking like this:

    Code (vJASS):

    library MatrixCoreMechanic requires Table

    globals
        private Table tMatrixInformation
        private constant integer iMaximumCore = 100
    endglobals

        private keyword Initialization
        public keyword SetMatrixCoreForUnit
     
        public function MatrixCoreMaxReached takes unit CoreUnit returns boolean
            local integer Temp
            set Temp = Table["TEST"][GetHandleId(CoreUnit)]
            return Temp >= iMaximumCore
        endfunction
     
        public function MatrixCoreZeroReached takes unit CoreUnit returns boolean
            return tMatrixInformation[GetHandleId(CoreUnit)] <= 0
        endfunction
     
        public function InitMatrixCoreForUnit takes unit CoreUnit returns nothing
            set tMatrixInformation[GetHandleId(CoreUnit)] = 0
        endfunction
     
        public function AddToMatrixCore takes unit CoreUnit, integer AddedSparks returns nothing
            set tMatrixInformation[GetHandleId(CoreUnit)] = tMatrixInformation[GetHandleId(CoreUnit)] + AddedSparks
            if MatrixCoreMaxReached(CoreUnit) then
                set tMatrixInformation[GetHandleId(CoreUnit)] = iMaximumCore
            endif
            if MatrixCoreZeroReached(CoreUnit) then
                set tMatrixInformation[GetHandleId(CoreUnit)] = 0
            endif
        endfunction
     
        public function SetMatrixCore takes unit CoreUnit, integer Sparks returns nothing
            set tMatrixInformation[GetHandleId(CoreUnit)] = Sparks
            if MatrixCoreMaxReached(CoreUnit) then
                set tMatrixInformation[GetHandleId(CoreUnit)] = iMaximumCore
            endif
            if MatrixCoreZeroReached(CoreUnit) then
                set tMatrixInformation[GetHandleId(CoreUnit)] = 0
            endif
        endfunction
     
        private module Initialization
            private static method onInit takes nothing returns nothing
                set tMatrixInformation = Table.create()
            endmethod
        endmodule

        // A dummy struct to carry out the instantiation (extends array so that it does not generate alloc and dealloc methods, which are unneeded here)
        private struct Initializer extends array
            implement Initialization
        endstruct
    endlibrary
     


    In another note, I could instead recommend another Table resource: [Snippet] New Table
     
  3. redscores

    redscores

    Joined:
    Aug 9, 2006
    Messages:
    2,157
    Resources:
    12
    Maps:
    5
    Spells:
    6
    Template:
    1
    Resources:
    12
    Thanks alot. I will try that :).

    It was weird tho, vexorian recommended this stuff with the Arrays in his documentation^^.
     
  4. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,420
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    The 2D array syntax only works when you are using the Table class itself, rather than a specific instance. For example, this is what your code looks like:
    Code (vJASS):
    set tMatrixInformation["Sparks"][GetHandleId(CoreUnit)] = 0


    However, Table's 2D syntax is designed for it to work like this:
    Code (vJASS):
    set Table["Sparks"][GetHandleId(CoreUnit)] = 0


    The reason has to do with how Table is implemented. Table is basically a wrapper for the built-in
    hashtable
    , which have two keys: a parent key and a child key. When you make a specific instance, e.g.
    tMatrixInformation
    , it acts as a specific parent key for whatever you want to store, and deals with that part for you. So then all you have at your disposal is a child key. That's why it is only designed to support one-dimension assignment for a specific table instance.

    When you use the 2D syntax, you're basically saying, "let me worry about both the parent key and the child key, I'll handle it myself". So you get access to both the parent key and the child key, as long as you're working on the Table class itself rather than a specific instance. Fun fact: internally, when you do
    Table["Sparks"][GetHandleId(CoreUnit)]
    , the
    Table["Sparks"]
    gets treated as a fake Table instance, and then it goes through the normal process to access the second index (CoreUnit's handle ID).

    The system that MyPad linked supports 2D arrays for specific instances (look at the
    TableArray
    class), but idk if it is really necessary in most cases. For your purposes, it seems like the handle ID should be unique enough. :)
     
  5. redscores

    redscores

    Joined:
    Aug 9, 2006
    Messages:
    2,157
    Resources:
    12
    Maps:
    5
    Spells:
    6
    Template:
    1
    Resources:
    12
    Thanks alot.

    This seems like a really curious syntax :D

    I will try it.