I have a stack of cards that I want to select by touch. This code used to work. I changed something in Main and now it doesn’t work, but I cannot for the life of me figure out what I did to it.
function Stack:selectCards(n1) print(n1) if n1<1 then self.selected=-1 elseif n1>#self.cards then self.selected=#self.cards else n1 = #self.cards+1-n1 self.selected=n1 end end
The problem is when calling the function, n1 receives a nil value. The print statement proves it then the condition fails.
The only thing I believe I did between working and not working was remove the test line in Main from setup() to a function dependent on the touch handler. When it broke the code, I moved it back to setup. Neither works now. I thought maybe I created a variable name clash, so I changed it from n to n1 and it still doesn’t work.
I know it has to be something stupid and I’m going to be embarrassed when I realize how simple it was.
The line in Main is: stacks[stackFrom].selectCards(1) and again, it is calling the function, just the parameter is nil.