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

bios:338: [string "startup"]:7: 'then' expected

Started by okok99haha, 17 January 2013 - 11:57 PM
okok99haha #1
Posted 18 January 2013 - 12:57 AM
rednet.open("right")
local id, message = rednet.receive()
print("From: ", id, ", Message: ", message)

while true do

if message = "wooodcollect" then
shell.run("woodcollect")
end

bios:338: [string "startup"]:7: 'then' expected
I keep getting this message even though when I have 'then' on line 3.
Please help!
Luanub #2
Posted 18 January 2013 - 01:14 AM
Your missing a = for comparisons its == and to assign a value its = so

if message = "wooodcollect" then

--should be
if message == "wooodcollect" then
okok99haha #3
Posted 18 January 2013 - 01:25 AM
Your missing a = for comparisons its == and to assign a value its = so

if message = "wooodcollect" then

--should be
if message == "wooodcollect" then
Thank you, it worked.
But the problem is that when I send the message "woodcollect" (it's a program name) it shows that it received the message but it doesn't run the program
Could you please check?
Thank you!
theoriginalbit #4
Posted 18 January 2013 - 01:27 AM
are you sending the message as "woodcollect" or "wooodcollect" ??
okok99haha #5
Posted 18 January 2013 - 01:29 AM
are you sending the message as "woodcollect" or "wooodcollect" ??
Oh I see I typed 3 o's by mistake
Thank you for finding my mistake!
okok99haha #6
Posted 18 January 2013 - 01:32 AM
Now I have a problem.. Every time I terminate it doesn't stop and the program restarts.. Can anyone tell me how to stop it?
theoriginalbit #7
Posted 18 January 2013 - 01:34 AM
no problems… how are you terminating? ctrl + t?
okok99haha #8
Posted 18 January 2013 - 01:36 AM
no problems… how are you terminating? ctrl + t?
yes
theoriginalbit #9
Posted 18 January 2013 - 01:38 AM
……. ummm… Is there any other scripts running on the computer? Are you pressing ctrl + t one too many times and terminating shell too? can we see all your code?
okok99haha #10
Posted 18 January 2013 - 01:40 AM
……. ummm… Is there any other scripts running on the computer? Are you pressing ctrl + t one too many times and terminating shell too? can we see all your code?

function plantSapling()
turtle.select(2)
turtle.place()
end

function placeBone()
turtle.select(3)
turtle.place()
end

function dig()
turtle.dig()
turtle.forward()
end

function digUp()
turtle.digUp()
turtle.up()
turtle.digUp()
turtle.up()
turtle.digUp()
turtle.up()
turtle.digUp()
turtle.up()
turtle.digUp()
turtle.up()
turtle.digUp()
end

function goBack()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
end


while true do
plantSapling()
placeBone()
dig()
digUp()
goBack()
turtle.suck()
end


This is my codes for 'woodcollect'
theoriginalbit #11
Posted 18 January 2013 - 01:46 AM
oh i see why… haha… it because after you terminate it, it will go back to the program that called it, in this case your program you got help with here, and message still equals 'woodcollect' so it runs it again… put the rednet receive inside the while loop to fix :)/>
okok99haha #12
Posted 18 January 2013 - 01:52 AM
oh i see why… haha… it because after you terminate it, it will go back to the program that called it, in this case your program you got help with here, and message still equals 'woodcollect' so it runs it again… put the rednet receive inside the while loop to fix :)/>
hmm.. not sure if I did it right
Now it just stops every time and start the program when I terminate
I typed rednet.receive() just before the last end
And is there way to stop the turtle if I send the message 'stop'?
theoriginalbit #13
Posted 18 January 2013 - 01:55 AM
if should be this

rednet.open("right")

while true do
  local id, message = rednet.receive()
  print("From: ", id, ", Message: ", message)
  if message == "woodcollect" then
	shell.run("woodcollect")
  end

if you want to add 'stop' just change the if

if message == "woodcollect" then
  shell.run( "woodcollect" )
elseif message == "stop" then
  return
end
money #14
Posted 18 January 2013 - 01:57 AM
……. ummm… Is there any other scripts running on the computer? Are you pressing ctrl + t one too many times and terminating shell too? can we see all your code?

function plantSapling()
turtle.select(2)
turtle.place()
end

function placeBone()
turtle.select(3)
turtle.place()
end

function dig()
turtle.dig()
turtle.forward()
end

function digUp()
turtle.digUp()
turtle.up()
turtle.digUp()
turtle.up()
turtle.digUp()
turtle.up()
turtle.digUp()
turtle.up()
turtle.digUp()
turtle.up()
turtle.digUp()
end

function goBack()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
end


while true do
plantSapling()
placeBone()
dig()
digUp()
goBack()
turtle.suck()
end


This is my codes for 'woodcollect'


function plantSapling()
  turtle.select(2)
  turtle.place()
