• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Things that creates new threads

Status
Not open for further replies.
Level 17
Joined
Apr 27, 2008
Messages
2,455
For groups that you need to keep over time you may consider this (or not)

For the groups that you only need instantly, group enum with a null filter +a loop with FirstOfGroup/GroupRemoveUnit is the way to go (remember the "for <unit_variable> in <group_variable> " loop in Cohadar's jasshelper.

Oh and every thing is jass which takes a code or is a type based of "code", such as boolexpr will create a new thread each time it's called / evaluated.
ForGroup will create X threads for X units inside it.
 
Last edited:
Level 16
Joined
Mar 3, 2006
Messages
1,564
use loops to avoid making another function, the downside of this using ForGroup is that you
need to remove the unit and add it again (if you want to use the group again and again)...

Yes, I have already done that and added a boolean so in case the user needs it again. But I want to create the code function but I don't know how to do that without using creating a new thread.

I am thinking of making it like that:

call forGroup(whichGroup,functionToRun)
but if I make functionToRun a code it will be the same as normal ForGroup
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
There is no way to start a code variable without open a new thread.

Make a ForGroupBJ is 100 % useless, either use ForGroup, or use an other unit data structure such as mine, where you can go through all the units with a loop.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
There is no way to start a code variable without open a new thread.

Yes, that's why I am trying to find another way to overcome this.

Make a ForGroupBJ is 100 % useless, either use ForGroup, or use an other unit data structure such as mine, where you can go through all the units with a loop.

I am not using any BJ.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
By "BJ" i obviously meant that you can just make a wrapper of ForForce, you can't improve it.

For the third time :

You have to use an other unit data structure, such as the one i've created and linked if you want to be able to go through a list of units which need to be kept over time, without opening a new thread.

Sure you can use an other group and use a FirstOfGroup/GroupRemoveUnit/GroupAddUnit inside loops, but then you will have to use two loops for each group iteration and it's really cumbersome.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
By "BJ" i obviously meant that you can just make a wrapper of ForForce, you can't improve it.

:vw_unimpressed:
For the third time :

You have to use an other unit data structure, such as the one i've created and linked if you want to be able to go through a list of units which need to be kept over time, without opening a new thread.
The problem is that I can't make heads or tails of what you have posted; I don't know how I can track it or where to start, remember I am still learning and don't consider myself a pro JASSER.

Sure you can use an other group and use a FirstOfGroup/GroupRemoveUnit/GroupAddUnit inside loops, but then you will have to use two loops and it's really cumbersome.
Will it be cumbersome as having to create N threads ?
 
Level 17
Joined
Apr 27, 2008
Messages
2,455

Well, that was not an insult, simply a fact, as there is no way to call a code argument without open a new thread.
Therefore you can't make a better custom function than the native one "ForForce".

The problem is that I can't make heads or tails of what you have posted; I don't know how I can track it or where to start, remember I am still learning and don't consider myself a pro JASSER.

To use UnitLL, you have to understand linked lists and how they can be implanted and used with vJass structs.

Will it be cumbersome as having to create N threads ?

By cumbersome, i meant the code that is needed to be written each time you want to enum the units inside a group.
It could be still faster than a ForGroup (but i have not tested), at least it will be way more boring to write.
I suppose you could use textmacros or even modules, but it's spaghetti code >.<

Also note that there is the problem of ghost units with a such method.
A ghost unit inside a group is a group removed of the game but not of the group.
When an unit is removed of the game, the groups where the unit was referenced are not cleaned up automatically.
ForForce doesn't enum such units, but with a FOG (FirstOfGroup/GroupRemoveUnit) loop they will be enumed.
And FirstOfGroup will return null with a such unit, so the loop will be broken if it contains one or more ghost units which are not enumed the last (very likely).
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Well, that was not an insult, ...

No, my friend, I didn't take any insult or offense when I put that :vw_unimpressed: its just all my hopes went down, suddenly.

To use UnitLL, you have to understand linked lists and how they can be implanted and used with vJass structs.

Linked list ? The only one I know of is Magtheridon's one but it has been graveyarded.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Ofc it is, he is just saying that he has just made an incomplete tutorial about linked lists, he didn't made the data structure "linked list", it was invented many years ago.

But in (v)jass you would always go for double linked lists, never simple ones, just because it makes operations on it easier and more efficient, and it's not like we have to care about memory used, so simple linked list are quite pointless in (v)Jass, at least in almost every cases.

The only thing that you can choice according the need would be a double linked list, circular or not.
 
Yeah, in JASS, you would only need doubly linked lists most of the time.
And if you needed a singly linked list, you would just use a stack instead.

Singly linked lists are only recommended if they're static.
If you actually needed to remove a node from the list at any point, you might as well
be using a doubly linked list because the algorithm for removing a node from a singly
linked list is O(n) where n is the amount of nodes in the list from the first node to the
node you want to remove.

For huge lists, this will be very slow. :|

Plus, it's not only about speed, doubly linked lists are easier to write.
 
Status
Not open for further replies.
Top