Jump to content




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


  • You cannot reply to this topic
5 replies to this topic

#1 Middleman3

  • New Members
  • 1 posts

Posted 22 May 2013 - 11:49 AM

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. :)/>

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 22 May 2013 - 12: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.

#3 nateracecar5

  • Members
  • 94 posts

Posted 22 May 2013 - 08: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.

#4 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 22 May 2013 - 08: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 by PixelToast, 22 May 2013 - 10:39 PM.


#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 22 May 2013 - 08:55 PM

You missed the two instances of the problem in the function block, PixelToast.

#6 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 22 May 2013 - 10:39 PM

fixed, also fixed the recursion, lack of elseif, etc





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users