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

Need help with peripherals

Started by graywolf69, 18 January 2015 - 02:48 AM
graywolf69 #1
Posted 18 January 2015 - 03:48 AM
So I have this program for touchscreen monitors. I'm converting it to work on 2 monitors simultaneously for airlocks that i can open and close from both sides. I have a couple of problems with it though:

1. Only one monitor displays the buttons, specifically the left one.

2. I tried to make it detect 2 monitors connected to it without me wrapping each individually (Not all the monitors are connected to the same side of the computer, some computers have a monitor on back and right, some on back and left, etc.)

I'm guessing its something like it doesn't run the commands regarding the monitor m2 until all code for m1 is complete, which it is never complete. Anyone know what's going wrong? Thank you so much basically I have to abandon my space station until the airlock doors work right :mellow:/> so help is greatly appreciated.

http://pastebin.com/2kYK0waj
Edited on 18 January 2015 - 02:51 AM
Quintuple Agent #2
Posted 18 January 2015 - 04:46 AM
Your problem is that you have a repeat until loop for monitor 1 that will keep looping and never let the next part of your code draw monitor 2

A fix to your problem would be to draw monitor 1 and 2 first then have your code for checking monitor_touch

I have rewritten the code along with adding a function to draw your menu to the monitor, that way you don't have 2 identical lines of code.

http://pastebin.com/V4YLuDeW

Edit: I just updated it, I fixed some formatting issues (used like 5 spaces instead of a tab) and I passed the mouseWidth and Height off in the function instead of being variables to the entire script
Edited on 18 January 2015 - 03:54 AM
graywolf69 #3
Posted 18 January 2015 - 05:19 AM
Thanks so much!

Also I think I know a way to find all nearby peripherals and wrap them, not specifically just monitors because I don't need it. I'm guessing there's a way to make it shorter but will this work? Basically I made it detect if there was a peripheral on each side, if there was it would wrap it, then later I had it check again if there was a peripheral on each side, and if there was it would run the monitorDraw function for that peripheral.

http://pastebin.com/71ixNkvH
Edited on 18 January 2015 - 04:51 AM
Quintuple Agent #4
Posted 18 January 2015 - 06:42 AM
Yes, there is a much easier way.
I will post an updated code shortly

Edit: Ok, here you go http://pastebin.com/Vki4797z

This will search for all monitors (even those connected by wired modems) and draw to them

What this does is it uses peripheral.getNames() which returns a list of all attached peripherals
http://computercraft.info/wiki/Peripheral.getNames

If you have any questions feel free to ask
Edited on 18 January 2015 - 05:53 AM
graywolf69 #5
Posted 18 January 2015 - 02:01 PM
Thanks, awesome!

EDIT: Well, it prints to all monitors just fine, but when you changed the checkClickPosition() function it made it so only the top button worked (basically when u changed it u left part of the old code and put it in a second place too if that makes sense). I changed it to the original code that worked before and now neither button works. Heres how it is now:

http://pastebin.com/gJsmrmxt

Also I added a line after the –body comment to turn redstone on initially, but that shouldn't matter. Help is appreciated!
Edited on 18 January 2015 - 01:57 PM
Quintuple Agent #6
Posted 18 January 2015 - 04:15 PM
Oh, lol, i see.
I forgot to remove the

mouseHeight == 2
on the first if else. If you remove it it should work fine. I removed the extra mouseHeight in the code.
http://pastebin.com/Vki4797z

Edit: I am not sure why changing checkClickPosition() back like that made it not work at all. If you switch back over to mine, tell me if that is fixed or not.

Another Edit!: I do notice one thing, you have

if mouseWidth >= 1 and mouseWidth <= 8 and mouseHeight == 2 then
           rs.setOutput("bottom",true)
elseif mouseWidth >= 1 and mouseWidth <= 8 and mouseHight == 4 then
           rs.setOutput("bottom",false)
end
On the second half, you have 'mouseHight' not 'mouseHeight'
Edited on 18 January 2015 - 03:27 PM
graywolf69 #7
Posted 18 January 2015 - 04:45 PM
Don't think it will work, I also tried that. Also you removed the lines mouseHeight=0, mouseWidth=0, might be another reason.
Quintuple Agent #8
Posted 18 January 2015 - 04:56 PM
I just tested the script and it worked fine for me.

Also, removing the mouseHeight and mouseWidth would not have that effect. What i did was instead of having mouseHeight and mouseWidth be available to the entire script, I passed it though to the function checkClickPosition()
Edited on 18 January 2015 - 03:57 PM
graywolf69 #9
Posted 18 January 2015 - 10:09 PM
Yep, works perfect! Thanks a lot!