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

HELP! - Program not working

Started by bwbwbwboo111, 30 January 2015 - 05:46 PM
bwbwbwboo111 #1
Posted 30 January 2015 - 06:46 PM
monitor = peripheral.wrap("top")
rs.setOutput("back", false)
rs.setOutput("left", true)
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.blue)
monitor.write"Lights: "
monitor.setTextColor(colors.red)
monitor.write "Off"
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.blue)
monitor.write"Lockdown: "
monitor.setTextColor(colors.red)
monitor.write"Off"
while true do
term.clear()
term.setCursorPos(1,1)
print"Welcome Warlock, what may I do for you?"
input = read()
if input == "lights on" then
print"Turning lights on now…"
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.blue)
monitor.write "Lights: "
monitor.setTextColor(colors.green)
monitor.write"On"
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.blue)
monitor.write"Lockdown: "
monitor.setTextColor(colors.red)
monitor.write"Off"
rs.setOutput("back", true)
sleep(3)
elseif input == "lights off" then
print "Turning lights off now…"
rs.setOutput("back", false)
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.blue)
monitor.write"Lights: "
monitor.setTextColor(colors.red)
monitor.write"Off"
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.blue)
monitor.write"Lockdown: "
monitor.setTextColor(colors.red)
monitor.write"Off"
sleep(3)
elseif input == "lockdown" then
while true do
term.clear()
term.setCursorPos(1,1)
rs.setOutput("left", false)
rs.setOutput("back", false)
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.red)
monitor.write"Lights: "
monitor.setTextColor(colors.red)
monitor.write"Off"
monitor.setTextColor(colors.blue)
monitor.setCursorPos(1,2)
monitor.write"Lockdown: "
monitor.setTextColor(colors.green)
monitor.write"On"
print "LOCKDOWN ACTIVATED, ALL DOORS AND LIGHTS SHUT OFF, ENTER PASSWORD TO DEACTIVATE:"
lockdown = read()
if lockdown == "stop" then
print "Lockdown deactivated, all systems returning to normal."
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.blue)
monitor.write"Lights: "
monitor.setTextColor(colors.green)
monitor.write"On"
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.blue)
monitor.write"Lockdown: "
monitor.setTextColor(colors.red)
monitor.write "Off"
rs.setOutput("back", true)
rs.setOutput("left", true)
sleep(3)
break
else
print "Wrong, lockdown continued."
sleep(1)
elseif input == "disable power" then
modem.transmit(0,0,"Disable")
while true do
print "Power Disabled, shall I activate the backup generator?"
power = read()
if power == "yes" then
modem.transmit(0,0,"Backup")
print "Backup Generator activated"
sleep(3)
break
elseif power == "no" then
print "Generator Ignored"
sleep(3)
elseif input == "enable power" then
while true do
print "Enabling the power will deactivate the backup generator, are you sure?"
backup = read()
if backup == "yes" then
print "Power re-enabled"
modem.transmit(0,0, "Enable")
sleep(3)
break
elseif backup == "no" then
print "Power still disabled"
sleep(2)
end
end
end
end
end
end



This is a program which controls the main computer of my base, and everytime I try and load it, it gives the error:

bios:366: [string"startup"]:89: 'end' expected (to close if at line 69)

I don't know what's happening, if someone could reply saying what's wrong with it and what I need to change, that would be great.

From lines 1-89 it worked fine, then I added in the power command and it all went balls up. I really need this fixed, as i cannot run the house without it.

-Bw
Dragon53535 #2
Posted 30 January 2015 - 07:32 PM
A couple of tips. When posting code, use the code tags.

Now for your error. It's easy to notice if you indent correctly.


