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

Spot the error

Started by Writer, 09 August 2014 - 12:36 AM
Writer #1
Posted 09 August 2014 - 02:36 AM
So, yesterday I decided to make a IRC type-a-thing, recieving/transmiting mensages, programs and text program. The layout for the idea is: at startup, make it appear a menu, with 3 options: start the IRC, start the normal CraftOS or shutdown the computer. Later on, I plan adding this menu onto an operating system. For the IRC, I'll have three different programs: the IRC itself, the commands and behind the sceens and the IRC menu. I started making the IRC menu. In here, you could access the principal programs like nickname, join channel and stuff like that, but only that. Otherwise, the program would be huge for that tiny litle computer screen.

In the IRC menu, I have a loop so it doesn't end (unless you shutdown or reboot the computer which, when implemented in the startup menu, will be kinda useless). However, after I putted the while loop, the menu when a bit fuddly: when I typed a command, even if correct, the program wouldn't respond. In other words, I putted the command, but nothing happened, so the screen sat still.

Here is the IRC code:

local version = "1.0"
local image = paintutils.loadImage("logo")
local command = ""

function mens(command, mensage)
  local length = (51-#command)/2
  local len = length + #command
  term.clear()
  term.setTextColor(colors.green)
  for i = 1, length do
    term.write("-")
    end
    term.write(command)
  for j = 1, len do
    term.write("-")
  end
  print (mensage)
  for k = 1, 51 do
    term.write("-")
  end
  term.setTextColor(colors.white)
end

while true do
  term.clear()
  term.setCursorPos(1, 19)
  paintutils.drawImage(image, 0 ,7)
  term.setCursorPos(1, 19)
  term.setBackgroundColor(colors.black)
  print[[
  IRC 1.0
  For more information, type '/info'
  To enter a chat, type '/enter (network)'
  To see the curent networks, type '/networks'
  For help, type '/help']]
  term.write 'Command '
  command = read()
  if command == "/help" then
    mens("Help", "/help \n/info \n/enter (network) \n/networks \n/list \n/quit \n/nick (nickname) \n/entry (enable|disable) \n/clear")
  elseif command == "/help help" then
    mens("Help", "/help - gives you all the existing codes")
  elseif command == "/help info" then
    mens("Info", "info - Shows you all the CC IRC's information")
  elseif command == "/help enter" then
    mens("Enter", "enter (network) - makes you enter in a existing and avaliable network")
  elseif command == "/help networks" then
    mens("Networks", "networks - returns all the existing networks")
  elseif command == "/help quit" then
    mens("Quit", "quit - makes you logout of the network")
  elseif command == "/help clear" then
    mens("Clear", "clear - clears the entire chat's text")
  elseif command == "/help list" then
    mens("List", "list - shows you the list of current IRC online users in the network")
  elseif command == "/help nick" then
    mens("Nickname", "nick (nickname) - changes your nickname")
  elseif command == "/help entry" then
    mens("Entry warmings", "entry (enable|disable) - enables or disables the IRC uses entry warmings")
  end
end

This is my first program in a long time, since I took a holiday break and started in making again a bit of Java programming.
Please, Pros, help me!
LeonTheMisfit #2
Posted 09 August 2014 - 03:46 AM
Your mens functions writes to the screen but then once it's complete your loop starts over and clears the screen right away. So it looks like nothing is happening because everything is happening so fast that you never see it. Try inserting a os.sleep(1) at the end of your mens function.
Writer #3
Posted 09 August 2014 - 09:42 AM
It worked perfectly! Thanks a lot! :D/>