The index is outside the given range

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!


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.

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.

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.


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.

I’ll try it. thank you!