• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Loop Question

Status
Not open for further replies.
Level 11
Joined
Jun 30, 2008
Messages
580
I am making a system that I believe will be using around 5 to 6 loops. Is this a problem? Is there an alternative to using loops that are more efficient.

Basically there will be methods for users to use to add a certain thing to the info with the struct:

call name.AddUnit(XunitX)
call name.AddUnit(XunitX2)

etc.

And the only way I can think of in the system that uses this info, is in the method have:
JASS:
method AddUnit takes unit u returns nothing
     set .array = .array+1
     set .unit[array] = u
endmethod

and in the system it will run through .array to find the right .unit.

and I will have several of these, is there any other alternative or does it not matter?
 
It shouldn't matter, as long as you are not hitting the op limit. Multiple loops are usually fine, depending on whatever is within the loops. :)

If you are performing several thousands of functions, then just beware of the op limit. However, there are workarounds to that, such as by using ExecuteFunc() or triggers to start a new thread.

In terms of efficiency, it really depends on the code on whether or not there is an alternative.
 
Level 13
Joined
Mar 16, 2008
Messages
941
This depends on the amount of units in your map but I bet the hashtable is faster then enumerating through the entire array (although this method isn't "slow" either).
You could also think of an indexing system with normal arrays if you don't like the hashtables. If the entire map is done with one I bet it's faster then all other stuff.
 
Status
Not open for further replies.
Top