monitor = peripheral.wrap("top")
rs.setOutput("back", false)
rs.setOutput("left", true)
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.blue)
monitor.write"Lights: "
monitor.setTextColor(colors.red)
monitor.write "Off"
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.blue)
monitor.write"Lockdown: "
monitor.setTextColor(colors.red)
monitor.write"Off"
while true do
  term.clear()
  term.setCursorPos(1,1)
  print"Welcome Warlock, what may I do for you?"
  input = read()
  if input == "lights on" then
	print"Turning lights on now..."
	monitor.clear()
	monitor.setCursorPos(1,1)
	monitor.setTextColor(colors.blue)
	monitor.write "Lights: "
	monitor.setTextColor(colors.green)
	monitor.write"On"
	monitor.setCursorPos(1,2)
	monitor.setTextColor(colors.blue)
	monitor.write"Lockdown: "
	monitor.setTextColor(colors.red)
	monitor.write"Off"
	rs.setOutput("back", true)
	sleep(3)
  elseif input == "lights off" then
	print "Turning lights off now..."
	rs.setOutput("back", false)
	monitor.clear()
	monitor.setCursorPos(1,1)
	monitor.setTextColor(colors.blue)
	monitor.write"Lights: "
	monitor.setTextColor(colors.red)
	monitor.write"Off"
	monitor.setCursorPos(1,2)
	monitor.setTextColor(colors.blue)
	monitor.write"Lockdown: "
	monitor.setTextColor(colors.red)
	monitor.write"Off"
	sleep(3)
  elseif input == "lockdown" then
	while true do
	term.clear()
	term.setCursorPos(1,1)
	rs.setOutput("left", false)
	rs.setOutput("back", false)
	monitor.clear()
	monitor.setCursorPos(1,1)
	monitor.setTextColor(colors.red)
	monitor.write"Lights: "
	monitor.setTextColor(colors.red)
	monitor.write"Off"
	monitor.setTextColor(colors.blue)
	monitor.setCursorPos(1,2)
	monitor.write"Lockdown: "
	monitor.setTextColor(colors.green)
	monitor.write"On"
	print "LOCKDOWN ACTIVATED, ALL DOORS AND LIGHTS SHUT OFF, ENTER PASSWORD TO DEACTIVATE:"
	lockdown = read()
	if lockdown == "stop" then
	  print "Lockdown deactivated, all systems returning to normal."
	  monitor.clear()
	  monitor.setCursorPos(1,1)
	  monitor.setTextColor(colors.blue)
	  monitor.write"Lights: "
	  monitor.setTextColor(colors.green)
	  monitor.write"On"
	  monitor.setCursorPos(1,2)
	  monitor.setTextColor(colors.blue)
	  monitor.write"Lockdown: "
	  monitor.setTextColor(colors.red)
	  monitor.write "Off"
	  rs.setOutput("back", true)
	  rs.setOutput("left", true)
	  sleep(3)
	  break
	else
	  print "Wrong, lockdown continued."
	  sleep(1)
	--You need an end here..., well actually two ends. One for the if statement, and one for the while true do
  elseif input == "disable power" then
	modem.transmit(0,0,"Disable")
	while true do
	  print "Power Disabled, shall I activate the backup generator?"
	  power = read()
	  if power == "yes" then
		modem.transmit(0,0,"Backup")
		print "Backup Generator activated"
		sleep(3)
		break
	  elseif power == "no" then
		print "Generator Ignored"
		sleep(3)
	  --Two ends needed here as well.
  elseif input == "enable power" then
	while true do
	  print "Enabling the power will deactivate the backup generator, are you sure?"
	  backup = read()
	  if backup == "yes" then
		print "Power re-enabled"
		modem.transmit(0,0, "Enable")
		sleep(3)
		break
	  elseif backup == "no" then
		print "Power still disabled"
		sleep(2)
	  end
	end
  end
end --Notice how these are all 3 on the same area? Delete the bottom two. You have too many ends here.
end
end
Edited on 30 January 2015 - 06:33 PM
bwbwbwboo111 #3
Posted 30 January 2015 - 07:56 PM
Thanks so much dude, works without errors now, just need to put the computer at the other end of modem with the program then I think I'm good, jic, u got any improvements I could make or it all good?
bwbwbwboo111 #4
Posted 30 January 2015 - 09:10 PM
Ok, I have now replaced the monitor text commands for variables (they are at the top of the code) and every time I run it, I am getting the error:

bios:366: [string "startup"]:77: '=' expected

Here is the code:
Spoiler

