Jump to content




HELP! - Program not working


10 replies to this topic

#1 bwbwbwboo111

  • Members
  • 5 posts

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

#2 Dragon53535

  • Members
  • 968 posts
  • LocationIn the Matrix

Posted 30 January 2015 - 07:32 PM

A couple of tips. When posting code, use the code tags. [ code][/code]

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 by Dragon53535, 30 January 2015 - 07:33 PM.


#3 bwbwbwboo111

  • Members
  • 5 posts

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?

#4 bwbwbwboo111

  • Members
  • 5 posts

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


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

Edited by Cranium, 30 January 2015 - 09:13 PM.


#5 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 30 January 2015 - 09:13 PM

For future reference, it's easier if you put your code in [code] tags, and long chunks of text in [spoiler] tags.

#6 TurtleHunter

  • Members
  • 112 posts

Posted 30 January 2015 - 09:24 PM

View Postbwbwbwboo111, on 30 January 2015 - 09:10 PM, said:

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


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

#7 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

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 by HPWebcamAble, 31 January 2015 - 12:20 AM.


#8 bwbwbwboo111

  • Members
  • 5 posts

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!

#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,096 posts
  • LocationTasmania (AU)

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.

#10 bwbwbwboo111

  • Members
  • 5 posts

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


#11 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,096 posts
  • LocationTasmania (AU)

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users