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

Multiple Points

Started by SGunner2014, 22 March 2015 - 10:52 PM
SGunner2014 #1
Posted 22 March 2015 - 11:52 PM
Hi there,

I'm trying to make this console program and it keeps erroring out with 'multiple points'. The latest thing I've added/changed was when I was trying to add i the ability to press the down and up buttons to go to the latest command. This is near the end of the code.

Code:
Spoiler

latestCommPoint = 0

listenSymbol = true

comTextCol = colors.white
comBgCol = colors.lightGray

term.setTextColor(comTextCol)
term.setBackgroundColor(comBgCol)
term.clear()

-- Variables --
commTable = {}

commands = {
  [ 'action' ] = function() print("hi") end,
  [ 'exit' ] = function() terminate = true end,
  [ 'access-list' ] = function(cmd)
    if cmd[1] ~= "deny" and cmd[1] ~= "off" and cmd[1] ~= "on" and cmd[1] ~= "showall" and cmd[1] ~= "show" and cmd[1] ~= "allow" then
      print("access-list <deny|allow|off|on|showall|show> <ip>")
    elseif cmd[1] == "deny" and cmd[2] ~= nil then
      
      file = fs.open("/database/access-list", "r")
      AL = textutils.unserialize(file.readAll())
      file.close()
      AL[cmd[2]] = {
        cmd[1],
      }
      printError(cmd[2] .. " > " .. cmd[1])
      file = fs.open("/database/access-list", "w")
      file.write(textutils.serialize(AL))
      file.close()
      
    elseif cmd[1] == "allow" and cmd[2] ~= nil then
      
      local file = fs.open("/database/access-list", "r")
      local AL = textutils.unserialize(file.readAll())
      file.close()
      AL[cmd[2]] = {
        cmd[1],
      }
      printError(cmd[2] .. " > " .. cmd[1])
      local file = fs.open("/database/access-list", "w")
      file.write(textutils.serialize(AL))
      file.close()
      
    elseif cmd[1] == "off" then
      
      
      
    elseif cmd[1] == "showall" then  
    
      local file = fs.open("/database/access-list", "r")
      local AL = textutils.unserialize(file.readAll())
      
      for k, v in pairs(AL) do
      
        printError(k .. " > " .. v[1])
      
      end
      
    
    elseif cmd[1] == "show" and cmd[2] ~= nil then
    
      local file = fs.open("/database/access-list", "r")
      local AL = textutils.unserialize(file.readAll())
      
      if AL[cmd[2]] ~= nil then
        printError(cmd[2] .. " > " .. AL[cmd[2]][1])
      else
        printError("IP does not exist in access-list")
      end
    else
      print("access-list " .. cmd[2] .. " <Invalid Usage>")
    end
  end,
}

-- access-list deny 1.1

-- Functions --
function arrowPress()

  endCond = nil

  repeat
    _, scancode = os.pullEvent('key')
    if scancode == 200 then
    
      endCond = true
      
    elseif scancode == 208 then
    
      endCond = true
      
    end
    
  until endCond == true

end

function comListen()
  if listenSymbol == true then
    term.setTextColor(colors.white)
    write('> ')
  else
    listenSymbol = true
  end
  
  curPosX, curPosY = term.getCursorPos()
  comm = read()
  
  if comm == nil and commTable[latestCommPoint] ~= nil then
    commTable[#commTable+1..'x'] = commTable[latestCommPoint..'x']
    --table.insert(commTable, commTable[latestCommPoint])
    comm = commTable[latestCommPoint..'x']
  else
    commTable[#commTable+1..'x'] = comm
    --table.insert(commTable, comm)
  end
end


function mainFunc(comm)

  local comTbl = {}
  
  for k in string.gmatch(comm, '[^ ]+') do
    table.insert(comTbl, k)
  end
  
  if commands[comTbl[1]] ~= nil then
    comTblPass = {}
    
    for i=2, #comTbl do
      table.insert(comTblPass, comTbl[i])
    end
    
    --print(comTbl[1])
    commands[comTbl[1]](comTblPass)
  else
    print('Command not found.')
  end

end

--  Startup  --
terminate = nil

function main()
repeat

  local pID = parallel.waitForAny(arrowPress, comListen)
  if pID == 1 then
    if scancode == 200 then
      if (commTable[latestCommPoint-1..'x'][1]) ~= nil then
        if latestCommPoint ~= 0
          paintutils.drawLine(2, curPosY, curPosX+#commTable[latestCommPoint..'x'][1], curPosY, colors.lightGray)
          term.setCursorPos(curPosX, curPosY)
          latestCommPoint = latestCommPoint-1
          write(commTable[latestCommPoint..'x'][1])
        end
        listenSymbol = false
      end
    elseif scancode == 208 then
      if (commTable[latestCommPoint+1..'x']) ~= nil then
        if latestCommPoint ~= 0 then
          paintutils.drawLine(2, curPosY, curPosX+#commTable[latestCommPoint..'x'][1], curPosY, colors.lightGray)
        end
        term.setCursorPos(curPosX, curPosY)
        latestCommPoint = latestCommPoint+1
        write(commTable[latestCommPoint..'x'][1])
        listenSymbol = false
      --else
      --paintutils.drawLine(2, curPosY, curPosX+#commTable[latestCommPoint], curPosY, colors.lightGray)
      end
    end
  elseif pID == 2 then
    mainFunc(comm)
  end

until terminate == true
end

local ok, err = pcall(main)
if not ok then
  local h = fs.open('latestError', 'w')
  h.writeLine(err)
  --h.write(textutils.serialize(commTable))
  h.writeLine(tostring(curPosX))
  h.writeLine(tostring(curPosY))
  h.writeLine(tostring(latestCommPoint))
  h.close()
end

Could someone find it in their hearts to help me?

Many thanks,
- Sam
Bomb Bloke #2
Posted 23 March 2015 - 12:01 AM
See here, then take a look for lines like these:

if (commTable[latestCommPoint+1..'x']) ~= nil then

Use extra brackets to divide up your terms.