HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

vJass - Saving Objects into a table

09-22-2009, 01:33 PM#1
Anachron
Hey...

I wondered, how can I store objects into a table?
Basicly I have something like this:
Collapse JASS:
struct A
    unit u
endstruct

globals
    Table aInstances = Table.create()
endglobals

Now, I want to save and load the instances

Collapse 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
Rising_Dusk
Collapse 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]
//*
//***************************************************************
Table's documentation explains all.

Furthermore:
Collapse JASS:
globals
    Table aInstances = Table.create()
endglobals
That won't compile with any struct. You must initialize to 0 and create the struct in the initializer for the library/scope.
09-22-2009, 01:55 PM#3
Anachron
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
Rising_Dusk
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.
Expand JASS:
Expand JASS:
These examples work the same.
09-22-2009, 02:30 PM#5
Anachron
So what do you think about this?

(Saving the itemtype and getting/saving/removing the data)
Expand JASS:

Edit: Oh btw, just to let you know, I already have the table initialisated
Expand JASS:

Quote:
I am sorry, but you are being retarded.
No, I am not. If you see a wall of code and even an example call,
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
Rising_Dusk
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:
Originally Posted by Anachron
No, I am not. If you see a wall of code and even an example call,
it doesn't say you understand the system.
By denying it, you are even more retarded. It is not a wall of text, it is the documentation of a system that you should read and understand thoroughly before using the system or any part of it in the first place. Furthermore, in Table's documentation you have to read two sentences and look at the example function call to figure it out. Guess how I learned it -- I read the documentation and it instantly made sense.

Seriously, quit defending your own ineptitude, suck it up, and learn properly.
09-23-2009, 04:43 AM#7
TheWye
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
grim001
Quote:
Originally Posted by TheWye
Some people don't have the same learning capability as the others you know.

Yes, unfortunately, some people were dropped on their head as a baby...
09-23-2009, 01:57 PM#9
Anachron
Quote:
Originally Posted by grim001
Yes, unfortunately, some people were dropped on their head as a baby...

Rules
Quote:
Be civil
No personal attacks, whether in posts, signatures or imagery. Anything the admins deem derogatory towards another user will be censored and/or deleted and you will be warned.

If you feel the need to flame someone, please do it in private e-mail. Do not feel compelled to defend your honor in public.

Be excellent to each other!

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
Rising_Dusk
Quote:
Originally Posted by Anachron
Believe it or not, Grim is just like everyone else here. We're going to help you, but only if you're both capable and willing to help yourself first. We are not your personal trainers and we are not going to hold your hand through everything. The first skill you need to master before attempting modding at all (with any hope of being successful) is to be able to help yourself. I'm truly sorry that the Hive has been teaching you all wrong, but as long as you're here we're going to shove it down your throat properly until you get the picture. (Or ragequit, whichever happens first)
09-23-2009, 02:27 PM#11
Anachron
Quote:
Believe it or not, Grim is just like everyone else here.
... so?

Quote:
We're going to help you, but only if you're both capable and willing to help yourself first.
I was just asking for an advanced example, I for myself didn't knew how to handle with method operators, so I had a problem with table because it used that. Is that that hard to accept?

Quote:
We are not your personal trainers and we are not going to hold your hand through everything.
Did I ever said I want that?

Quote:
The first skill you need to master before attempting modding at all (with any hope of being successful) is to be able to help yourself.

You wouldn't know all these if you haven't learned by anyone else.

Quote:
I'm truly sorry that the Hive has been teaching you all wrong, but as long as you're here we're going to shove it down your throat properly until you get the picture. (Or ragequit, whichever happens first)
Depends on sight, maybe your point of view is wrong, its just a matter of the view.
09-23-2009, 02:34 PM#12
grim001
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
Rising_Dusk
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.