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

Monitor Touchscreen Woes

Started by Tassyr, 03 August 2015 - 07:35 AM
Tassyr #1
Posted 03 August 2015 - 09:35 AM
So I'm still fighting making a keypad entry system. I got the housekeeping set up- it automatically selects the monitor, it lets you set the redstone output side, it lets you lock in the code.

So far, so good.

But after well over two hours I can't get the touchscreen function to work worth a damn. No matter what I do, I can't figure out the variables there. Nor how to do the second part;



My plan was that you put in the numbers and either hit clear (reset to no input recorded) or enter (Submit code.)
And that four asterisks would appear at that upper grey bar as you entered the code. But I can't figure even where to begin with those.

… help?


-- housekeeping; this area is for cleaning up
-- redstone output sides.
term.clear()
term.setCursorPos(1,1)
term.write("Enter redstone output side:")
term.setCursorPos(30,1)
local sides = {}
  for k, v in pairs( rs.getSides() ) do
	sides[ v ] = true
  end
local side
repeat
  side = read ()
until sides[ side ]

-- test of redstone output
redstone.setOutput(side, true)
sleep(1)
redstone.setOutput(side, false)

-- autodetection and assignment of monitor side
if peripheral.isPresent("top") == true then
monitor = peripheral.wrap("top")

elseif peripheral.isPresent("bottom") == true then
monitor = peripheral.wrap("bottom")

elseif peripheral.isPresent("left") == true then
monitor = peripheral.wrap("left")

elseif peripheral.isPresent("right") == true then
monitor = peripheral.wrap("right")

elseif peripheral.isPresent("front") == true then
monitor = peripheral.wrap("front")

elseif peripheral.isPresent("back") == true then
monitor = peripheral.wrap("back")

else
  term.clear()
  term.setCursorPos(1,1)
  print("NO MONITOR ATTACHED!")
  sleep(1)
  os.shutdown()
end

--enter code
term.clear()
term.setCursorPos(1,1)
print("Enter Password- four digits, numbers only.")
local code
repeat
  code = read()
until #code == 4


term.clear()
monitor.setTextScale(0.5)
while true do
--begin monitor pattern
monitor.setBackgroundColor(colors.gray)
monitor.setTextColor(colors.black)
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setBackgroundColor(colors.lightGray)
monitor.write("			   ")
monitor.setBackgroundColor(colors.lightGray)
monitor.setCursorPos(4,3)
monitor.write("		 ")
monitor.setCursorPos(4,4)
monitor.write(" 1  2  3 ")
monitor.setCursorPos(4,5)
monitor.write("		 ")
monitor.setCursorPos(4,6)
monitor.write(" 4  5  6 ")
monitor.setCursorPos(4,7)
monitor.write("		 ")
monitor.setCursorPos(4,8)
monitor.write(" 7  8  9 ")
monitor.setCursorPos(4,9)
monitor.write("		 ")
monitor.setCursorPos(4,10)
monitor.setBackgroundColor(colors.red)
monitor.write("CLR")
monitor.setBackgroundColor(colors.lightGray)
monitor.setCursorPos(7,10)
monitor.write(" 0 ")
monitor.setBackgroundColor(colors.lime)
monitor.setCursorPos(10,10)
monitor.write("ENT")








sleep(1)
end

And yes, I've deleted the section of code that was my os.pull. It just kept erroring, no matter what the hell I did. There IS a nice huge gap where it SHOULD be though.
Edited on 03 August 2015 - 07:36 AM
Lupus590 #2
Posted 03 August 2015 - 10:08 AM
What version of computercraft are you using?
Edited on 03 August 2015 - 08:17 AM
Tassyr #3
Posted 03 August 2015 - 10:11 AM
1.63 according to tekkit's info panel.
Lupus590 #4
Posted 03 August 2015 - 10:17 AM
The easiest way would be to use a buttion API, touchpoint is a popular one.

Also this may be useful: http://computercraft.info/wiki/Peripheral.find
Edited on 03 August 2015 - 08:19 AM
Tassyr #5
Posted 03 August 2015 - 10:26 AM
The easiest way would be to use a buttion API, touchpoint is a popular one.

Also this may be useful: http://computercraft...Peripheral.find