monitor = peripheral.wrap("top")
clear = monitor.clear()
lights = monitor.setCursorPos(1,1)
lockdown = monitor.setCursorPos(1,2)
power = monitor.setCursorPos(1,3)
gen = monitor.setCursorPos(1,4)
red = monitor.setTextColor(colors.red)
green = monitor.setTextColor(colors.green)
blue = monitor.setTextColor(colors.blue)
rs.setOutput("back", false)
rs.setOutput("left", true)
modem.transmit(0,0,"Enable")
clear
lights
blue
monitor.write"Lights: "
red
monitor.write "On"
lockdown
blue
monitor.write"Lockdown: "
red
monitor.write"Off"
power
blue
monitor.write"Power: "
green
monitor.write"Enabled"
gen
blue
monitor.write"Generator: "
red
monitor.write"Deactivated"
while true do
  term.clear()
  term.setCursorPos(1,1)
  print"Welcome Warlock, what may I do for you?"
  input = read()
  if input == "lights on" then
		print"Turning lights on now..."
		clear
		lights
		blue
		monitor.write"Lights: "
		red
		monitor.write "On"
		lockdown
		blue
		monitor.write"Lockdown: "
		red
		monitor.write"Off"
		power
		blue
		monitor.write"Power: "
		green
		monitor.write"Enabled"
		gen
		blue
		monitor.write"Generator: "
		red
		monitor.write"Deactivated"
		rs.setOutput("back", true)
		sleep(3)
  elseif input == "lights off" then
		print "Turning lights off now..."
		rs.setOutput("back", false)
		clear
		lights
		blue
		monitor.write"Lights: "
		red
		monitor.write "Off"
		lockdown
		blue
		monitor.write"Lockdown: "
		red
		monitor.write"Off"
		power
		blue
		monitor.write"Power: "
		green
		monitor.write"Enabled"
		gen
		blue
		monitor.write"Generator: "
		red
		monitor.write"Deactivated"
		sleep(3)
  elseif input == "lockdown" then
		while true do
		clear
		lights
		red
		monitor.write"Lights: Off"
		lockdown
		blue
		monitor.write"Lockdown: "
		green
		monitor.write"On"
		power
		red
		monitor.write"Power: Disabled"
		gen
		red
		monitor.write"Generator: Deactivated"
		print "LOCKDOWN ACTIVATED, ALL DOORS AND LIGHTS SHUT OFF, ENTER PASSWORD TO DEACTIVATE:"
		lockdown = read()
		if lockdown == "stop" then
		  print "Lockdown deactivated, all systems returning to normal."
		  monitor.clear()
		clear
		lights
		blue
		monitor.write"Lights: "
		red
		monitor.write "On"
		lockdown
		blue
		monitor.write"Lockdown: "
		red
		monitor.write"Off"
		power
		blue
		monitor.write"Power: "
		green
		monitor.write"Enabled"
		gen
		blue
		monitor.write"Generator: "
		red
		monitor.write"Deactivated"
		  sleep(3)
		  break
		else
		  print "Wrong, lockdown continued."
		  sleep(1)
  elseif input == "disable power" then
		modem.transmit(0,0,"Disable")
		clear
		lights
		blue
		monitor.write"Lights: "
		red
		monitor.write "On"
		lockdown
		blue
		monitor.write"Lockdown: "
		red
		monitor.write"Off"
		power
		blue
		monitor.write"Power: "
		red
		monitor.write"Disabled"
		gen
		blue
		monitor.write"Generator: "
		red
		monitor.write"Deactivated"
		while true do
		  print "Power Disabled, shall I activate the backup generator?"
		  power = read()
		  if power == "yes" then
				modem.transmit(0,0,"Backup")
				clear
				lights
				blue
				monitor.write"Lights: "
				red
				monitor.write "On"
				lockdown
				blue
				monitor.write"Lockdown: "
				red
				monitor.write"Off"
				power
				blue
				monitor.write"Power: "
				red
				monitor.write"Disabled"
				gen
				blue
				monitor.write"Generator: "
				green
				monitor.write"Activated"
				print "Backup Generator activated"
				sleep(3)
				break
		  elseif power == "no" then
				print "Generator Ignored"
				sleep(3)
				clear
				lights
				blue
				monitor.write"Lights: "
				red
				monitor.write "Off"
				lockdown
				blue
				monitor.write"Lockdown: "
				red
				monitor.write"Off"
				power
				blue
				monitor.write"Power: "
				green
				monitor.write"Enabled"
				gen
				blue
				monitor.write"Generator: "
				red
				monitor.write"Deactivated"
  elseif input == "enable power" then
		while true do
		  print "Enabling the power will deactivate the backup generator, are you sure?"
		  backup = read()
		  if backup == "yes" then
				print "Power re-enabled"
				modem.transmit(0,0, "Enable")
				clear
				lights
				blue
				monitor.write"Lights: "
				green
				monitor.write "On"
				lockdown
				blue
				monitor.write"Lockdown: "
				red
				monitor.write"Off"
				power
				blue
				monitor.write"Power: "
				green
				monitor.write"Enabled"
				gen
				blue
				monitor.write"Generator: "
				red
				monitor.write"Deactivated"
				sleep(3)
				break
		  elseif backup == "no" then
				print "Power still disabled"
				sleep(2)
		  end
		end
  end
