• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Pros & Cons on different methods of passing data

Status
Not open for further replies.
Level 7
Joined
Nov 19, 2015
Messages
283
Just learning Jass/vJass atm. In GUI I would mostly use a periodic timer, adding units to a group and then doing stuff.

I guess with Jass, everyone just uses timers now. Whats the best method of passing data across? I used hashtables before in GUI. I've been told that the table system by Bribe is better. Also learnt about structs and passing them through arrays and handles.

Could someone please tell me the advantages and limitations of these methods and perhaps offer other methods. Please correct me if I am wrong on anything since I am still learning. (I prefer not to just copy and paste someone else's system since I kinda want to know how to do it myself or at least be able to understand the internal workings of the system.)
 
In vJASS you often work with a struct if you want to work with more data.
Like iterating through struct members, or attaching a struct to a timer.

Iterating though instances can happen like having a list[] of your struct,
or with a double linked list for example. These are two common methods.

Hashtable can be used to bind data to timers. TimerUtils could be used here, too.

Table can work like hashtable, and is just an abstraction of it to take more profit of single hashtables.

But hashtable is very powerful and not too often needed. For normal spells you usually don't need it.

I'm not really sure what to explain, but could you maybe explain this?

"Also learnt about structs and passing them through arrays and handles."

Maybe if you have an explicit question it will help a bit. :)
 
Level 7
Joined
Nov 19, 2015
Messages
283
In vJASS you often work with a struct if you want to work with more data.
Like iterating through struct members, or attaching a struct to a timer.

Iterating though instances can happen like having a list[] of your struct,
or with a double linked list for example. These are two common methods.

Hashtable can be used to bind data to timers. TimerUtils could be used here, too.

Table can work like hashtable, and is just an abstraction of it to take more profit of single hashtables.

But hashtable is very powerful and not too often needed. For normal spells you usually don't need it.

I'm not really sure what to explain, but could you maybe explain this?

"Also learnt about structs and passing them through arrays and handles."

Maybe if you have an explicit question it will help a bit. :)


Thanks for the information. So to clarify:
Using structs is the most common
Hashtables/tables are not often used
Tables is an improved way of using hashtables

What do you mean by powerful? Do you mean that it can do a lot of things but is slower (more stress on the computer)? Hence not preferred for simple spells.

This was the tutorial I read up on to learn about passing data through timers.
http://www.thehelper.net/threads/jass-timers-and-how-to-pass-data-to-them.106986/ It explains how to link data to timers. 1. periodic timers using arrays, 2. Attaching to a handle (Using H2I), 3. Saved in an index array (subtracting off the initial handle count).

I guess what I want to know is really what is best to do. I feel like there a millions ways to get things done in Jass (yay to versatility) however with all these options I don't know what is best. In GUI there usually was usually only 1 (maybe 2) ways of getting something done. Could you give me exampes of your code say for a simple damage over time spell or a do this after X seconds.
 
Level 7
Joined
Nov 19, 2015
Messages
283
Ok, I guess I'll be using structs and arrays.

Could you give me an example of what you would use a hashtable for? I have a missile system that uses it. It takes saves the angle, speed, damage, caster, origin point, homing, and other stuff. Would this be effective use of hashtables or would structs be better and faster.

If I was going to input all the data from my spells, damage, mana cost, cast time... and then call it up for my functions, Would this be good use for a hashtable?

I always used hashtables in GUI since it was so useful and could store any of whatever I wanted. I never really used arrays before since I learnt about Hashtables before I made MUI spells.


Also why do people use a constant function? (E.g.)
constant function GetDamage takes nothing returns real
return 5.
endfunction

rather than

Global
set Damage = 5.

Wouldn't it be slower having to call the function everytime you want to get the damage. If its in a scope, why not use a global?
 
Hashtable is useful when it comes to high integers beyond 8191, where normal arrays are not enough.
So basicly for all HandleIds, ItemTypeId, UnitTypeId, TerrainType, etc.
For most or maybe all others I usually don't use it.

constant function can take arguments.
For example you can use it for damage calculation:
JASS:
constant function takes integer level returns real
    return 100. * level
endfunction
If you don't need parameters then yes, use globals.
 
Level 7
Joined
Nov 19, 2015
Messages
283
The function is usually in config part and is easily accessable for the user.
He can write his own calculation with given level integer instead of
modifying the core code itself.

Ahh, so for systems and such. So if its for my own map it faster to just use globals.

Another quick question.
Example:
Caster spawns units
I add units to a unit group
Caster stops channeling
Pick all units in group = owner of caster

or

Caster spawns units
Caster stops channeling
Pick all units in map = owner of caster and unit type

or is it done differently in vJass. Perhaps a better method?
 
If you want to take level of ability under consideration for your calculation then use functions, else globals are good.

I'm not sure I understand the first variant in given example, but:

If you can add specific units yourself to a group it seems good. So no enums are needed.
If you use always a temp group + enum, then you will only need one global group.

Me personaly would choose variant with a group for each caster if I need to keep track of the units.
 
Level 7
Joined
Nov 19, 2015
Messages
283
If you want to take level of ability under consideration for your calculation then use functions, else globals are good.

I'm not sure I understand the first variant in given example, but:

If you can add specific units yourself to a group it seems good. So no enums are needed.
If you use always a temp group + enum, then you will only need one global group.

Me personaly would choose variant with a group for each caster if I need to keep track of the units.

Sorry, just to make it clear.
Have group that I keep adding and removing units from.
or
Create a new group whenever I need it instead of there always being an empty group.

So you would say create a new unit group for each unit that casts the ability and save all units spawned into the group? Would you destroy the group when it is empty/ end of spell or when the unit dies?
 
Yes if each caster uses a group, for example to add DummyUnits that belong to the caster,
then I would create it exclusivly for the caster and also destroy it after the caster is done.

UnitGroups might also be recycled so you don't create/destroy unit groups by your own,
but use recyle functions instead. Such a system is usually called GroupUtils.

You also could create array/list or a new struct especially for the dummy units,
so no group handle is needed, but it doesn't matter too much.
group is exactly made for this purpose and can be used.
 
JASS per se is slow, but that doesn't mean you aren't allowed to use it.
If you need a unit group, then use it, and it will be perfectly fine.
Such performance doubts don't matter much in reality,
because then many GUI maps should be just totaly unplayable, which is not the case.
It's good practice to write fast code, too, but usefulness is more important, always.

If you have a faster way that is good to implement, then sure go for it,
but there is really no need to think about it for more than 1 minute if to create 1 handle or not. ;)
 
Status
Not open for further replies.
Top