| 09-19-2008, 02:54 PM | #1 |
Given: JASS:library itembin initializer init requires Table //======================================================================== globals private Table itemlookup // table containing all the information of any particular item // to be looked up when a unit aquires/loses an item to // appropriately give / remove stat bonuses, buffs, etc. endglobals struct itementry public integer rawitem = 0 // itemID (rawcode) entered into itemlookup public integer maxstack = 0 // maximum size item stacks up to (0 = non stackable) public integer rawabil = 0 // abilID (rawcode) that bonus item gives public integer dataA1 = 0 // data value for ability public string name = "" // name of item (for appearances only) public string iico = "" // path for item/ability art public string uhot = "" // hotkey public string utub = "" // extended tooltip //================================================================ // constructEntry takes the values of struct itementry's member data and creates a // new item and new ability object, then places those into the first open spot on // the table. //================================================================ static method Create takes integer rawitem, integer rawabil, integer dataA1, integer maxstack returns itementry local itementry r=itementry.allocate() set r.rawitem = rawitem set r.rawabil = rawabil set r.dataA1 = dataA1 set r.maxstack = maxstack return r //! external ObjectMerger w3a Sca1 hpea anam "My Chaos" ansf (Peasant) achd 0 Cha1 1 hpea endmethod static method Insert takes nothing returns nothing local integer a = 0 loop exitwhen not(itemlookup.exists(a)) set a = a + 1 endloop // set itemlookup[a] = .this ?? endmethod endstruct function init takes nothing returns nothing set itemlookup = Table.create() endfunction endlibrary I'm wanting to store the entire struct inside the table (so that it may be looked up later). The problem I'm having is in my Insert function, which is called like: JASS:itementry foo = itementry.Create('ratc', 'Alt9', 50, 0) //(Claws of attack +50) foo.Insert() But I'm not sure how to reference the itementry that was used to call the .Insert function. I could just build another temporary struct inside the insert function based off of the current member data, but that would be ineffecient. |
| 09-20-2008, 05:24 AM | #2 |
don't use static method and then use "this" to access the calling struct. |
| 09-20-2008, 05:45 AM | #3 |
Why not static methods? All those methods are supposed to be accessible from outside the struct. |
| 09-20-2008, 06:32 AM | #4 |
which normal methods do. Private methods are only able to be used in a struct. A static method makes it so it doesn't take a struct as an argument (or "calling struct" JASS:struct MyStruct method basic takes nothing returns nothing // ... endmethod static method static takes nothing returns nothing // ... endmethod endstruct function test takes nothing returns nothing local MyStruct s = MyStruct.create() // create is a static method call s.basic() // non-static, the s struct is the calling struct (hence becomes the variable "this" in the method "basic" call MyStruct.static() // since its static, it doesn't take a calling struct and therefore no "this" variable is allowed to be used in the method |
