12 posts
Posted 08 August 2012 - 02:30 PM
I need to make so when you write a thing, the last thing you wrote goes 1 line up.
like this
Lysdal : hey
Lysdal : hello
Lysdal : hai
Message :
i will code the rednet part later myself
rednet.open("left")
term.clear()
name = os.getComputerLabel()
while true do
term.clearLine()
term.setCursorPos(1,17)
write("Message: ")
message = read()
term.setCursorPos(1,16)
print(name.." : "..message)
end
there isnt any errors i just want to get the chat history thing working
463 posts
Location
Germany
Posted 08 August 2012 - 02:43 PM
function:
function chatHistory(history)
for n=15, 1, -1 do
term.setCursorPos(1, n)
write(history[#history-(7.5-(n-7.5))])
end
end
didn't test it but I think it should work
PS.: You need a table where all names and messages should be stored. store it like:
history[#history+1]=name..": "..msg
this table has to be the first param of chatHistory
12 posts
Posted 08 August 2012 - 03:04 PM
rednet.open("left")
term.clear()
name = os.getComputerLabel()
function chatHistory(history)
for n=15, 1, -1 do
term.setCursorPos(1, n)
write(history[#history-(7.5-(n-7.5))])
end
end
while true do
term.clearLine()
term.setCursorPos(1,17)
write("Message: ")
message = read()
chatHistory(history[#history+1]=name..": "..msg)
end
gives me a
error
bios:206: [string "chat"]:17: ')' expected
3790 posts
Location
Lincoln, Nebraska
Posted 08 August 2012 - 03:54 PM
I believe on the second to last line, where it says chatHistory(history[#history+1]=name..": "..msg), it needs to be chatHistory(history[#history+1]=name..","..msg). instead of colon, a comma goes there.
864 posts
Location
Sometime.
Posted 08 August 2012 - 04:07 PM
Comma wouldn't work..
You're missing ')' because you didn't do
chatHistory(history[#history+1]=name..": "..msg))
1604 posts
Posted 08 August 2012 - 05:30 PM
I believe on the second to last line, where it says chatHistory(history[#history+1]=name..": "..msg), it needs to be chatHistory(history[#history+1]=name..","..msg). instead of colon, a comma goes there.
The colon is a string, so it could be anything.
Comma wouldn't work..
You're missing ')' because you didn't do
chatHistory(history[#history+1]=name..": "..msg))
And now you have an extra ).
The problem is that you have to create the table, then assign the values in a separate line, and then pass it as a parameter.
local history = {}
...
-- in some part of the code that receives messages:
history[#history + 1] = receivedMessage
-- or
table.insert(history, receivedMessage)
...
-- then to print it out:
chatHistory(history)
463 posts
Location
Germany
Posted 08 August 2012 - 06:16 PM
Hey did an error in my function!
Change 7,5 to 7 like so:
function chatHistory(history)
for n=15, 1, -1 do
term.setCursorPos(1, n)
write(history[#history-(7-(n-7))])
end
end
because with 7,5 it will set the cursor position to 0 sometimes
1604 posts
Posted 08 August 2012 - 06:19 PM
Hey did an error in my function!
Change 7,5 to 7 like so:
function chatHistory(history)
for n=15, 1, -1 do
term.setCursorPos(1, n)
write(history[#history-(7-(n-7))])
end
end
because with 7,5 it will set the cursor position to 0 sometimes
It can be:
write(history[#history - (14 - n)])