Only one question. How do I install an API?
Lupus590 #6
Posted 03 August 2015 - 10:46 AM
just download the file like you would a program using pastebin (or the method that the author says)

then to load the API in your program add this line at the top
 os.loadAPI("fileName") 
where filename is the name and path of the file of the API

I can make a youtube video of me installing touchpoint if required
Tassyr #7
Posted 03 August 2015 - 10:47 AM
just download the file like you would a program using pastebin (or the method that the author says)

then to load the API in your program add this line at the top
 os.loadAPI("fileName") 
where filename is the name and path of the file of the API

I can make a youtube video of me installing touchpoint if required

Seems simple enough but will I have to do this for -every- time I use this program on a new computer? Is there no way to just… slap it in a folder and have it added to the stock APIs?
Lupus590 #8
Posted 03 August 2015 - 10:56 AM
The touchpoint API is licenced as MIT, you could merge it into your program and have it as (what I'd call) a psudo-API, this will bloat your program but mean you only have one file to work with.
Tassyr #9
Posted 03 August 2015 - 10:57 AM
I… have no idea what that means.
Lupus590 #10
Posted 03 August 2015 - 11:38 AM
What I mean by a psudo-API is replicating the loadAPI() result in a program by placing the API code in the same file as the program that will use it.

I've never used touchpoint before so my knowledge of it is a bit limited.

Your best method is to use the API as intended, I.E. have the API as a separate file
Edited on 03 August 2015 - 09:41 AM
Lyqyd #11
Posted 03 August 2015 - 03:39 PM
Seems simple enough but will I have to do this for -every- time I use this program on a new computer? Is there no way to just… slap it in a folder and have it added to the stock APIs?

You could use a resource pack to add the API to the /rom/apis folder in the computers, which would cause it to be automatically loaded on startup. There is a sticky thread in the Programs section that details how to create a resource pack. This option will only work if you're playing in single player, or if you control the server you play on.
flaghacker #12
Posted 03 August 2015 - 05:56 PM
It's not really an answer to you question, but you could replace this mess:


-- autodetection and assignment of monitor side 
if peripheral.isPresent("top") == true then 
  monitor = peripheral.wrap("top") 
elseif peripheral.isPresent("bottom") == true then 
  monitor = peripheral.wrap("bottom") 
elseif peripheral.isPresent("left") == true then 
  monitor = peripheral.wrap("left") 
elseif peripheral.isPresent("right") == true then 
  monitor = peripheral.wrap("right") 
elseif peripheral.isPresent("front") == true then 
  monitor = peripheral.wrap("front") 
elseif peripheral.isPresent("back") == true then 
  monitor = peripheral.wrap("back") 
else 
  term.clear() 
  term.setCursorPos(1,1) 
  print("NO MONITOR ATTACHED!") 
  sleep(1) 
  os.shutdown() 
end

by this:


local monitor = peripheral.find("monitor")

if not monitor then
  term.clear() 
  term.setCursorPos(1,1) 
  print("NO MONITOR ATTACHED!") 
  sleep(1) 
  os.shutdown() 
end

Anoter tip:
if [condition] == true then
is the same as
if [condition] then
TheOddByte #13
Posted 03 August 2015 - 09:22 PM
Another tip:
if [condition] == true then
is the same as
if [condition] then
and

if <condition> == false then
is the same as

if not <condition> then
Bomb Bloke #14
Posted 04 August 2015 - 02:15 AM
Regarding the "having to install touchpoint" "issue", as far as I'm concerned the solution is to simply have your script do it for you. Isn't the whole point of programming to give instructions once, then have the computer do the work ever after? :)/>

if not touchpoint then                                                                                -- If the touchpoint API isn't already loaded,
        if not (fs.exists("touchpoint") or fs.exists(shell.resolve("touchpoint"))) then                -- then if the file doesn't exist,
                shell.run("pastebin get pFHeia96 touchpoint")                                           -- download it to the current folder
                os.loadAPI(shell.resolve("touchpoint"))                                                 -- then load it.
        else os.loadAPI(fs.exists("touchpoint") and "touchpoint" or shell.resolve("touchpoint")) end   -- else load it from root or the current folder, whichever happens to contain it.
end