Love it! I lost two games out of three, but I love it anyway! 🙂
One suggestion...
list.any = function()
return self[rnd * self.len]
end function
list = ["Rock", "Paper", "Scissors"]
choice = list.any
This works, as you found, but it gives me the heebie-jeebies. You're creating your own variable called list
that hides the built-in reference to the list datatype. That's a habit that will surely cause you grief someday, so I recommend avoiding it. Pick pretty much any other name, such as:
list.any = function()
return self[rnd * self.len]
end function
choices = ["Rock", "Paper", "Scissors"]
choice = choices.any
or even do a one-liner:
list.any = function()
return self[rnd * self.len]
end function
choice = ["Rock", "Paper", "Scissors"].any
Notice that I didn't change the first use of list
at the top, where you're adding a new list.any
method. The key thing to understand there is that you're adding a method to the list type, so this method becomes available for all lists, no matter how you refer to them.