end


There- if you find any mistakes, feel free to correct them, but the priority for me is the error :)/>
Edited on 30 January 2015 - 08:13 PM
Cranium #5
Posted 30 January 2015 - 09:13 PM
For future reference, it's easier if you put your code in
 tags, and long chunks of text in [spoiler] tags.
TurtleHunter #6
Posted 30 January 2015 - 09:24 PM
Ok, I have now replaced the monitor text commands for variables (they are at the top of the code) and every time I run it, I am getting the error:

bios:366: [string "startup"]:77: '=' expected

Here is the code:
Spoiler

monitor = peripheral.wrap("top")
clear = monitor.clear()
lights = monitor.setCursorPos(1,1)
lockdown = monitor.setCursorPos(1,2)
power = monitor.setCursorPos(1,3)
gen = monitor.setCursorPos(1,4)
red = monitor.setTextColor(colors.red)
green = monitor.setTextColor(colors.green)
blue = monitor.setTextColor(colors.blue)
rs.setOutput("back", false)
rs.setOutput("left", true)
modem.transmit(0,0,"Enable")
clear
lights
blue
monitor.write"Lights: "
red
monitor.write "On"
lockdown
blue
monitor.write"Lockdown: "
red
monitor.write"Off"
power
blue
monitor.write"Power: "
green
monitor.write"Enabled"
gen
blue
monitor.write"Generator: "
red
monitor.write"Deactivated"
while true do
  term.clear()
  term.setCursorPos(1,1)
  print"Welcome Warlock, what may I do for you?"
  input = read()
  if input == "lights on" then
		print"Turning lights on now..."
		clear
		lights
		blue
		monitor.write"Lights: "
		red
		monitor.write "On"
		lockdown
		blue
		monitor.write"Lockdown: "
		red
		monitor.write"Off"
		power
		blue
		monitor.write"Power: "
		green
		monitor.write"Enabled"
		gen
		blue
		monitor.write"Generator: "
		red
		monitor.write"Deactivated"
		rs.setOutput("back", true)
		sleep(3)
  elseif input == "lights off" then
		print "Turning lights off now..."
		rs.setOutput("back", false)
		clear
		lights
		blue
		monitor.write"Lights: "
		red
		monitor.write "Off"
		lockdown
		blue
		monitor.write"Lockdown: "
		red
		monitor.write"Off"
		power
		blue
		monitor.write"Power: "
		green
		monitor.write"Enabled"
		gen
		blue
		monitor.write"Generator: "
		red
		monitor.write"Deactivated"
		sleep(3)
  elseif input == "lockdown" then
		while true do
		clear
		lights
		red
		monitor.write"Lights: Off"
		lockdown
		blue
		monitor.write"Lockdown: "
		green
		monitor.write"On"
		power
		red
		monitor.write"Power: Disabled"
		gen
		red
		monitor.write"Generator: Deactivated"
		print "LOCKDOWN ACTIVATED, ALL DOORS AND LIGHTS SHUT OFF, ENTER PASSWORD TO DEACTIVATE:"
		lockdown = read()
		if lockdown == "stop" then
		  print "Lockdown deactivated, all systems returning to normal."
		  monitor.clear()
		clear
		lights
		blue
		monitor.write"Lights: "
		red
		monitor.write "On"
		lockdown
		blue
		monitor.write"Lockdown: "
		red
		monitor.write"Off"
		power
		blue
		monitor.write"Power: "
		green
		monitor.write"Enabled"
		gen
		blue
		monitor.write"Generator: "
		red
		monitor.write"Deactivated"
		  sleep(3)
		  break
		else
		  print "Wrong, lockdown continued."
		  sleep(1)
  elseif input == "disable power" then
		modem.transmit(0,0,"Disable")
		clear
		lights
		blue
		monitor.write"Lights: "
		red
		monitor.write "On"
		lockdown
		blue
		monitor.write"Lockdown: "
		red
		monitor.write"Off"
		power
		blue
		monitor.write"Power: "
		red
		monitor.write"Disabled"
		gen
		blue
		monitor.write"Generator: "
		red
		monitor.write"Deactivated"
		while true do
		  print "Power Disabled, shall I activate the backup generator?"
		  power = read()
		  if power == "yes" then
				modem.transmit(0,0,"Backup")
				clear
				lights
				blue
				monitor.write"Lights: "
				red
				monitor.write "On"
				lockdown
				blue
				monitor.write"Lockdown: "
				red
				monitor.write"Off"
				power
				blue
				monitor.write"Power: "
				red
				monitor.write"Disabled"
				gen
				blue
				monitor.write"Generator: "
				green
				monitor.write"Activated"
				print "Backup Generator activated"
				sleep(3)
				break
		  elseif power == "no" then
				print "Generator Ignored"
				sleep(3)
				clear
				lights
				blue
				monitor.write"Lights: "
				red
				monitor.write "Off"
				lockdown
				blue
				monitor.write"Lockdown: "
				red
				monitor.write"Off"
				power
				blue
				monitor.write"Power: "
				green
				monitor.write"Enabled"
				gen
				blue
				monitor.write"Generator: "
				red
				monitor.write"Deactivated"
  elseif input == "enable power" then
		while true do
		  print "Enabling the power will deactivate the backup generator, are you sure?"
		  backup = read()
		  if backup == "yes" then
				print "Power re-enabled"
				modem.transmit(0,0, "Enable")
				clear
				lights
				blue
				monitor.write"Lights: "
				green
				monitor.write "On"
				lockdown
				blue
				monitor.write"Lockdown: "
				red
				monitor.write"Off"
				power
				blue
				monitor.write"Power: "
				green
				monitor.write"Enabled"
				gen
				blue
				monitor.write"Generator: "
				red
				monitor.write"Deactivated"
				sleep(3)
				break
		  elseif backup == "no" then
				print "Power still disabled"
				sleep(2)
		  end
		end
  end
