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

Wireless Touchscreen Turtle Control

Started by Trikk, 07 May 2013 - 12:15 PM
Trikk #1
Posted 07 May 2013 - 02:15 PM
Hello, I am new to the computer craft scene. I have written some of my own programs including one that controls a wireless turtle from my computer. The downside is I can only see the turtle on the side of my screen so I'm hoping to find a way to turn a monitor into a remote. So for example the monitor would have Up, Down, Left, Right, Forward, Backward, Dig, ect. When you click, the command is sent to the turtle and then it moves. I've googled and roamed the forums but cannot seem to find anything that will point me in the direction I'm wanting to go. If someone could point me in the direction that would be great. I already have some code written, but as I said I want to use a monitor to control the turtle instead of typing in commands.
Lyqyd #2
Posted 07 May 2013 - 05:05 PM
Split into new topic.
SadKingBilly #3
Posted 07 May 2013 - 05:34 PM
It sounds like you'd rather we point you in the right direction than just give you some code (which is the attitude you should have), so here goes. First, read about the "monitor_touch" event on the wiki, which is used with os.pullEvent(). Then read about term.redirect() to run your program on a monitor instead of the computer. It's basically the same thing as you already have, really. To be honest, I'm not sure myself if you actually need to redirect the output to the monitor or not. But you will need to wrap your monitor using peripheral.wrap() before the computer will handle any monitor_touch events.

term.redirect()
os.pullEvent()
monitor_touch
peripheral.wrap()
Lyqyd #4
Posted 07 May 2013 - 05:53 PM
But you will need to wrap your monitor using peripheral.wrap() before the computer will handle any monitor_touch events.

This is not at all the case.
SadKingBilly #5
Posted 07 May 2013 - 06:01 PM
But you will need to wrap your monitor using peripheral.wrap() before the computer will handle any monitor_touch events.

This is not at all the case.
Really? :o/> I was sure I had read that somewhere. Sorry for the misinformation, I should probably stay out of Ask a Pro unless I'm the one asking. :mellow:/>
Lyqyd #6
Posted 07 May 2013 - 06:04 PM
Being able to admit that you're wrong is almost as good as not being wrong in the first place. Don't sweat it too much. :)/>
sploders101 #7
Posted 07 May 2013 - 06:32 PM
But you will need to wrap your monitor using peripheral.wrap() before the computer will handle any monitor_touch events.

This is not at all the case.
Really? :o/> I was sure I had read that somewhere. Sorry for the misinformation, I should probably stay out of Ask a Pro unless I'm the one asking. :mellow:/>

Yeah I used it to acctually find the monitor on some of my programs. You are somewhat correct. You do need to wrap it to write to it and things like that but no you dont need to wrap it to get touch events.
Engineer #8
Posted 07 May 2013 - 06:57 PM
superanonymous said:
Snip

Actually you dont have to wrap to the monitor to write and stuff. You can call it as following:

peripheral.call('side', 'write', 'my string please')

this gets annoying after a while so wrapping is better imo :P/>
digpoe #9
Posted 08 May 2013 - 10:10 AM
superanonymous said:
Snip

Actually you dont have to wrap to the monitor to write and stuff. You can call it as following:

peripheral.call('side', 'write', 'my string please')

this gets annoying after a while so wrapping is better imo :P/>

But you can make it less annoying:

function writeText(side, str)
 peripheral.call(side, "write", str)
end

writeText("Top", "Hey!") --example
theoriginalbit #10
Posted 08 May 2013 - 10:22 AM
superanonymous said:
Snip

Actually you dont have to wrap to the monitor to write and stuff. You can call it as following:

peripheral.call('side', 'write', 'my string please')

this gets annoying after a while so wrapping is better imo :P/>

But you can make it less annoying:

function writeText(side, str)
peripheral.call(side, "write", str)
end

writeText("Top", "Hey!") --example
I still always suggest that redirecting the terminal is the best/easiest method of printing to a monitor, because then you have text wrapping!


--# get the monitor
local monObj = peripheral.wrap("left")

--# make the term api refer to the monitor object
term.redirect(monObj)

--# all these work just as though you were interacting with the normal terminal, only it effects the monitor
write('This will write, with word wrapping, and supports characters such as \n and \t')
print('This will write, with word wrapping, and supports characters such as \n and \t, and automatically puts a new line at the end')
term.write('Very few times that you need to use this')
term.clear()
term.clearLine()
term.getCursorPos()
term.setCursorPos(1,1)
term.setCursorBlink(true)
term.isColor() --# dependent on the version of CC you are using
term.getSize()
term.scroll(1)
term.setTextColour(colors.white) --# dependent on the version of CC you are using... if using correct one normal monitors can go between black and white, advanced can do all colours
term.setBackgroundColour(colors.white) --# dependent on the version of CC you are using... if using correct one normal monitors can go between black and white, advanced can do all colours

--# this is the only thing that needs to be called on the monitor object
monObj.setTextScale(2)

--# make the term api write to the computer terminal again
term.restore()
sploders101 #11
Posted 08 May 2013 - 01:24 PM
superanonymous said:
Snip

Actually you dont have to wrap to the monitor to write and stuff. You can call it as following:

peripheral.call('side', 'write', 'my string please')

this gets annoying after a while so wrapping is better imo :P/>

Yeah I forgot about that. I used it for a while and finally gave up and said: "forget this! I'm going back to wrapping even for 1 function!"
:P/>
Trikk #12
Posted 08 May 2013 - 02:02 PM
Thanks for all the replies. I actually figured it out by searching further on google, youtube and these forums. I did use the peripheral wrap. I did have a few difficulties because I didn't realize that you needed an advanced monitor to actually use the touch screen function. It took me half an hour to figure it out, but I did. Its functional now, but its a bit ugly. Basically it takes up two screens, has a list of commands, and when you right click one the turtle responds. I plan to actually release it to the public with a video or something when I've made it pretty.

Thanks for all your quick replies though, the support is appreciated.
logwet #13
Posted 14 July 2013 - 11:23 PM
Nice idea, can you make a program like this for me please ( i'm really bad at Lua even though I love computercraft :P/> so I basically get programs of other people) I need this code for a "Remote-Turtle-Rescue" program that i'm making, all credit will be given where credit is due :)/> thanks
Tejprulle #14
Posted 15 July 2013 - 02:35 AM
Event though it's not as fun, you could use direwolf20's buttonAPI to create neat and simple buttons!
albrat #15
Posted 15 July 2013 - 11:01 AM
Event though it's not as fun, you could use direwolf20's buttonAPI to create neat and simple buttons!
re-use working code O.o