HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How to null an array?

08-08-2006, 08:42 AM#1
Retro
How do you set an array to null?

e.g: local unit array u
08-08-2006, 09:01 AM#2
Wyvernoid
Why, does "set u = null" bug?
But... if jass uses the same array principle as C... You need to set every element to null.
08-08-2006, 09:19 AM#3
Retro
I'm not sure if it bugs but does "set u = null" sets every index to null? Or do you have to make a loop?
08-08-2006, 09:21 AM#4
Daelin
Collapse JASS:
loop
     set i = 1
     exitwhen i>SizeOfArray
     set a[i]=null
     set i = i + 1
endloop

replace SizeOfArray with the size your array should have (number). Also it is discussable if you started with indexes from 1 or from 0.

~Daelin
08-08-2006, 09:23 AM#5
Wyvernoid
Better make a loop.
'Cause I really don't know if JASS is the same as C here. If so, 'u' is just something (pointer?) and setting it to null still leave those data in memory untouched. So I said...
Quote:
Originally Posted by Wyvernoid
You need to set every element to null.

EDIT: Daelin you were quicker ^^ @Retro: Just use Daelin's JASS.
08-08-2006, 09:59 AM#6
Retro
Thanks to both of you. Arrays always starts from a[0] right?

But geez, I've no clue on this next piece: Is there any way an array could have a maximum index? I mean like an array C, and set its max index to C[50], can it be done?
08-08-2006, 10:09 AM#7
The)TideHunter(
Maxium array is 8192.
0 isent always the start of an array, if you dont set anything to Array[0], then theirs no need to null.
I dont tend to use 0, i always start on 1, but thats people opinions, do what you feel best doing.

If you had a array of 5000, you dont have to null them all, just null the ones you have used.
08-08-2006, 11:11 AM#8
oNdizZ
Quote:
Originally Posted by Daelin
Collapse JASS:
loop
     set i = 1
     exitwhen i>SizeOfArray
     set a[i]=null
     set i = i + 1
endloop

replace SizeOfArray with the size your array should have (number). Also it is discussable if you started with indexes from 1 or from 0.

~Daelin

ehumm :p
you dont wanna change that and put the set i = 1 outside the loop? :)
if the SizeOfArray is bigger than i, then that loop will never end :/
08-08-2006, 11:14 AM#9
PipeDream
First element of the array is zero and the last is eight thousand one hundred and ninety one. Looping through all of these will probably run you out of thread.
Quote:
But geez, I've no clue on this next piece: Is there any way an array could have a maximum index? I mean like an array C, and set its max index to C[50], can it be done?
I'm not sure what you mean here. C, after all, has no provisions for bounds checking.
08-08-2006, 11:16 AM#10
Daelin
Oops... my mistake. I was working in paralel with a group loop. :P

Collapse JASS:
set i = 1
loop
    exitwhen i>SizeOfArray
    set a[i]=null
    set i = i + 1
endloop

~Daelin
08-08-2006, 11:45 AM#11
blu_da_noob
Quote:
Originally Posted by PipeDream
First element of the array is zero and the last is eight thousand one hundred and ninety one. Looping through all of these will probably run you out of thread.

I'm not sure what you mean here. C, after all, has no provisions for bounds checking.

I'm fairly sure that 8192 iterations with a simple action (ie setting a variable) doesn't hit the thread limit, although it is probably close.
08-08-2006, 12:05 PM#12
PipeDream
Collapse JASS:
loop
    exitwhen i>SizeOfArray
    set a[i]=null
    set i = i + 1
endloop
look up i
push
look up size
push
compare
conditional jump
look up i
push
literal null
push
set a
look up i
push
literal 1
push
add
set i
jump

18 ops
so you're right, you can run the loop for size of array up to 16k
08-09-2006, 03:14 AM#13
Retro
I mean, could you limit the maximum element of an array? Sorry if it wasn't clear enough before. So instead of 8192, can it be maxed at 50, for example. Thank you.
08-09-2006, 03:27 AM#14
DioD
Array is array, use only first 50 slots, you cant limit or block other slots.

Add global var integer X = 50 and use it inside array control functions.
08-09-2006, 03:38 AM#15
Retro
Alright, thanks for the answers. This thread may rest in peace now.