5 global variables never unset. Also, if (%dice <= 0) || %sides <= 0) { Looks as if it may not work..