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

"bios:338: [string "celldoor"]:40: 'end' expected (to close 'function' at line 39)"

Started by Middleman3, 22 May 2013 - 10:49 AM
Middleman3 #1
Posted 22 May 2013 - 12:49 PM
Im having an issue with my CellDoor function. it says at line 40, but its really just whenever I call a function.

bios:338: [string "celldoor"]:40: 'end' expected (to close 'function' at line 39)

The program is supposed to display a menu, with 3 choices, open, close and exit.
with Open, it'll ask for a number of cells to open, then ask for the colors of the redpower wires for the doors, then one by one (cuz I cant think of how to use a table/array along with the redstone.setBundledCables function) anyways, one by one, the doors will open in the order he entered the colors.

Close will simply close all the doors, and Exit will reboot the PC.

About the Error:
Basically, its asking me for an 'end' after every time I call a function. I assume it thinks that Im declaring the function right there, instead of calling it. It happens at every function I try to call.



function Open()
  print("How Many Doors?")
  doorNumber = read()
  print("Which Colors?")
  local i = 1
  repeat
	print(i,": ")
	colorset.i = read()
	i = i + 1
  until i == doorNumber

  print("Are you sure? (y/n)")
  sure = read()
  if sure == "n" then
	function Open()
  end
  if sure == "y" then

	for i = 1, doorNumber, 1 do
	  redstone.setBundledOutput("bottom", colorset.i)
	end

  else
	print("enter y or n")
	function Open()
  end
end

  function Menu()
  print("Menu")
  print("1. Open")
  print("2. Close")
  print("3. Exit")
  selection = read()

  if selection == 1 then
	function Open()
  else
	if selection == 2 then
	  redstone.setBundledOutputs("bottom", 0)
	else
		if selection == 3 then
		  shell.run("reboot")
		else
		  print("Enter 1-3 to make a selection.")
		
		  function Menu()
		end
	  end
	end
  end

function Menu()


P.S. I was wondering if there is some switch operator that I don't know about, because the extended if else junk is tedious.

Thanks all and I hope this post was beneficial to my fellow nuebs. :)/>/>
Lyqyd #2
Posted 22 May 2013 - 01:08 PM
Split into new topic.

Remove the word function from the last line. You surmise correctly that it is another declaration, not a call. You manage to call other functions correctly, so I'm baffled as to why you'd include the function keyword there.

Edit: remove it from everywhere else you call functions that you've declared too. You may also wish to invest in some loops rather than recursing to loop.
nateracecar5 #3
Posted 22 May 2013 - 09:34 PM
When you call a function like that, you need to do function() <functionName(strings)> end. You need to do that for peripherals (I had that problem). If you want to call a function, just type the function name and then the strings if there are one.
PixelToast #4
Posted 22 May 2013 - 09:38 PM
this:

while true do
  print("Menu")
  print("1. Open")
  print("2. Close")
  print("3. Exit")
  selection = read()
  shell.run("clear")
  if selection == 1 then
	open()
  elseif selection == 2 then
	redstone.setBundledOutputs("bottom", 0)
  elseif selection == 3 then
	shell.run("reboot")
  else
	print("Enter 1-3 to make a selection.")
  end
end
Edited on 22 May 2013 - 09:39 PM
Lyqyd #5
Posted 22 May 2013 - 09:55 PM
You missed the two instances of the problem in the function block, PixelToast.
PixelToast #6
Posted 22 May 2013 - 11:39 PM
fixed, also fixed the recursion, lack of elseif, etc