end
function placeBone()
  turtle.select(3)
  turtle.place()
end
function dig()
  turtle.dig()
  turtle.forward()
end
function digUp()
  repeat
	turtle.digUp()
	turtle.up()
	d = turtle.detectUp()
  until d == false
  sleep(0.5)
end
function goBack()
  repeat
	turtle.down()
	e = turtle.detectUp()
  until e == true
  turtle.turnLeft()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnLeft()
  turtle.turnLeft()
  sleep(0.5)
end

while true do
plantSapling()
placeBone()
dig()
digUp()
goBack()
turtle.suck()
end

a better code for chopping tree
okok99haha #15
Posted 18 January 2013 - 02:07 AM
if should be this

rednet.open("right")

while true do
  local id, message = rednet.receive()
  print("From: ", id, ", Message: ", message)
  if message == "woodcollect" then
	shell.run("woodcollect")
  end

if you want to add 'stop' just change the if

if message == "woodcollect" then
  shell.run( "woodcollect" )
elseif message == "stop" then
  return
end
I have no idea why but it just place item on slot 2 and just turns 360 degrees
Never mind it was out of fuel
okok99haha #16
Posted 18 January 2013 - 02:33 AM
if should be this

rednet.open("right")

while true do
  local id, message = rednet.receive()
  print("From: ", id, ", Message: ", message)
  if message == "woodcollect" then
	shell.run("woodcollect")
  end

if you want to add 'stop' just change the if

if message == "woodcollect" then
  shell.run( "woodcollect" )
elseif message == "stop" then
  return
end

Sending the message stop doesn't seem to stop the turtle..
rednet.open("right")
while true do
  local id, message = rednet.receive()
  print("From: ", id, ", Message: ", message)
  if message == "woodcollect" then
  shell.run( "woodcollect" )
elseif message == "stop" then
  return
  end
end

function plantSapling()
  turtle.select(2)
  turtle.place()
end
function placeBone()
  turtle.select(3)
  turtle.place()
end
function dig()
  turtle.dig()
  turtle.forward()
end
function digUp()
  turtle.digUp()
  turtle.up()
  turtle.digUp()
  turtle.up()
  turtle.digUp()
  turtle.up()
  turtle.digUp()
  turtle.up()
  turtle.digUp()
  turtle.up()
  turtle.digUp()
end
function goBack()
  turtle.down()
  turtle.down()
  turtle.down()
  turtle.down()
  turtle.down()
  turtle.down()
  turtle.turnLeft()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnLeft()
  turtle.turnLeft()
end

while true do
plantSapling()
placeBone()
dig()
digUp()
goBack()
end
Is this correct?
remiX #17
Posted 18 January 2013 - 02:34 AM
Can we see the code where you send the rednet message for 'stop'
okok99haha #18
Posted 18 January 2013 - 02:36 AM
Can we see the code where you send the rednet message for 'stop'
I just use lua
rednet.send(32,"stop")
remiX #19
Posted 18 January 2013 - 02:40 AM
You may need to open rednet ;)/>
okok99haha #20
Posted 18 January 2013 - 02:59 AM
You may need to open rednet ;)/>
Rednet is opened but still doesn't stop when I send the message "stop"
remiX #21
Posted 18 January 2013 - 03:06 AM
You may need to open rednet ;)/>
Rednet is opened but still doesn't stop when I send the message "stop"
I know you opened it on the receiving end.
You said you opened it using lua prompt, but did you open rednet on the computer you're sending with?\

Post the code as one so we can see, above you have the code in 2 parts,
ChunLing #22
Posted 18 January 2013 - 12:42 PM
It currently wouldn't stop the turtle in the middle of a woodcollect cycle. So you need to make it so that woodcollect isn't an infinite cycle. Or you can put a rednet.receive with a timeout inside of the loop for woodcollect, and have it exit the loop on receiving the stop message. There is a bit of a problem because you have to send the stop message during a time when the turtle is actually listening for it (turtle functions dump events, unless you use the turtle.native versions).

If you really need to make it so that a turtle will stop immediately on receiving a given rednet message, it's possible to rebuild the turtle.native API into a version that makes it so that any turtle function also looks for a stop message. I've never really felt the need for this myself.
1xx-lars-xx1 #23
Posted 17 February 2013 - 10:06 AM
So i get:
bios:338: [string ''startup''] : 14: 'end'
expected (to close 'function' at line 7)

And my script is for a melee turtle.
Here it is:

function attack()
turtle.attack()
check()
sleep(.1)
end

function check()
if turtle.getItemCount(16) > 0 then
for i = 1, 16 do
turtle.select(i)
turtle.dropDown()
end
turtle.select(1)

What am i doing wrong here?
remiX #24
Posted 17 February 2013 - 10:33 AM
Add another end at the end of function check()

PS: Rename the attack() function because it might over-write the turtle.attack() function.