• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

I was trying to convert my hashtables into table

Status
Not open for further replies.
Oh yeah. It isn't a 1:1 correspondence with the hashtable function. The whole philosophy of Table revolves mostly around the idea of using a struct as the storage for a multitude of data.

Naïve hashtable usage involves long lists of data being stored:
JASS:
call SaveBoolean(hash, id, 0, true)
call SaveUnit(hash, id, 1, caster)
call SaveUnit(hash, id, 2, target)
Table usage revolves around storing the struct and letting that do everything for you:
JASS:
struct Data
    static Table storage = 0

    unit caster
    unit target
    boolean something
    
    private static method onInit takes nothing returns nothing
        set storage = Table.create()
    endmethod
endstruct

// ... some code
local Data d = Data.create()
set storage[id] = d

That is just a random example. The main concern is the line: set storage[id] = d. Rather than storing all data individually in the hashtable, you simply store the struct. Later on, you can load the struct from the same ID and then grab whatever data you want. In a sense, you can picture structs as "packing" the data into a box.
 
Status
Not open for further replies.
Top