Well, let's see…
If the first timer expires
or you click, then randomSpawn() gets called.
randomSpawn() then calls checkClick() (it shouldn't). checkClick() then tries to pull a second event (it shouldn't), and regardless as to where that click is, calls randomSpawn() again (it
really shouldn't). That then calls checkClick() again, and so on.
Hence you never again check to see if your timers have expired and the program eventually crashes after a hundred clicks or so due to a stack overflow (when a function calls another function, the first function doesn't end until the second one does - if they just keep calling each other recursively like that, then eventually the build-up of running functions causes a crash).
So:
- randomSpawn() should spawn a dot, and do nothing else. Instead, have the while loop at the bottom of the script call checkClick() directly before calling randomSpawn().
- xrdn and yrdn would likely be best defined as local to the whole script, not just to the randomSpawn() function. That, or randomSpawn() should return them (though I'd think the former to be easiest).
- checkClick() should not try to pull another event. Instead, pass the click co-ordinates that the while loop at the bottom of the script already collected to it.
- Likewise, checkClick() should only check clicks. It shouldn't try to call randomSpawn() again.
It may help your understanding to stress that doing this:
event,button,x,y = os.pullEvent("mouse_click")
Is much the same as doing this:
myEvent = {os.pullEvent("mouse_click")}
Only difference being, the second method takes the event, button and x/y co-ords and dumps them into a table for you. myEvent[1] gets the event name, myEvent[2] gets the button, myEvent[3] gets the x co-ord and you can probably guess where the y co-ord goes.
You may only pull a given event once - it's then removed from the event queue, and can't be pulled a second time. If you don't specify an event type when pulling then
any event-type may be returned. If you
do specify an event type, then the command pulls as many events as it takes until it gets the sort you asked for -
throwing away any it finds that don't match.