end


There- if you find any mistakes, feel free to correct them, but the priority for me is the error :)/>

All of your variables that represent functions, when called should be variable(). ex: power() instead of power clear() instead of clear etc
HPWebcamAble #7
Posted 31 January 2015 - 12:19 AM
To elaborate on what Turtle said:


test = print("hi")
test
DOESN'T make 'test' run 'print("hi")'. 'test' will be the value the 'print("hi")' returns.
(It should be 1 but that isn't important)
Instead, it will say "'=' expected", because the computer has no idea what to do with 'test' on its own.

What you need to do is like this:

test = print

Then you can do

test("hi")

That's because 'print' is a variable. The type of variable is a function, so using () will execute the function.
When you use 'test=print', you literally assign the value of 'print' to 'test', so now doing 'test()' will be the same as 'print()', since you made them the same.

You can also use this:

function lights() monitor.setCursorPos(1,1) end

Then you could use 'lights()' instead of 'monitor.setCursorPos(1,1)'.
Its the same thing, but just quicker to type.

Basically, you make a new function, and that function calls the function 'monitor.setCursorPos(1,1)'
(You can do it on one line, or three. Its the same thing in Lua)

Remember, lights(3,3) will still run 'monitor.setCursorPos(1,1)'. Even though you are giving it the values 3 and 3, you never told it to do anything with arguments.

For that to work, you need

function lights(x,y) monitor.setCursorPos(x,y) end

--# OR

lights = monitor.setCursorPos

Sorry for long answer hopefully this helps :)/>
Edited on 30 January 2015 - 11:20 PM
bwbwbwboo111 #8
Posted 31 January 2015 - 08:09 AM
Ok, I've done what you said, now I'm getting this:

