Posted 19 May 2013 - 12:54 PM
I used the following code:
What I am trying to do is when the computer recieves a message it will add it to the table"ChatMessages" and then it will printout all of the stuff in the table
When I broadcast a message from a computer right next to it,It fails to print the message out and the screen remains blank
EDIT:
now the problem is when i send a message it overwrites the old text and doesnt go down a line
the way to fix it is by editing the for loop like this:
local w,h = term.getSize()
local sides = {"top","bottom","left","right","front","back"}
local Version = "Block talk v.1"
local name = "nil"
local ChatMessages = { }
local function printCentered(str,ypos)
term.setCursorPos(w/2-#str/2,ypos)
term.write(str)
end
local function printRight(str,ypos)
term.setCursorPos(w-#str,ypos)
term.write(str)
end
local function discover()
for i = 1,#sides do
if peripheral.isPresent(sides[i]) then
if peripheral.getType(sides[i]) == "modem" then
rednet.open(sides[i])
end
end
end
end
discover()
while true do
term.clear()
printCentered("-Welcome to "..Version.."-",1)
printCentered(string.rep("-",w),2)
e = {os.pullEvent()}
if e[1] == "rednet_message" then
table.insert(ChatMessages,e[3])
end
local y = 3
for i = 1,#ChatMessages do
local x = 1
term.setCursorPos(x,y)
print(ChatMessages[i])
local y = y + 1
end
end
What I am trying to do is when the computer recieves a message it will add it to the table"ChatMessages" and then it will printout all of the stuff in the table
When I broadcast a message from a computer right next to it,It fails to print the message out and the screen remains blank
EDIT:
local w,h = term.getSize()
local sides = {"top","bottom","left","right","front","back"}
local Version = "Block talk v.1"
local name = "nil"
local ChatMessages = { }
local function printCentered(str,ypos)
term.setCursorPos(w/2-#str/2,ypos)
term.write(str)
end
local function printRight(str,ypos)
term.setCursorPos(w-#str,ypos)
term.write(str)
end
local function discover()
for i = 1,#sides do
if peripheral.isPresent(sides[i]) then
if peripheral.getType(sides[i]) == "modem" then
rednet.open(sides[i])
end
end
end
end
discover()
while true do
term.clear()
printCentered("-Welcome to "..Version.."-",1)
printCentered(string.rep("-",w),2)
local y = 3
for i = 1,#ChatMessages do
local x = 1
term.setCursorPos(x,y)
print(ChatMessages[i])
local y = y + 1
end
e = {os.pullEvent()}
if e[1] == "rednet_message" then
table.insert(ChatMessages,e[3])
end
end
now the problem is when i send a message it overwrites the old text and doesnt go down a line
the way to fix it is by editing the for loop like this:
Spoiler
local w,h = term.getSize()
local sides = {"top","bottom","left","right","front","back"}
local Version = "Block talk v.1"
local name = "nil"
local ChatMessages = { }
local function printCentered(str,ypos)
term.setCursorPos(w/2-#str/2,ypos)
term.write(str)
end
local function printRight(str,ypos)
term.setCursorPos(w-#str,ypos)
term.write(str)
end
local function discover()
for i = 1,#sides do
if peripheral.isPresent(sides[i]) then
if peripheral.getType(sides[i]) == "modem" then
rednet.open(sides[i])
end
end
end
end
discover()
while true do
term.clear()
printCentered("-Welcome to "..Version.."-",1)
printCentered(string.rep("-",w),2)
local x = 1
local y = 3
term.setCursorPos(x,y)
for i = 1,#ChatMessages do
print(ChatMessages[i])
end
e = {os.pullEvent()}
if e[1] == "rednet_message" then
table.insert(ChatMessages,e[3])
end
end