Notifications
Clear all

[Closed] Array for Loop index error

– Comments –
/* Hello…I’m a beginner at scripting.
Trying to set up a rollout that will update the current vertex selected, and current frame number.
Having issues with ‘no vertex selected’ … errors out and I can’t figure out how to solve at roughtly line 31
Works fine as long as a mesh object and at least 1 vertex selected
*/
try(destroyDialog Empty_Array)catch()
unregisterTimeCallback time_p
registerTimeCallback time_p

– Start Create Rollout Interface

rollout Empty_Array “Empty Array Error” width:260 height:80
(
– Get Info Grp
GroupBox ‘grp1’ “Get Numbers” pos:[8,10] width:244 height:60 align:#left

label 'lbl_Cvtx' "Current Vtx:" pos:[16,35] width:80 height:16 align:#left
label 'lbl_CvtxNum' "1" pos:[80,35] width:50 height:16 align:#left

label 'lbl_Cfrm' "Current Frm:" pos:[130,35] width:80 height:16 align:#left
label 'lbl_CfrmNum' "1" pos:[195,35] width:50 height:16 align:#left

– End of Buttons / Interface

– Start Timer Section
timer clock “testClock” interval:100
on clock tick do
(
Cfrm = (currenttime)
lbl_CfrmNum.text = (trimright (Cfrm as string) “f”)

		if $.selectedVerts[1].index == undefined then
			(
				print "none selected"
			)
			else
			(
				Cvtx = $.selectedVerts[1].index
				lbl_CvtxNum.text = (Cvtx as string)
				--print ("vertex " + Cvtx as string + " selected")
			)			  
	  )	

– End Timer Section

– Start Functions Section
– Function for Mesh is Selected Section
fn validateSelection = –Selection validation function – Makes sure one mesh is selected
(
if selection.count == 1 then
(
return true
)
else – too many or not enough selected
(
messageBox “Please select just one object”
return false
)
)
– Function for Vertex is Selected Section
fn vertsSelectionvalidate verts= –Vertex selectoin validation function – Makes sure at least one vertex is selected
(
if verts.count > 0 then
(
return true
)

	else -- none selected
	(	
		messageBox "Please select some verts"
		return false
	)
)

– End Functions Section
) – End Rollout

createdialog Empty_Array

unregisterTimeCallback time_p
fn time_p =
(
if currenttime > 0 then
(
CT = (trimright (currenttime as string) “f”)
print CT
)
)
registerTimeCallback time_p

3 Replies

Looks like you are looking for and index of 1, but if you only have one selected vertex, the array index is probably 0 as, I believe, arrays always start with 0. If you only have one item in the array it will have an index of 0. If you try to get the item at index 1 and there isn’t one there, you will get an error.

Change this line:

if $.selectedVerts[1].index == undefined then

to this and see how it goes:

if $.selectedVerts.count == 0 then

That seems to work…
Thanks!