| 09-22-2009, 01:33 PM | #1 |
Hey... I wondered, how can I store objects into a table? Basicly I have something like this: JASS:struct A unit u endstruct globals Table aInstances = Table.create() endglobals Now, I want to save and load the instances JASS:function load takes unit u returns A return aInstances[GetHandleId(u)] endfunction function save takes A returns nothing set aInstances[GetHandleId(A.u)] = A endfunction Is this the correct usage of Tables? Is that how I can store object instances? I never worked with tables :/ Sorry if its nooby, but I never feeled like needing them. |
| 09-22-2009, 01:51 PM | #2 |
JASS://*************************************************************** //* Table object 3.0 //* ------------ //* //* set t=Table.create() - instanceates a new table object //* call t.destroy() - destroys it //* t[1234567] - Get value for key 1234567 //* (zero if not assigned previously) //* set t[12341]=32 - Assigning it. //* call t.flush(12341) - Flushes the stored value, so it //* doesn't use any more memory //* t.exists(32) - Was key 32 assigned? Notice //* that flush() unassigns values. //* call t.reset() - Flushes the whole contents of the //* Table. //* //* call t.destroy() - Does reset() and also recycles the id. //* //* If you use HandleTable instead of Table, it is the same //* but it uses handles as keys, the same with StringTable. //* //* You can use Table on structs' onInit if the struct is //* placed in a library that requires Table or outside a library. //* //* You can also do 2D array syntax if you want to touch //* mission keys directly, however, since this is shared space //* you may want to prefix your mission keys accordingly: //* //* set Table["thisstring"][ 7 ] = 2 //* set Table["thisstring"][ 5 ] = Table["thisstring"][7] //* //*************************************************************** Furthermore: JASS:globals Table aInstances = Table.create() endglobals |
| 09-22-2009, 01:55 PM | #3 |
It doesn't say it all. I don't get the rid how to save objects correctly there. I mean, I can read how it stores, but I don't know how how to use it... Yeah, the documentations tells how to call, but not how to use the calls... EDIT: Can you please write my example full in the table compileable version? Would be nice. I want to learn. |
| 09-22-2009, 02:21 PM | #4 |
The documentation explains how to call it, which explains exactly how to use it. I am sorry, but you are being retarded. To start, your example wouldn't even compile if you removed Table from it because you forgot a bunch of important shit in normal JASS syntax... Secondly, if you want to store to units, you should use a HandleTable. JASS:scope Rawr initializer Init private struct data unit u endstruct globals HandleTable tab = 0 endglobals private function load takes unit u returns data return data(tab[u]) endfunction private function save takes data A returns nothing set tab[A.u] = integer(A) endfunction private function Init takes nothing returns nothing set tab = HandleTable.create() endfunction endscope JASS:scope Rawr2 initializer Init private struct data unit u endstruct globals Table tab = 0 endglobals private function load takes unit u returns data return data(tab[GetHandleId(u)]) endfunction private function save takes data A returns nothing set tab[GetHandleId(A.u)] = integer(A) endfunction private function Init takes nothing returns nothing set tab = Table.create() endfunction endscope |
| 09-22-2009, 02:30 PM | #5 | |
So what do you think about this? (Saving the itemtype and getting/saving/removing the data) JASS:
//: #=#=#=#=#=#=#=#=#=#=#=#=
//: Load & Save Wildcards
//: #=#=#=#=#=#=#=#=#=#=#=#=
globals
private Table itWcTab = 0
endglobals
public function LoadWildCard takes item it returns itemWC
return itemWC(itWcTab[GetItemTypeId(it)])
endfunction
public function SaveWildCard takes item it, itemWC itWC returns nothing
set itWcTab[GetItemTypeId(it)] = integer(itWC)
endfunction
public function DestroyWildCard takes item it returns nothing
call itWcTab.flush(GetItemTypeId(it))
endfunction
Edit: Oh btw, just to let you know, I already have the table initialisated JASS:
private function init takes nothing returns nothing
set itWcTab = Table.create()
endfunction
Quote:
it doesn't say you understand the system. An example usage of storing something into a table like a playergoldstore or something like that system would clear eyes and the brain, because its easier to understand. |
| 09-22-2009, 07:21 PM | #6 | |
The code you posted looks fine. Of course, had you just tested it in WC3, you would have known that without having to ask. Quote:
Seriously, quit defending your own ineptitude, suck it up, and learn properly. |
| 09-23-2009, 04:43 AM | #7 |
Some people don't have the same learning capability as the others you know. I think you're being too harsh on him Dusk... Your posts will look much nicer if you remove all the "you are retarded" comments. But.. who am I to judge.. |
| 09-23-2009, 01:23 PM | #8 | |
Quote:
Yes, unfortunately, some people were dropped on their head as a baby... |
| 09-23-2009, 01:57 PM | #9 | ||
Quote:
Rules Quote:
And, whats so wrong about needing an advanced example how to use? I got it nevermore, but really, stop harrassing. |
| 09-23-2009, 02:19 PM | #10 | |
Quote:
|
| 09-23-2009, 02:27 PM | #11 | |||||
Quote:
Quote:
Quote:
Quote:
You wouldn't know all these if you haven't learned by anyone else. Quote:
|
| 09-23-2009, 02:34 PM | #12 |
My post wasn't a random flame. It's a statement that no one has an excuse to claim that they don't have the "same learning capability as others," unless they actually are brain-damaged. |
| 09-23-2009, 05:10 PM | #13 |
Anyways, Anachron, you're just like Flame_Phoenix. Instead of sucking it up and trying harder to become better (and testing things yourself without asking silly questions), you expect us to walk you through everything and just bitch and moan when people get frustrated with you over it. That's a very, very bad way to be and will earn you no respect or friends at WC3C. Also, grim's point is absolutely valid. Gonna lock this for great justice. Hopefully it is obvious why. |
