HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Store a struct on a unit

11-10-2008, 09:48 AM#1
Fire-Dragon-DoL
Collapse JASS:
call SetUnitUserData( unit, astruct )

Can i use a struct instead of an integer as a parameter for the custom value of a unit? (should i use H2I(astruct) before passing it as a parameter?)

Does it causes some problems like going outside cache limit?

If not...i can store everything i want inside the struct right?


...Is this the way to make spell multi-istanceable without using handlevars?
11-10-2008, 11:00 AM#2
moyack
Actually a struct is an integer index, not a new handle type... so you can do this without no usage of I2H:

call SetUnitUserData( unit, astruct ) = call SetUnitUserData( unit, integer(astruct) )
11-10-2008, 11:07 AM#3
ToukoAozaki
As moyack mentioned, struct variables are actually array indices of struct members. So you can use it directly as UserData. However, be extra careful that the struct type is correct; vJass is (inherently) NOT typesafe, so referring to a type other than what you've put before would result in unpredictable behavior. (not to mention, it is very hard to debug once this happens)
11-10-2008, 11:33 AM#4
Fire-Dragon-DoL
Quote:
Originally Posted by ToukoAozaki
As moyack mentioned, struct variables are actually array indices of struct members. So you can use it directly as UserData. However, be extra careful that the struct type is correct; vJass is (inherently) NOT typesafe, so referring to a type other than what you've put before would result in unpredictable behavior. (not to mention, it is very hard to debug once this happens)

Thanks a lot...in this way i can avoid handle vars...

and maps will not behave strangely again

yes the problem of gaining back the correct structures is obvius...i'll pay attenction to it

Is this the correct way to create multi instanceable spells and things like that? (there are some cases where you need to store a value on a unit, not possible to use a global, expecially when there is a size limit!)

A suggestion: which is the limitation of a struct?
I mean...you have said that is an index of an array, is this limit directly connected to the array size limit?
so i can store a maximum of 8191 properties or methods in a single struct? (this is just to know, i don't think i'll use so much properties :P )
11-10-2008, 11:43 AM#5
moyack
No, the issue is to overwrite the index. For example if you have a spell A that store a struct index in a unit, and a spell B stores other data into the unit, then will have a problem with spell A. In other words, try to use the userdata for only a very internal data in your map. For other storage stuff, Table is your answer.
11-10-2008, 12:03 PM#6
ToukoAozaki
Quote:
Originally Posted by Fire-Dragon-DoL
Is this the correct way to create multi instanceable spells and things like that? (there are some cases where you need to store a value on a unit, not possible to use a global, expecially when there is a size limit!)

If you're gonna create some smart, versatile struct, that could be possible. But still I'd suggest using Table or TimerUtils. It is more straightforward that way.

Quote:
Originally Posted by Fire-Dragon-DoL
A suggestion: which is the limitation of a struct?
I mean...you have said that is an index of an array, is this limit directly connected to the array size limit?
so i can store a maximum of 8191 properties or methods in a single struct? (this is just to know, i don't think i'll use so much properties :P )

Each struct properties (or members) have their own arrays, so number of properties won't make any differences.

With default settings, you get a maximum of 8191 struct instances. (you can scale that, but would be a little bit slower) Properties don't affect number of instances, except for one case that possibly limit the number of instances is having (sized) array members in the struct.

Methods are just functions with special parameters, so they are irrelevant.
11-10-2008, 04:35 PM#7
Fire-Dragon-DoL
Thanks

I've heared that is good if i use globals instead of handle vars so i thought a struct (which is actually a global!) could be a good idea used in this way

ok i'm reading tables now...hope will be useful :P
EDIT: Do you know some editors like jasscraft?
-Vim: Has the problem that doesn't have the search table (and doesn't have the little box that appear when you are writing, suggesting parameter for functions!)
-Jasscraft: doesn't have syntax highlighter for vjass!

Others?I need the same features as jasscraft, but with syntax highlighter for vjass...
crack jasscraft >.< XD
11-10-2008, 04:44 PM#8
Ammorth
The jassnewgenpack has tesh (sp) which is a highlighter plugin for the WE custom script. Thats what I use (and then jasscraft for the searchable native lists only).
11-10-2008, 06:17 PM#9
emjlr3
TESH has a searchable native list

and you can import custom functions too
11-10-2008, 06:17 PM#10
Anitarf
Quote:
Originally Posted by Fire-Dragon-DoL
I've heared that is good if i use globals instead of handle vars so i thought a struct (which is actually a global!) could be a good idea used in this way
That's incredibly vague what you just wrote so I can't really tell if you're very wrong or just slightly wrong.

Globals can't replace attaching to units, you still need to do that somehow, like with the old handle vars or preferably with the new Table or some other system. The point is that with structs we only need to attach a single integer to a unit, instead of a ton of data; this saves us time, as well as allows us to avoid return bug abuse that would otherwise be needed to store handles; however, we often still need an attachment system of some sort.
11-11-2008, 01:53 PM#11
Fire-Dragon-DoL
Quote:
Originally Posted by Anitarf
That's incredibly vague what you just wrote so I can't really tell if you're very wrong or just slightly wrong.

Globals can't replace attaching to units, you still need to do that somehow, like with the old handle vars or preferably with the new Table or some other system. The point is that with structs we only need to attach a single integer to a unit, instead of a ton of data; this saves us time, as well as allows us to avoid return bug abuse that would otherwise be needed to store handles; however, we often still need an attachment system of some sort.

It's vague because what i've read IS vague, i've heared "avoid using handle vars, use globals instead with vjass because you can declare them everywhere"
...that's things that i've read, and that's why i didn't understand what they where saying...for logic, i find hard doing everything without storing values on a unit...

Are there any documentation about tables?Or some examples :O

Quote:
Originally Posted by Ammorth
The jassnewgenpack has tesh (sp) which is a highlighter plugin for the WE custom script. Thats what I use (and then jasscraft for the searchable native lists only).
I've downloaded it (which worldedit.exe should i use with it?), however it crashes, probably because my worldeditor is italian...

boh :/

Btw the search functions search also through personalised files (if you implement them)...that's a great thing, you can place functions like castersystem functions (and it helps you a lot, really)
11-14-2008, 03:44 AM#12
Pyrogasm
Quote:
Originally Posted by Fire-Dragon-DoL
Are there any documentation about tables?Or some examples :O
Table is actually a code resource by Vexorian. It's just a type of storage system.