bios:366: [string "startup"]:7: ')' expected

Here's the code:




monitor = peripheral.wrap("top")
b = (colors.blue)
g = (colors.green)
r = (colors.red)
c = monitor.setTextColor
m = monitor.setCursorPos
z = (1,1)
y = (1,2)
x = (1,3)
v = (1,4)
clear = monitor.clear
rs.setOutput("back", false)
rs.setOutput("left", true)
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.blue)
monitor.write"Lights: "
monitor.setTextColor(colors.red)
monitor.write "Off"
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.blue)
monitor.write"Lockdown: "
monitor.setTextColor(colors.red)
monitor.write"Off"
mx
cb
monitor.write"Power: "
cg
monitor.write"Enabled"
mv
cb
monitor.write"Generator: "
cr
monitor.write"Deactivated"
while true do
term.clear()
term.setCursorPos(1,1)
print"Welcome Warlock, what may I do for you?"
input = read()
if input == "lights on" then
print"Turning lights on now..."
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.blue)
monitor.write "Lights: "
monitor.setTextColor(colors.green)
monitor.write"On"
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.blue)
monitor.write"Lockdown: "
monitor.setTextColor(colors.red)
monitor.write"Off"
mx
cb
monitor.write"Power: "
cg
monitor.write"Enabled"
mv
cb
monitor.write"Generator: "
cr
monitor.write"Deactivated"
rs.setOutput("back", true)
sleep(3)
elseif input == "lights off" then
print "Turning lights off now..."
rs.setOutput("back", false)
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.blue)
monitor.write"Lights: "
monitor.setTextColor(colors.red)
monitor.write"Off"
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.blue)
monitor.write"Lockdown: "
monitor.setTextColor(colors.red)
monitor.write"Off"
mx
cb
monitor.write"Power: "
cg
monitor.write"Enabled"
mv
cb
monitor.write"Generator: "
cr
monitor.write"Deactivated"
sleep(3)
elseif input == "lockdown" then
while true do
term.clear()
term.setCursorPos(1,1)
rs.setOutput("left", false)
rs.setOutput("back", false)
modem.transmit(0,0,"Disable")
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.red)
monitor.write"Lights: "
monitor.setTextColor(colors.red)
monitor.write"Off"
monitor.setTextColor(colors.blue)
monitor.setCursorPos(1,2)
monitor.write"Lockdown: "
monitor.setTextColor(colors.green)
monitor.write"On"
mx
cr
monitor.write"Power: Off"
mv
cr
monitor.write"Generator: Off"
print "LOCKDOWN ACTIVATED, ALL DOORS AND LIGHTS SHUT OFF, ENTER PASSWORD TO DEACTIVATE:"
lockdown = read()
if lockdown == "stop" then
print "Lockdown deactivated, all systems returning to normal."
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.blue)
monitor.write"Lights: "
monitor.setTextColor(colors.green)
monitor.write"On"
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.blue)
monitor.write"Lockdown: "
monitor.setTextColor(colors.red)
monitor.write "Off"
mx
cb
monitor.write"Power: "
cg
monitor.write"On"
mv
cb
monitor.write"Generator: "
cr
monitor.write"Off"
rs.setOutput("back", true)
rs.setOutput("left", true)
modem.transmit(0,0,"Enable")
sleep(3)
break
else
print "Wrong, lockdown continued."
sleep(1)
end
end
elseif input == "disable power" then
modem.transmit(0,0,"Disable")
clear
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.blue)
monitor.write"Lights: "
monitor.setTextColor(colors.green)
monitor.write"On"
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.blue)
monitor.write"Lockdown: "
monitor.setTextColor(colors.red)
monitor.write"Off"
monitor.setCursorPos(1,3)
monitor.setTextColor(colors.blue)
monitor.write"Power: "
monitor.setTextColor(colors.red)
monitor.write"Disabled"
mv
cb
monitor.write"Generator: "
cr
monitor.write"Off"
while true do
print "Power Disabled, shall I activate the backup generator?"
power = read()
if power == "yes" then
modem.transmit(0,0,"Backup")
print "Backup Generator activated"
clear()
mz
cb
monitor.write"Lights: "
cg
monitor.write"On"
my
cb
monitor.write"Lockdown: "
cr
monitor.write"Off"
mx
cb
monitor.write"Power: "
cr
monitor.write"Disabled"
mv
cb
monitor.write"Generator: "
cg
monitor.write"On"
sleep(3)
break
elseif power == "no" then
print "Generator Ignored"
sleep(3)
end
end
elseif input == "enable power" then
while true do
print "Enabling the power will deactivate the backup generator, are you sure?"
backup = read()
if backup == "yes" then
print "Power re-enabled"
modem.transmit(0,0, "Enable")
mz
cb
monitor.write"Lights: "
cg
monitor.write"On"
my
cb
monitor.write"Lockdown: "
cr
monitor.write"Off"
mx
cb
monitor.write"Power: "
cg
monitor.write"Enabled"
mv
cb
monitor.write"Generator: "
cr
monitor.write"Deactivated"
sleep(3)
break
elseif backup == "no" then
print "Power still disabled"
sleep(2)
end
end
end
end

