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

[CC 1.63]mouse events returning incorrect positions | screenshare program

Started by MKlegoman357, 17 June 2014 - 05:32 PM
MKlegoman357 #1
Posted 17 June 2014 - 07:32 PM
Hello, everyone!

I was making a screenshare program that you could use to share your screen onto a monitor. It automatically adapts to both, monitor and terminal, to make a window on both, monitor and terminal, that wouldn't be bigger than the monitor and terminal. I create those windows in the center of the terminal and monitor. Because the window is centered on the terminal I decided to overwrite coroutine.yield so I could overwrite mouse events.

The problem is that positions returned by the raw call to coroutine.yield are incorrect. Moreover, the y or x coordinate sometimes has .5 (for ex.: X: 15; Y: 3.5).

Here is my setup with incorrectly printed positions:

Spoiler

Here's the pastebin link of the program:
http://pastebin.com/0weVvyth

I hope someone will point out that stupid mistake I always make :D/>!
Cranium #2
Posted 17 June 2014 - 07:35 PM
Have you increased or decreased the text scale on the monitor? I think that affects the mouse events.
MKlegoman357 #3
Posted 17 June 2014 - 07:42 PM
Nope. Also, how would that affect mouse clicks?

Also, forgot to mention I tried to overwrite os.pullEventRaw and os.pullEvent too, but they did the same. Although overwriting os.pullEvent returned more accurate positions.

I also noticed that after each mouse click coroutine.yield was called three times: first two returned the same results, third returned different positions. I guess the first call comes from the main parallel inside BIOS.lua file, the second - from multishell and the third from the currently running program (shell).
Lyqyd #4
Posted 17 June 2014 - 07:43 PM
You are doing this to yourself in your transformations of the clicked coordinates in your override of coroutine.yield. When you declare termX and termY, if one of those ends up with a decimal remainder, that will appear in all coordinates meant for the window.
MKlegoman357 #5
Posted 17 June 2014 - 08:18 PM
*facepalm* okay, that was my stupid mistake :D/>, thank you Lyqyd.

I also found out why positions are wrong, coroutine.yield is called multiple times (yet another *facepalm*).