Jump to content




Function Help!


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

#1 qwerty6543

  • Members
  • 8 posts

Posted 28 August 2013 - 05:03 PM

I am trying to make a piston airlock and I was wondering how to make it so at a certant point it will go back to a place in the command, Here is my script:

redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
print ""
write ">"
input = read()
if input == "open" then
   print "Opening..."
   redstone.setOutput("right", false)
   A()
else
   print "Command not recognised."
   A()
end
if input == "close" then
   print "Closing..."
   redstone.setOutput("right", true)
   A()
else
   print "Command not recognised."
   A()
end
end


When I try to run it it just says the first line and then goes to the normal console. I know it's bad to call a function in a function but I don't know what else to do!

#2 GopherAtl

  • Members
  • 888 posts

Posted 28 August 2013 - 05:17 PM

Put it in a while loop to make it repeat, instead of calling itself.

Also, use elseif, not else. As written it would be showing "command not recognized" twice if you weren't calling A again the first time, you should only have one final "else" at the end.

redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
  while true do
    print ""
    write ">"
    input = read()
    if input == "open" then
      print "Opening..."
      redstone.setOutput("right", false)
    elseif input == "close" then
      print "Closing..."
      redstone.setOutput("right", true)
    else
      print "Command not recognised."
    end
  end
end


#3 qwerty6543

  • Members
  • 8 posts

Posted 28 August 2013 - 05:34 PM

View PostGopherAtl, on 28 August 2013 - 05:17 PM, said:

Put it in a while loop to make it repeat, instead of calling itself.

Also, use elseif, not else. As written it would be showing "command not recognized" twice if you weren't calling A again the first time, you should only have one final "else" at the end.

redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
  while true do
	print ""
	write ">"
	input = read()
	if input == "open" then
	  print "Opening..."
	  redstone.setOutput("right", false)
	elseif input == "close" then
	  print "Closing..."
	  redstone.setOutput("right", true)
	else
	  print "Command not recognised."
	end
  end
end

I typed that in exactly and when i try to run it it gives me a 204 error.

#4 qwerty6543

  • Members
  • 8 posts

Posted 28 August 2013 - 05:43 PM

View Postqwerty6543, on 28 August 2013 - 05:34 PM, said:

View PostGopherAtl, on 28 August 2013 - 05:17 PM, said:

Put it in a while loop to make it repeat, instead of calling itself.

Also, use elseif, not else. As written it would be showing "command not recognized" twice if you weren't calling A again the first time, you should only have one final "else" at the end.

redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
  while true do
	print ""
	write ">"
	input = read()
	if input == "open" then
	  print "Opening..."
	  redstone.setOutput("right", false)
	elseif input == "close" then
	  print "Closing..."
	  redstone.setOutput("right", true)
	else
	  print "Command not recognised."
	end
  end
end

I typed that in exactly and when i try to run it it gives me a 204 error.

Never mind I figured it out

#5 Last1Here

  • Members
  • 32 posts
  • LocationUK

Posted 28 August 2013 - 05:44 PM

View Postqwerty6543, on 28 August 2013 - 05:34 PM, said:

View PostGopherAtl, on 28 August 2013 - 05:17 PM, said:

Put it in a while loop to make it repeat, instead of calling itself.

Also, use elseif, not else. As written it would be showing "command not recognized" twice if you weren't calling A again the first time, you should only have one final "else" at the end.

redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
  while true do
	print ""
	write ">"
	input = read()
	if input == "open" then
	  print "Opening..."
	  redstone.setOutput("right", false)
	elseif input == "close" then
	  print "Closing..."
	  redstone.setOutput("right", true)
	else
	  print "Command not recognised."
	end
  end
end

I typed that in exactly and when i try to run it it gives me a 204 error.

works fine for me, make sure you call the function with A() at the end

#6 GopherAtl

  • Members
  • 888 posts

Posted 28 August 2013 - 06:13 PM

FYI, the number before the : in Lua error messages is the line number where the error occurs, not a code identifying the type of error.

#7 reububble

  • Members
  • 72 posts
  • LocationBehind you

Posted 29 August 2013 - 12:34 AM

It looks like you aren't calling the function after you make it.
Use A() after you define it to actually call the function

To make Last1Here's comment more distinguished, I left out the giant quote, but basically I'm repeating what they said.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users