The index is outside the given range

Hi!
I am trying to get difference between two values of a list. (x[0] - x[1])
But when the size of a list is 1, index error occured.
so I want to set default value when the size of a list is 1.

I used == node and check whether the count and ‘1’ are equal to each other or not.
if the count equals 1, set value 3500.
if not equals, set value (x[0] - x[1]). <– I don’t know what to do.

thank you for your time!

image

Does your if node not return the desired option? In this case 3500? The error is inconsequential in that case as it will not be there if that is the option that is passed :slight_smile:

Hi @minji

What is your goal here? Show complete graph with all the previews visible.

Hi
this is complete graph.
I edited DynamoPlayer sample script ‘Add Another Level Above Existing Upper Story Level.dyn’.

this is example.

I edited some parts.
Capture

I want to handle exception when the size of a list is 1.

Building the functions into your If statement will allow them to run without errors.
If list length is 1, do this. If list length is not 1, do that.
image

@Nick_Boyts

thanks! it works!!:smiley:

but is there any way to do this without using the code block?

The code block just uses Design Script syntax (and a little shorthand) to make the function more compact, but you can write the exact same thing using Count and GetItemAtIndex nodes with an If node.

@Nick_Boyts
I’ll try it. thank you!