Node links won't work

I’m trying to hook up some links and I’ve run into a problem.
The first two links hook-up but the third one won’t.

import bpy

tree = bpy.context.scene.node_tree
links = tree.links




render_layer = bpy.data.scenes[bpy.context.scene.name].render.layers.new(name = 'test')
        
render_layer.use_pass_z = True
render_layer.use_pass_vector = True
#render_layer.use_pass_object_index = True




#Render node.
render_node = tree.nodes.new('CompositorNodeRLayers')
render_node.layer = "test"
           


#Vector blur node.
vec_blur_node = tree.nodes.new("CompositorNodeVecBlur")
vec_blur_node.location = render_node.location.x + 300, render_node.location.y




#Link them up.
links.new(render_node.outputs[1],vec_blur_node.inputs[0])   #Alpha to Image
links.new(render_node.outputs[2],vec_blur_node.inputs[1])   #Z to Z
links.new(render_node.outputs[3],vec_blur_node.inputs[2])   #Speed to Speed

And if I create some more sockets below the ‘Speed’ output, like ‘#render_layer.use_pass_object_index = True’
I can’t hook that one up either.

The problem seems to be with the Render Layers outputs not the inputs on other nodes.

Is this a bug?

‘Speed’ on the RenderLayers outputs is index 5, 3 is ‘Normal’. The pass object index is 14. I guess they have set indexes and aren’t indexed in the order you enable them.

you should use link names instead of link indices numbers, it’s much easier to read. From 2.68, 2.67 has a bug about names, only indices supported

Not only that, it’s much easier to code. In this situation, you would have to know all the indexes just to get it to work right, as opposed to just dropping the name in there.

Thanks guys that clears it up.