• 🏆 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!

[General] Loop inside a loop problem

Status
Not open for further replies.
Level 6
Joined
Oct 1, 2012
Messages
166
Hello Hive Workshop!
I have a problem with loop inside a loop. I need it to check six times whether or not one integer is between 1 and 4001. So I made a function to loop six times the action, in which it loops 4001 times checking whether the integer is the number between 1 and 4001.
The world editor seems to be somewhat buggy with too big loops, as I checked. Any solutions? I tried splitting the first loop into 6 different loops, but to no avail.
 
Level 7
Joined
Jan 30, 2011
Messages
267
do i understand right that you have 6 different integers and for each one you need to check whether its between 1 and 4001 or not? why do you need another 4001 loops inside each loop then? just check if(1 <= myInteger and myInteger <= 4001)
 
Level 6
Joined
Oct 1, 2012
Messages
166
That's not really the thing. The thing is that I need this loop for a saving function. This one saves items from a hero's backpack. These are up to six. All items have index's from 1 to 4001 (that's 300 places for each type of quipment and additional 1000, I don't plan having this much, but I hate changing everything a year after doing something, so I let there be enough space). If I reduced the number to 2000, then it would give the same, as I was working with the loops to see how they work and no individual trigger could count more than ~4000 times. I made a function giving 'yes' everytime the loop count was divisable by 1000 with 6 different loops one after another counting from 1 to 4001 and it gave me 'yes' only four times.
 
Level 6
Joined
Oct 1, 2012
Messages
166
Didn't think about it. But I found a funny solution - when I made 6 different triggers for checking individual equipment spaces, it seems to work. I just teleport the hero between six points, entering one makes the game check another eq space and then, the last counter, teleports the hero back to where he was and runs the trigger changing numbers to the code, then giving it to the player.
Well... I guess it's solved, somewhat. But if anybody has any other solution, I'd be glad :D
 
The problem is you are most likely hitting operation limit.
That explains why it works when you split the code over multiple triggers (= different threads).

You can fix this by adding a 0 second wait after each loop cycle to open up a new thread.

However I really suggest using hashtables instead of this, as its much faster and more professional and gets rid of the loops.
 
Level 6
Joined
Oct 1, 2012
Messages
166
Well, coincidentally, there is no lag after using the command. It maybe caused by my computer being far too good for wc3, but the code isn't that complex. I'll see after beta testing through internet.
But thank you all for opinions and tips :)
I consider this thread solved.
 
Status
Not open for further replies.
Top