Thanks for the help so far!
Bomb Bloke #9
Posted 31 January 2015 - 09:53 AM
It's complaining about your use of a comma here:

z = (1,1)

You can't set a variable to (1,1). You'll also find that you can't "combine" variables as you've attempted to do with mx, cb, cg and so on. You could do this, though:

c = monitor.setTextColor
g = colors.green

m = monitor.setCursorPos
z = {1,1}     -- Stick the values in a table.

c(g)          -- Call c with the value in g.
m(unpack(z))  -- Call m with the unpacked values in table z.

The downside with this sort of thing is that it makes your script pretty much unreadable. Have a think about defining your own functions instead - for example, one that you can pass a string to, which'll get the monitor's current cursor position, write the string to it, then automatically move the cursor down a line from where it started.
bwbwbwboo111 #10
Posted 31 January 2015 - 12:35 PM
Right, last one, whenever I transmit a signal to disable/enable power, this happens:

startup:13: Too long without yielding

Help! Here's the code for the receiving computer, I don't think it's anything to do with the sending code.


modem = peripheral.wrap("top")
modem.open(0)
event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
while true do
  if (message) == "Enable" then
   rs.setOutput("left", true)
   rs.setOutput("front", true)
   rs.setOutput("right", false)
  elseif (message) == "Disable" then
   rs.setOutput("left", false)
   rs.setOutput("front", false)
  elseif (message) == "Backup" then
   rs.setOutput("right", true)
  end
 end
Bomb Bloke #11
Posted 31 January 2015 - 02:17 PM
When a computer/turtle starts running code, ComputerCraft starts a ten second timer. If that code doesn't yield before that timer ends then ComputerCraft will either crash the script or the whole computer (depending on the nature of the functions your script is calling). After each yield, any other systems waiting to run code may do so, then after they've all yielded, processing continues with a new time limit.

The reason why is that running your code chews up valuable server processing power, and so it shouldn't be able to monopolise it. In fact, only ONE CC device can run code at a time: While one is doing something, none of the others can do anything until it yields.

Whether or not it takes more than ten seconds for your code to execute has a little to do with the power of the Minecraft server it's running on, and a lot to do with how often you allow your code to yield. Pulling events (eg getting typed characters or checking timers) triggers a yield, and many commands (eg turtle movements, sleeping, or getting text input from the user) have to pull events to work anyway. Basically, anything that triggers a pause is pulling an event in order to do it, and in order to pull an event the code yields.

In your code, you pull one modem message event, then start a loop that inspects the result of that one message event over and over forever, without yielding again. Odds are you want to put your os.pullEvent() call into your loop, so that you're able to get and inspect more than one message.