HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Initial value of globals

01-25-2010, 10:58 AM#1
Themerion
How do unassigned globals work!?

Some times, it seems that the initial value is what I expect it to be (null,0,.0, etc), some times checking the value of an unassigned variable causes scripts to be interrupted. How to treat initial values? Assign all arrays from 0 to MAX_SIZE with null or 0 ?
01-25-2010, 11:16 AM#2
Anachron
Depends on the handletype.

Constant integers are 0 by default, constant boolean is false by default and constant handles are null by default.
01-25-2010, 12:25 PM#3
Themerion
Well, what if it ain't constant?

Collapse JASS:
handle array arr

doSomethingWith( arr[GetRandomInt(0,8190)] )

Which value will be sent to the function? Will the script halt? What's the best way to handle this?
01-25-2010, 12:49 PM#4
Anachron
Doesn't matter whether they are constant or not.
Aslong as they are not initialized, they are
Integer = 0
Boolean = false
Handle = null

So yours would sent a null value to the function
01-25-2010, 01:37 PM#5
Anitarf
Uninitialized variables crash the thread when used.
Uninitialized arrays work the same as 0/0.0/false/null.