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

Map initialisation OVERLOAD

Status
Not open for further replies.
Level 4
Joined
Sep 28, 2016
Messages
47
Hi all,

I'm worried, scared and afraid for the future. I was happily working on the map, when I made a TINY edit, and suddenly my entire intro is broken, and I think I crashed the map initialisation.

I've tested it, and it's when I change a real array from [1] to [1000]. If I change it back to [1], everything works again.

The things I've seen happening are: Cinematic mode is not flicked on properly, and so fog is on and other things which screws up cinematic. Timing of elapsed time triggers are moved. Waygate destinations change.

All I wanted to do was create a system that allowed the farms to be built to produce units every set amount of time (+random number of secs to scatter the production and make it look a bit random). I need the real array to store the count, which I use in a unit group loop for instancing, like you would a dummy for a multiplayer skill.

Anyone got any ideas as to how to fix?
 
Level 12
Joined
Jan 2, 2016
Messages
973
the difference between an array of [1] and array or [1000] is that the [1] looks like:
r[0] = 0, r[1] = null, r[2] = null... r[999] = null.
while the other one looks like:
r[0] = 0, r[1] = 0, r[2] = 0... r[999] = 0.
So you can still use the array, even if you've given it [1] as value. It will just initialize less 0's (or whatever value you've given it), you can still use "Set r[534] = 'some number' " to change the "null" into the value you want.
 
Level 4
Joined
Sep 28, 2016
Messages
47
the difference between an array of [1] and array or [1000] is that the [1] looks like:
r[0] = 0, r[1] = null, r[2] = null... r[999] = null.
while the other one looks like:
r[0] = 0, r[1] = 0, r[2] = 0... r[999] = 0.
So you can still use the array, even if you've given it [1] as value. It will just initialize less 0's (or whatever value you've given it), you can still use "Set r[534] = 'some number' " to change the "null" into the value you want.

Oh cool. But this doesn't explain why the function doesn't work sometimes. Does it give us a clue as to the map init problem?
 
There is somethng called Operations Limit, which does just halt all operations when it's count gets reached.
So the result is, when you do too much operations inside your init trigger events, some might not run properly, or entirly.

Don't init array variables bigger than "1" by default. You actually do not need to change it.
If, then it's only useful for something like timers/groups/ ... something that must be created. But also then it also only not really advised.
Maybe only useful when the count is static, like 11 timers, one for each player, then it's acceptable.
 
Level 12
Joined
May 22, 2015
Messages
1,051
There is somethng called Operations Limit, which does just halt all operations when it's count gets reached.
So the result is, when you do too much operations inside your init trigger events, some might not run properly, or entirly.
Just want to elaborate on this by saying that there is a big init function that gets generated by the warcraft 3 map editor when you save. It sets up all the variables and creates all the triggers. However, it sets up the variables first, so if you hit the operations limit, then it will skip creating the triggers (or some of them).

When you specify the size of an array, the bit init function makes a loop to fill all the indexes of the array with a default value. This very quickly increases the amount of operations in the init function. Good thing you don't actually need to set the size of arrays as has been mentioned. Just keep it at size 1 and it will work like normal.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
the difference between an array of [1] and array or [1000] is that the [1] looks like:
r[0] = 0, r[1] = null, r[2] = null... r[999] = null.
All indices of JASS arrays are initialized to a default value. For handle and string types it is null, for integer type it is 0, for real type it is 0.0, for boolean it is false, etc.

So it actually looks like...
r[0] = 0, r[1] = 0, r[2] = 0... r[8191] = 0.

Do note that this only applies to arrays. Trying to access either a global or local variable that has not been initialized will result in a thread crash.

while the other one looks like:
Which is what the first example looks like as 0 happens to be the default value for integer arrays.

Oh cool. But this doesn't explain why the function doesn't work sometimes. Does it give us a clue as to the map init problem?
Hitting operation limit. The operation limit is an attempt at stopping one kind of trigger infinite loop form crashing WC3 by limiting how much a trigger can do before it forcefully stops (thread crash). After performing so many JASS operations a thread crashes. Since initializing an array for 1000 indices requires iterating through 1000 indices this eats up the operation limit. The solution is to avoid such large variable initializations inside the initialization thread and instead spawn other threads with their own fresh op limit to do the variable initialization.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
the difference between an array of [1] and array or [1000] is that the [1] looks like:
r[0] = 0, r[1] = null, r[2] = null... r[999] = null.
while the other one looks like:
r[0] = 0, r[1] = 0, r[2] = 0... r[999] = 0.
I'm pretty sure leaving the default size of the array to 1 just looks like this on map init:
r[0] = 0, r[1] = 0

It only initializes a value up to the size you specify.
 
Status
Not open for further replies.
Top