Jump to content




Vertical "Chat" scrolling

lua help networking

8 replies to this topic

#1 deletedededed

  • Members
  • 13 posts
  • LocationThe Internet

Posted 21 November 2014 - 03:25 AM

I've been working on a chat system for my faction "Oblivion" as said in previous posts. So far I've produced a display/input system using two computers per user. My problem is that once the monitor fills up there is no convenient way to clear the old text from the first line without removing the more recent messages! ex. http://gyazo.com/3f5...3bac46e9523b7cc

Input (To send a message to other users)
rednet.open("top")
var = read()
rednet.broadcast(var)
shell.run("Sender1")

Monitor output (shows messages from yourself and all other users)
rednet.open("top")
m = peripheral.wrap("right")
password = 42
while true do
event, id, message, distance = os.pullEvent("rednet_message")
if password == 42 then
local cX,cY = m.getCursorPos()
m.setCursorPos(1,cY+1)
m.write(message)
if cY >= 25 then ---should clear first 3 lines if there are more then 25 (Max)----------
term.scroll(3)[/color] ---doesn't respond/doesn't give output------------
end
end
sleep(0.1)
end

The commented code is what I'm having issues with


Just for reference, disk drives are disabled on the server (dupe glitches from older versions) so I wanted to keep this code as simple as possible to enter upwards of 10 times.

Edited by kenny_tha_koala, 21 November 2014 - 03:34 AM.


#2 valithor

  • Members
  • 1,050 posts

Posted 21 November 2014 - 03:55 AM

I am not certain of this, but you would probably want to use m.scroll(3) instead of term.scroll(3). Term is still refering to the computer itself, while m is the monitor. Because of this you are telling the computer terminal itself to scroll the text on the computer not the monitor.

Edited by valithor, 21 November 2014 - 03:55 AM.


#3 Dragon53535

  • Members
  • 971 posts
  • LocationIn the Matrix

Posted 21 November 2014 - 04:11 AM

Spoiler
After reading and testing valithor's answer. I can say that his is correct, and easier to use.

Edited by Dragon53535, 21 November 2014 - 05:38 AM.


#4 deletedededed

  • Members
  • 13 posts
  • LocationThe Internet

Posted 21 November 2014 - 08:26 PM

Here is my "Edited" code, It seems now that the monitor wont respond to new output. Anything typed into the Clients simply doesn't affect the server. I did some testing and found the issue but I am not knowledgeable enough to know how to fix it. (problem lines are marked with --Problem)

rednet.open("top")
m = peripheral.wrap("right")

while true do
event, id, message, distance = os.pullEvent("rednet_message")
local cX,cY = m.getCursorPos()
m.setCursorPos(1,cY+1)
m.write(message)
if cY == 25 then --Problem
m.scroll(1) --Problem
end

sleep(0.1)
end

EDIT: With more testing I found that the issue is still scrolling the monitor, The server still runs with the added changes

Edited by kenny_tha_koala, 21 November 2014 - 08:29 PM.


#5 valithor

  • Members
  • 1,050 posts

Posted 21 November 2014 - 10:17 PM

View Postkenny_tha_koala, on 21 November 2014 - 08:26 PM, said:

Here is my "Edited" code, It seems now that the monitor wont respond to new output. Anything typed into the Clients simply doesn't affect the server. I did some testing and found the issue but I am not knowledgeable enough to know how to fix it. (problem lines are marked with --Problem)

rednet.open("top")
m = peripheral.wrap("right")

while true do
event, id, message, distance = os.pullEvent("rednet_message")
local cX,cY = m.getCursorPos()
m.setCursorPos(1,cY+1)
m.write(message)
if cY == 25 then --Problem
m.scroll(1) --Problem
end

sleep(0.1)
end

EDIT: With more testing I found that the issue is still scrolling the monitor, The server still runs with the added changes

I suspect that it is technically working, but you are just writing stuff off of the screen. The y coords for writing is likely greater than the size of the monitor.

Here is how I would fix it.

rednet.open("top")
m = peripheral.wrap("right")

while true do
event, id, message, distance = os.pullEvent("rednet_message")
local cX,cY = m.getCursorPos()
m.setCursorPos(1,cY+1)
m.write(message)
if cY == 25 then --Problem
m.scroll(1) --Problem
m.setCursorPos(24) -- The scroll will clear the 25th line, so you need to set this to the 24th line since you increase the line selected by one a few lines up
end

sleep(0.1)
end

Edited by valithor, 21 November 2014 - 10:23 PM.


#6 deletedededed

  • Members
  • 13 posts
  • LocationThe Internet

Posted 22 November 2014 - 01:03 AM

I've updated my Server to match this format and it seems I am having the issue yet again. The clients are Broadcasting the information, the server is receiving it, however it wont display on the monitors. Yes, I have checked through my code multiple times and copied exactly what changes needed to be made. I don't think the issue is necessary the scrolling its something to do with how order is interpreted into the monitor

#7 Dragon53535

  • Members
  • 971 posts
  • LocationIn the Matrix

Posted 22 November 2014 - 01:21 AM

Perhaps put m.write after your if statement

#8 deletedededed

  • Members
  • 13 posts
  • LocationThe Internet

Posted 22 November 2014 - 02:53 AM

That would just create a missing variable loop. Nothing would ever count text from the first "While true do" statement meaning that the "if cY == 25" would never receive any lines. It would never set of so text would never be wrote. Its like a redundant code where the output triggers the input

Edit: added some quotes

Edited by kenny_tha_koala, 22 November 2014 - 02:53 AM.


#9 Dragon53535

  • Members
  • 971 posts
  • LocationIn the Matrix

Posted 22 November 2014 - 03:12 AM

rednet.open("top")
m = peripheral.wrap("right")
while true do
event, id, message, distance = os.pullEvent("rednet_message")
local cX,cY = m.getCursorPos()
m.setCursorPos(1,cY+1)
m.write(message) --#Move this
if cY == 25 then
m.scroll(1)
m.setCursorPos(24)
end
--#here
sleep(0.1)
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users