This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Zarty55's profile picture

Get if there is a event in the event queue?

Started by Zarty55, 20 January 2014 - 08:17 PM
Zarty55 #1
Posted 20 January 2014 - 09:17 PM
So, I'm creating a paint-like program, the one that comes with the game doesn't work well for me.

My problem is, my drawing function is kinda slow in large windows, there isn't much for me to do about that really. My problem is that the event queue get's clogged up when I have too much mouse_drag events. You see, my update function is like that:

(This is inside a while loop)
-Gets event
-Handles event
-Draw window
-Repeat

When the event queue get's clogged up the program runs "in the past". My only solution to make the thing smoother is to check 3 times for events in one update. But the problem is that the program gets stuck if there is no event, then the program only updates when there is 3 events in the queue. My solution to this would be to check if there is more than one event in the queue and then handle them all.

I've found this:
http://www.computercraft.info/forums2/index.php?/topic/13900-oseventcount-the-number-of-events-in-the-queue/

To be fair, I don't know why it wasn't added before. There might be a way to get around this, but why not just have this simple solution to make it work?

I've programmed in Lua before, I'm just kinda new to CC.
Lyqyd #2
Posted 20 January 2014 - 09:56 PM
Checking to see if there is an event in the queue is totally unnecessary. You should focus instead on improving your event handling. For instance, if you draw only the necessary changes rather than redrawing everything on every event, you'd likely see vast improvements.