24 posts
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!
1111 posts
Location
Portland OR
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
24 posts
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!
7508 posts
Location
Australia
Posted 18 January 2013 - 01:27 AM
are you sending the message as "woodcollect" or "wooodcollect" ??
24 posts
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!
24 posts
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?
7508 posts
Location
Australia
Posted 18 January 2013 - 01:34 AM
no problems… how are you terminating? ctrl + t?
24 posts
Posted 18 January 2013 - 01:36 AM
no problems… how are you terminating? ctrl + t?
yes
7508 posts
Location
Australia
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?
24 posts
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'
7508 posts
Location
Australia
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 :)/>
24 posts
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'?
7508 posts
Location
Australia
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
4 posts
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
24 posts
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
24 posts
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?
2088 posts
Location
South Africa
Posted 18 January 2013 - 02:34 AM
Can we see the code where you send the rednet message for 'stop'
24 posts
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")
2088 posts
Location
South Africa
Posted 18 January 2013 - 02:40 AM
You may need to open rednet ;)/>
24 posts
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"
2088 posts
Location
South Africa
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,
2005 posts
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.
1 posts
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?
2088 posts
Location
South Africa
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.