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

e-craft:60: attempt to index ? (a function value)

Started by SgtElis, 05 February 2013 - 06:27 AM
SgtElis #1
Posted 05 February 2013 - 07:27 AM
I have never got this error before! I tried to search around but never found anything that could fix my error…

Here is the code:

function screen()
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.red)
print("	 _________________________________________	 ")
print("	 | __________ |			 | __________ |	 ")
print("	 | __________ |			 | __________ |	 ")
print("	 |____________|_____________|____________|	 ")
print("	 |									   |	 ")
print("	 |									   |	 ")
print("	 |									   |	 ")
print("	 |									   |	 ")
print("	 |									   |	 ")
print("	 |									   |	 ")
print("	 |_______________________________________|	 ")
print("	 |_______________________________________|	 ")
print("	 |									   |	 ")
print("	 |									   |	 ")
print("	 |_______________________________________|	 ")
print("	 |									   |	 ")
print("	 |									   |	 ")
print("	 |_______________________________________|	 ")
end
function verision()
  term.setTextColor(colors.lime)
  term.setCursorPos(21,3)
  print("E-Craft 2.0")
end
function redstone()
  screen()
  term.setCursorPos(8,6)
  term.setTextColor(colors.orange)
  print("1 Right On | 4 Front On  | 7		  ")
  term.setCursorPos(8,7)
  print("----------   -----------   ---------- ")
  term.setCursorPos(8,8)
  print("2 Left On  | 5 Top On	| 8		  ")
  term.setCursorPos(8,9)
  print("----------   -----------   ---------- ")
  term.setCursorPos(8,10)
  print("3 Back On  | 6 Down On   | 9 Back	 ")

  term.setCursorPos(7,14)
  term.setTextColor(colors.cyan)
  print("Choose Side:")
  term.setCursorPos(20,14)
  term.setTextColor(colors.orange)
  local input = read()

  if input == "1" then
	term.setCursorPos(7,14)
	term.setTextColor(colors.cyan)
	print("Choose Time:  ")
	term.setCursorPos(20,14)
  
	local time = tonumber(read())
  
	redstone.setOutput("right",true) 
	sleep(time)
	redstone.setOutput("right",false)
  end
end
  
function mainPage()
  term.setCursorPos(8,6)
  term.setTextColor(colors.orange)
  print("1 Redstone | 4		   | 7		  ")
  term.setCursorPos(8,7)
  print("----------   -----------   ---------- ")
  term.setCursorPos(8,8)
  print("2 Redpower | 5		   | 8 Logout   ")
  term.setCursorPos(8,9)
  print("----------   -----------   ---------- ")
  term.setCursorPos(8,10)
  print("3 Rednet   | 6		   | 9 Shutdown ")
  term.setTextColor(colors.cyan)
  term.setCursorPos(7,14)
   print("Choose Program:")
  term.setCursorPos(23,14)
  term.setTextColor(colors.orange)
  local input = read()

  if input == "1" then
	term.setCursorPos(7,17)
	term.setTextColor(colors.cyan)
	 print("Redstone")
	sleep(1)
	term.setCursorPos(23,14)
	 print("			")
	term.setCursorPos(7,17)
	 print("			")
	redstone()

  elseif input == "2" then
	term.setCursorPos(7,17)
	term.setTextColor(colors.cyan)
	 print("Redpower")
	sleep(1)
	term.setCursorPos(23,14)
	 print("			")
	term.setCursorPos(7,17)
	 print("			")
	mainPage()

  elseif input == "3" then
	term.setCursorPos(7,17)
	term.setTextColor(colors.cyan)
	 print("Rednet")
	sleep(1)
	term.setCursorPos(23,14)
	 print("			")
	term.setCursorPos(7,17)
	 print("			")
	mainPage()
  
  elseif input == "8" then
	term.setCursorPos(7,17)
	term.setTextColor(colors.cyan)
	 print("Loging out")
	sleep(0.3)
	term.setCursorPos(17,17)
	 print(".")
	sleep(0.3)
	term.setCursorPos(18,17)
	 print(".")
	sleep(0.3)
	term.setCursorPos(19,17)
	 print(".")
	sleep(0.3)
	term.setCursorPos(7,14)
	 print("							 ")
	term.setCursorPos(7,17)
	 print("			 ")
	term.setCursorPos(8,6)
	 print("									  ")
	term.setCursorPos(8,7)
	 print("									  ")
	term.setCursorPos(8,8)
	 print("									  ")
	term.setCursorPos(8,9)
	 print("									  ")
	term.setCursorPos(8,10)
	 print("									  ")
	logIn()
  
  elseif input == "9" then
	term.setCursorPos(7,17)
	term.setTextColor(colors.cyan)
	 print("Shutting Down")
	sleep(0.3)
	term.setCursorPos(20,17)
	 print(".")
	term.setCursorPos(21,17)
	sleep(0.3)
	 print(".")
	term.setCursorPos(22,17)
	sleep(0.3)
	 print(".")
	sleep(0.3)
	os.shutdown()

  else
	term.setCursorPos(7,17)
	term.setTextColor(colors.cyan)
	 print("Not a Program")
	sleep(1)
	term.setCursorPos(23,14)
	 print("				  ")
	term.setCursorPos(7,17)
	 print("			 ")
	mainPage()
  end
end
function logIn()
  term.setCursorPos(7,14)
  term.setTextColor(colors.cyan)
  print("User:")
  term.setCursorPos(7,17)
  print("Pass:")
  term.setTextColor(colors.orange)
  term.setCursorPos(13,14)
  while true do
	local user = read()
	if user ~= "Elis" then
	  term.setCursorPos(13,14)
	  print("						 ")
	  logIn()
	end
  
	term.setCursorPos(13,17)
	local pass = read("*")
	if pass ~= "1234" then
	  term.setCursorPos(13,14)
	  print("						 ")
	  term.setCursorPos(13,17)
	  print("						 ")
	  logIn()
	else
	  term.setCursorPos(7,14)
	  print("							  ")
	  term.setCursorPos(7,17)
	  print("							  ")
	  mainPage()
	end
  end
end
screen()
verision()
logIn()

It's a very big program… :P/>

Hope someone can help me!

Tnx!

//Elis

EDIT: Sry for it taking up so much place! I dont know how to put it in a "window" :P/>
GopherAtl #2
Posted 05 February 2013 - 09:24 AM
you've overwritten the redstone api with your redstone function. So when you try to access the api, ex, redstone.setOutput(…), you are trying to index (get members of, using ".") a function (your function called redstone).

Rename the function something else.
SgtElis #3
Posted 05 February 2013 - 08:18 PM
Tnx! That fixed my problem! :D/> I had some problem getting it to work though but I fixed it! Tnx a lot! :D/>