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

attempt to call string >.<

Started by Cozzimoto, 19 June 2013 - 08:38 AM
Cozzimoto #1
Posted 19 June 2013 - 10:38 AM
ok i have tried several things in order to get this small program to work. basically this program is connected to other computers with gates on MFSUs and each line is a main and a back up battery, im trying to track the battery and display a certain status up on an advanced monitor. ive tried converting the booleans to strings, and doing a compare that way, ive also tried changing the color around. this is starting to give me a headache and i cannot see what i am doing wrong

the error it is throwing is on line 37 (alot of * to mark the line) and the computer is saying attempt to call string

this is the table the program receives to do the compares
ive hardcoded to convert to string and do compares, but i converted back to booleans to have the program do the compares that way, still having issues

package = {mvOneMain = {isEmpty = true, isFull = true, spaceForEnergy = true},
		   mvOneBack = {isEmpty = true, isFull = true, spaceForEnergy = true}}

this is the program

MODEM = peripheral.wrap("back")
M = peripheral.wrap("top")
MODEM.open(2424)
x,y = M.getSize()
tri = x/3
package = {}

function draw()
  M.clear()

  for i=1,3 do
	M.setCursorPos((tri*i)-9,1)
	  if i == 1 then
		M.write("- MV 1 -")
	  elseif i == 2 then
		M.write("- MV 2 -")
	  else
		M.write("- LV 1 -")
	  end
  
	M.setCursorPos((tri*i)-9,4)
	M.write("Main")
	M.setCursorPos((tri*i)-9,7)
	M.write("Backup")
  end
end

function e(X,Y,COLOR,TEXT)
  M.setCursorPos(X,Y)
  M.setBackgroundColor(COLOR)
  M.write(" "..TEXT.." ")
  M.setBackgroundColor(colors.black)
end

function checkStatus()
  if package.mvOneMain.isEmpty == true then
	e(4,5,colors.red,"Empty") **************************************************************************************
  elseif package.mvOneMain.spaceForEnergy == true then
	e(4,5,colors.orange,"Dischargin")
  elseif package.mvOneMain.isFull == true then
	e(4,5,colors.lime,"Full")
  else
	e(4,5,colors.grey,"NA")
  end
end

while true do  
  e,side,iC,rC,msg,dist = os.pullEvent("modem_message")
  package = textutils.unserialize(msg)
  print(type(package.mvOneMain.isEmpty))
  draw()
  checkStatus()
end
theoriginalbit #2
Posted 19 June 2013 - 10:44 AM
it is because in your while loop you override the `e` function with the event string. hence it telling you that you're attempting to call a string.

either rename the variable or localise the variable and pass the data around where appropriate.

future reference, any time it states "attempt to call <value>" then check and make sure you're not overriding functions with variables of the type the error states.
Cozzimoto #3
Posted 19 June 2013 - 07:46 PM
oh wow i see it now, im dumb, talk about no seeing anything when i named a variable and a function the same name. thanks man. its working now