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

[LUA][ERROR]Too Long without yielding[SOLVED]

Started by CreeperGoBoom, 30 November 2012 - 10:26 PM
CreeperGoBoom #1
Posted 30 November 2012 - 11:26 PM
Hey guys, im new here at this forum, first of all hi guys :D/>

now im having a small problem

i created a program called lockit which outputs redstone signal to a set of doors i have going in my mines

program worked fine up until i decided to mess around with a login/logout feature (just for fun)

probably a silly part of code, i have some experience with coding, probably looks like crap to you guys but im very tired at the moment so bear with me :D/>

heres the code

http://pastebin.com/UMTtKVy9
Getting the error: Too long without yielding, but the line number on the error is different each time

and yes i have searched the forums for a few hours now but none of the fixes apply to my scenario (maybe i missed one, i dunno)

Any help would be greatly appreciated
Luanub #2
Posted 30 November 2012 - 11:44 PM
The problem is you have the "if not Logged then" nested in the "if Logged then" so the script never runs it. Which means it just runs the clears and write without yielding.

IMO the best solution is the change the not Logged to an elseif and remove one end. The reason being is you're only checking the one thing Logged so its probably best to check it in one statement.

Spoiler

yes=true
no=false
lock="lock"
unlock="unlock"
pass="admin"
monstat=""
Currentstate=""
Logged = false

Lokit = function(bool,state,Cstate)
redstone.setOutput("back", bool)
redstone.setOutput("bottom", bool)
monstat = state
Currentstate = Cstate
end

Lokit(yes,"Locked","Locked")
mon = peripheral.wrap("right")

while true do
mon.clear()
mon.setCursorPos(1,1)
mon.write(monstat)
term.clear()
term.setCursorPos(1,1)
if Logged then
  print("Lockdown system activated!")
  print("status: "..Currentstate)
  input = read()
  if input == lock then
	Lokit(yes,"Locked","Locked")
	print("Area now on Lockdown!")
	sleep(1)
  elseif input == unlock then
	Lokit(no,"UNL","Unlocked")
	write("Area Unlocked, watch your back!")
	sleep(1)
  elseif input == "logout" then Logged=false
  end
elseif not Logged then
	print ("Please enter the master password!")
	input = read("*")
	if input == pass then Logged = true
	end
end
end
CreeperGoBoom #3
Posted 30 November 2012 - 11:55 PM
ill keep that one in mind, thanks :D/>