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

[Error] attempt to call string

Started by Cranium, 25 August 2012 - 02:04 PM
Cranium #1
Posted 25 August 2012 - 04:04 PM
I am trying to add a monitor to my Master Control System, but when displaying statuses, it seems to give me an error when trying to call to those statuses. I have no idea why, because the item above the line receiving the error has the same code, but receives no error.
The error is monitor:124: attempt to call string

-----Monitor Program-----
--variables
local sSide = {
"left",
"right",
"top",
"bottom",
"back",
"front"
}
--peripherals
for i=1,6 do
if peripheral.isPresent(sSide[i]) then
if peripheral.getType(sSide[i]) == "monitor" then mon = peripheral.wrap(sSide[i])
elseif peripheral.getType(sSide[i]) == "disk" then disk = sSide
elseif peripheral.getType(sSide[i]) == "modem" then modem = sSide
end
else
end
end
local mX,mY = mon.getSize()
--functions
function time()
local t=os.time()
local time = textutils.formatTime(t,false)
return time
end
local function saveState(saveTable)
    local file = fs.open("status", "w")
    if file then
	    for eNum, eInfo in ipairs(saveTable) do
		    file.writeLine(eInfo.type..","..eInfo.color..","..eInfo.status)
	    end
	    file.close()
    end
end
local function loadState()
    local loadTable = {}
    local file = fs.open("status", "r")
    if file then
	    readLine = file.readLine()
	    while readLine do
		    local lineTable = {}
		    lineTable.type, lineTable.color, lineTable.status = string.match(readLine, "(%w+),(%w+),(%w+)")
		    if lineTable.type then
			    table.insert(loadTable, lineTable)
		    end
		    readLine = file.readLine()
	    end
	    file.close()
    end
    return loadTable
end
function state(status)
local controlTable = loadState()
if status=="true" then state="On"
elseif status=="false" then state="Off"
end
return state
end
--screen functions
function monTitle()
mon.clear()
mon.setCursorPos(1,1)
for i=1,mX do
mon.setCursorPos(i,1)
mon.write("-")
mon.setCursorPos(i,mY)
mon.write("-")
mon.setCursorPos(i,5)
mon.write("-")
end
for i=1,mY do
mon.setCursorPos(1,i)
mon.write("|")
mon.setCursorPos(mX,i)
mon.write("|")
end
for i=6,mY-1 do
mon.setCursorPos(25,i)
mon.write("|")
end
for i=26,mX do
mon.setCursorPos(i,16)
mon.write("-")
mon.setCursorPos(25,16)
mon.write("+")
mon.setCursorPos(mX,16)
mon.write("+")
end
mon.setCursorPos(1,1)
mon.write(".")
mon.setCursorPos(mX,1)
mon.write(".")
mon.setCursorPos(1,5)
mon.write("+")
mon.setCursorPos(mX,5)
mon.write("+")
mon.setCursorPos(1,mY)
mon.write("'")
mon.setCursorPos(mX,mY)
mon.write("'")
mon.setCursorPos(25,5)
mon.write("+")
mon.setCursorPos(25,mY)
mon.write("+")
local b = string.len("Master Control System Status")/2
local x = (mX/2)-b
mon.setCursorPos(x,3)
mon.write("Master Control System Status")
end
function screen()
local controlTable = loadState()
for eNum,dInfo in ipairs(controlTable) do
if dInfo.type~="Admin" and dInfo.type~="User" and dInfo.type~="Firstrun" then
  mon.setCursorPos(2,6)
  mon.write("Production Status")
  if dInfo.type=="Macerator" then
   mon.setCursorPos(5,8)
   mon.write("Macerator: ")
   mon.write(state(dInfo.status))
  elseif dInfo.type=="Furnace" then
   mon.setCursorPos(5,10)
   mon.write("Furnace: ")
   mon.write(state(dInfo.status))
  elseif dInfo.type=="Compressor" then
   mon.setCursorPos(5,12)
   mon.write("Compressor: ")
   mon.write(state(dInfo.status))
  elseif dInfo.type=="Extractor" then
   mon.setCursorPos(5,14)
   mon.write("Extractor: ")
   mon.write(state(dInfo.status))
  end
  mon.setCursorPos(27,6)
  mon.write("Power Status")
  if dInfo.type == "MFSU" or dInfo.type == "Batbox" or dInfo.type == "MFE"then
   mon.setCursorPos(30,8)
   mon.write(dInfo.type..": ")
   mon.write(dInfo.status)
  end
end
end
end
--code
monTitle()
screen()
This is the code so far, and this is the file table I'm referring to:

Admin,craniumkid22,XXXX
User,miveck,XXXX
Lights,1,false
Power,false,false
Reactor,16384,true
Coolant,2048,true
MFSU,256,None
Macerator,2,false
Furnace,16,false
Compressor,1024,false
Extractor,4096,false
Firstrun,completed,true
ardera #2
Posted 25 August 2012 - 04:19 PM
The only I can say is that attempt to call string means that you do something like this
hello="hi"
hello()
Cranium #3
Posted 25 August 2012 - 04:28 PM
Yep, that was it. After I called state(), I was changing what state() was by saying state="whatever". Fixed, no more errors. Such a silly mistake….