3 posts
Posted 03 June 2014 - 06:19 PM
Hi there!
So I'm new (as in new-new) to CC, and so I was wondering if someone would be able to tell me in relatively simple terms how to create something like an in-game chatroom, but not the kind that connects to an IRC.
What I was thinking of would be going up to my monitor and typing something in which a friend at another one could see and reply to, similarly to Minecraft chat, but able to possibly be saved in a log as well. Perhaps I could also do this from one of those portable computers?
Cheers in advance :)/>
49 posts
Location
United States (EST)
Posted 03 June 2014 - 06:34 PM
-snip-
Well, just to bring your vocabulary up to speed: A monitor is not a computer, it cannot do anything except display something when a computer tells it to, much like a real life monitor. A computer does all the computer functions, and can interact with things connected to it (i.e. a monitor). A turtle is a computer that can be fueled and move on its own and break blocks, among other things. So I assume when you say monitor, you mean computer, and when you say portable computer, you mean a turtle, correct?
Whitecatblack
115 posts
Posted 03 June 2014 - 06:41 PM
A monitor is not a computer, it cannot do anything except display something when a computer tells it to,
It has touch screen capabilities..
here is the link to the wiki page
Edited on 03 June 2014 - 04:42 PM
1220 posts
Location
Earth orbit
Posted 03 June 2014 - 06:43 PM
Keep in mind, only advanced monitors have touch capability, standard monitors do not.
49 posts
Location
United States (EST)
Posted 03 June 2014 - 07:00 PM
It has touch screen capabilities..
He suggested there was going to be typing involved with sending the message, so I am asking him for clarification, especially since he said he is very new to CC, he may not know the difference.
Whitecatblack
7083 posts
Location
Tasmania (AU)
Posted 04 June 2014 - 02:38 AM
By "monitor" he's referring to "any device with a display, which you can type into" (computers/turtles/pocket computers all happen to have built-in displays), and by "portable computer" he means "pocket computer". I think it's a
fair assumption that he's planning on typing into something that
lets you type into it… anything beyond that definition is irrelevant to the question at hand. ;)/>
Netroth, it's difficult to know where to start with you without knowing your previous programming experience - are you only new to CC? Know anything about Lua? What about coding in other languages?
Assuming you've a basic idea of variables/loops/tables/etc already (sing out if you're not sure what those terms mean), a good place to start would be reading through the
rednet API documentation.
… which I suppose still hasn't been fully updated for 1.6. With any luck that'll magically get done today.
3 posts
Posted 04 June 2014 - 05:05 AM
I'm aware of the difference between a computer and a monitor but it was like 6am so I just said monitor, although I was also thinking of the advance monitor touch capability, where I could make keys which flashed when I "pressed" them. Yes, I was talking about the pocket computer :P/> I don't know any lua but I'm willing to learn and from what I have seen I would think it shan't take too long to do so. Perhaps just throw a whole lot of info at me, I'm pretty good at taking stuff and translating it through the help of wikis and such, while finding it easier to learn from an example which I will actually end up using :P/>
In short, I know everything I need except lua XD
Edited on 04 June 2014 - 03:47 AM
7083 posts
Location
Tasmania (AU)
Posted 04 June 2014 - 05:46 AM
Righto. I guess I'll translate to "no knowledge of programming at all".
These two tutorials are probably the best start as far as ComputerCraft itself goes, then take a read through
this lot to get you started on the Lua-coding side of things.
repl.it is dead handy for quickly testing out how generic snippets of code behave (it's often faster to test things there than in ComputerCraft, though you don't get ComputerCraft's unique features), and
this page leads to info on most ComputerCraft-specific functions.
3 posts
Posted 06 June 2014 - 06:41 AM
These tutorials are splendid, thank you very much :)/> Just one more question, and that would be about monitors. Is there a way that I can do something on the computer which displays the same on the monitor, without having to run the monitor program each time. Say I want to type something on my computer, and have it show up on the monitor as I type. Is that possible to do?
3057 posts
Location
United States of America
Posted 06 June 2014 - 03:25 PM
term.redirect( mon ) will send everything rendered on the terminal to the specified monitor. There's only one problem: you can't see it on the terminal any more. I have devised a workaround that may or may not work, see if you can understand it
Spoiler
oldterm = {} --#creating a backup of term
for k, v in pairs( term ) do
oldterm( k ) = v
end
function redirect( mon ) --#this function needs a wrapped monitor
for k, v in pairs( term ) do --#this next bit overwrites the term api
term[k] = function( ... )
oldterm[k]( ... )
mon[k]( ... )
end
end
end
function restore() --#function to restore the old term api
for k, v in pairs( term ) do
term[k] = oldterm[k]
end
end
--#now, to call this
local monitor = peripheral.wrap( "right" ) --#assuming the monitor is on the right
redirect( monitor )
term.clear() --#clears both the monitor and the terminal
term.write( "hello" ) --#writes "hello" on the monitor and the terminal
restore()
7508 posts
Location
Australia
Posted 06 June 2014 - 03:32 PM
term.redirect( mon ) will send everything rendered on the terminal to the specified monitor. There's only one problem: you can't see it on the terminal any more. I have devised a workaround that may or may not work, see if you can understand it
Spoiler
oldterm = {} --#creating a backup of term
for k, v in pairs( term ) do
oldterm( k ) = v
end
function redirect( mon ) --#this function needs a wrapped monitor
for k, v in pairs( term ) do --#this next bit overwrites the term api
term[k] = function( ... )
oldterm[k]( ... )
mon[k]( ... )
end
end
end
function restore() --#function to restore the old term api
for k, v in pairs( term ) do
term[k] = oldterm[k]
end
end
--#now, to call this
local monitor = peripheral.wrap( "right" ) --#assuming the monitor is on the right
redirect( monitor )
term.clear() --#clears both the monitor and the terminal
term.write( "hello" ) --#writes "hello" on the monitor and the terminal
restore()
buggy at best. especially with functions such as
getSize which return values.
3057 posts
Location
United States of America
Posted 06 June 2014 - 03:35 PM
term.redirect( mon ) will send everything rendered on the terminal to the specified monitor. There's only one problem: you can't see it on the terminal any more. I have devised a workaround that may or may not work, see if you can understand it
Spoiler
oldterm = {} --#creating a backup of term
for k, v in pairs( term ) do
oldterm( k ) = v
end
function redirect( mon ) --#this function needs a wrapped monitor
for k, v in pairs( term ) do --#this next bit overwrites the term api
term[k] = function( ... )
oldterm[k]( ... )
mon[k]( ... )
end
end
end
function restore() --#function to restore the old term api
for k, v in pairs( term ) do
term[k] = oldterm[k]
end
end
--#now, to call this
local monitor = peripheral.wrap( "right" ) --#assuming the monitor is on the right
redirect( monitor )
term.clear() --#clears both the monitor and the terminal
term.write( "hello" ) --#writes "hello" on the monitor and the terminal
restore()
buggy at best. especially with functions such as
getSize which return values.
Notice I said it may not work… wrote it in ~2 minutes. If you want to improve it please do. Didn't someone make a "synch" api for this?
7508 posts
Location
Australia
Posted 06 June 2014 - 03:37 PM
Notice I said it may not work… wrote it in ~2 minutes. If you want to improve it please do. Didn't someone make a "synch" api for this?
not now, bed time. indeed people have made APIs to do this, I have done similar in the past too.
There are also in-game "chatroom" programs on the forums, along with being packaged in ComputerCraft 1.63
Edited on 06 June 2014 - 01:37 PM
7083 posts
Location
Tasmania (AU)
Posted 07 June 2014 - 02:22 AM
Say I want to type something on my computer, and have it show up on the monitor as I type. Is that possible to do?
Are you saying you want your code to do this, or are you saying you want to be able to use the likes of the "edit" script like this?
120 posts
Posted 09 June 2014 - 06:13 AM
Rednet is what you are looking for.
Look into rednet.open(), rednet.broadcast(), rednet.send(), and rednet.receive().
We were working on MineBook (right now it is SUPER basic), and this is what it was:
Host:
print("MineBook Host 0.0.1")
rednet.open("left")
while true do
id, message = rednet.receive()
print("Sent from" .. id)
print(message)
sleep(1)
end
Client:
sv = 238
rednet.open("right")
while true do
print("Message in quotes:")
msg = read()
rednet.send(sv, msg)
sleep(1)
term.clear()
end
The client is larger then the server because it has to hold the server ID.
Edited on 09 June 2014 - 04:15 AM
131 posts
Posted 09 June 2014 - 07:57 PM
These tutorials are splendid, thank you very much :)/> Just one more question, and that would be about monitors. Is there a way that I can do something on the computer which displays the same on the monitor, without having to run the monitor program each time. Say I want to type something on my computer, and have it show up on the monitor as I type. Is that possible to do?
Try this code:
function peripheral.link(...)
local peripherals = {...}
local nperipherals = #peripherals
for k in pairs(peripherals[nperipherals]) do
peripherals[k] = function(...)
for i = 1, nperipherals do
if i == nperipherals then
return peripherals[i][k](...)
else
peripherals[i][k](...)
end
end
end
end
return peripherals
end
term.redirect(peripheral.link(peripheral.wrap("monitor_side"), term.current()))
That should allow you to use the term API as normal, but it'll write to both the monitor and the computer screen at the same time.
Edited on 09 June 2014 - 06:12 PM