Log in

View Full Version : Array - newbie question


rgr
15th March 2025, 15:04
First attempt with arrays...

function Testaaa(array Clips) {
return Clips[0][0]
}

a=ColorBars (720, 576, "YUV420").trim(1,1).subtitle("a")
b=ColorBars (720, 436, "YUV420").trim(1,1).subtitle("b")
c=ColorBars (1920, 600, "YUV420").trim(1,1).subtitle("c")
d=ColorBars (650, 650, "YUV420").trim(1,1).subtitle("d")

Clips = [a,b,c,d]
Testaaa(Clips)


Why do I need to use "return Clips[0][0]" and not "return Clips[0]".
This is a 1D array. Am I missing something?

StvG
15th March 2025, 21:01
Use the specific array parameter (clip_array) instead the generic array parameter (array or val_array).

function Testaaa(clip_array Clips) {
return Clips[0]
}

a=ColorBars (720, 576, "YUV420").trim(1,1).subtitle("a")
b=ColorBars (720, 436, "YUV420").trim(1,1).subtitle("b")
c=ColorBars (1920, 600, "YUV420").trim(1,1).subtitle("c")
d=ColorBars (650, 650, "YUV420").trim(1,1).subtitle("d")

Clips = [a,b,c,d]
Testaaa(Clips)

rgr
15th March 2025, 23:12
OK, sure. Thanks.

rgr
27th March 2025, 21:13
Another problem.


arr=[]
for (i=0,FrameCount) {
arr=ArrayAdd(arr,999.00)
}
...
subtitle(String(ArraySize(arr))) # <-- works OK - correct value 1015
...
outputStr= ""
for (i=0,ArraySize(arr)) { #1015 elements
outputStr=outputStr+String(i)+","+String(arr[i])+chr(10) # <-- line 70
}


And why does everything work OK up to the for loop, but not in the loop?

[avisynth @ 0000024337b9e540] ArrayGet: Array index out of range. Problematic index count: 1
(cut.avs, line 70)
(cut.avs, line 71)

StvG
27th March 2025, 22:33
Because for (i=0,ArraySize(arr)) means elements from 0 to the array size inclusive but in fact the elements are from 0 to ArraySize(arr)-1 inclusive.

rgr
27th March 2025, 22:54
Ouch, and the best thing is that I had it written correctly.

I just didn't understand at all what the "problematic index count" was about -- I thought the index in the array was incorrect.