Can somebody explain some code for me please

Hi all,

I have a line of code from a module and I was was wondering if anyone could explain the line for me please so I have a better understanding of what is happening…

index = math.min(math.max(index,1),#backpack)

‘backpack’ is a table of items.

Many thanks.

First,

math.max(index,1)

this finds the maximum value from the given inputs, i.e. it returns the value of index or 1, whichever is higher.

Then

math.min(math.max(index,1),#backpack)

this finds the minimum value from the given inputs, i.e. it returns the value of the previous function or #backpack (i.e. number of items in backpack table), whichever is lower.

Wow! Quick answer!

That is brilliant.  Nice concise answer and I actually understood it.

[happy face]

First,

math.max(index,1)

this finds the maximum value from the given inputs, i.e. it returns the value of index or 1, whichever is higher.

Then

math.min(math.max(index,1),#backpack)

this finds the minimum value from the given inputs, i.e. it returns the value of the previous function or #backpack (i.e. number of items in backpack table), whichever is lower.

Wow! Quick answer!

That is brilliant.  Nice concise answer and I actually understood it.

[happy face]