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

[error] when do statement doesn't work

Started by moltenberry, 03 August 2012 - 11:08 AM
moltenberry #1
Posted 03 August 2012 - 01:08 PM
hi

im very new to this mod and i was experimenting with turtles.
but when i try to do a when d statement it say's.

bios:206: [string "a"]:1: '=' expected

its realy anoying when i try to properly progam (for a noob)

my (very nooby code was)

when turtle.detect() do
turtle.dig
turtle.forward
end

i hope that you wil find it out soon

i am using computercraft in tekkit 3.0.4
KaoS #2
Posted 03 August 2012 - 01:11 PM
replace 'when' with 'if'
and you need () after turtle.dig and turtle.forward

so:


if turtle.detect() do
turtle.dig()
turtle.forward()
end
Luanub #3
Posted 03 August 2012 - 01:11 PM
You will want to use while instead of when. Also when you call a function you will want to follow it with ()'s

Corrected code:

while turtle.detect() do
turtle.dig()
turtle.forward()
end

An if statement would be


if turtle.detect() then
Edited on 03 August 2012 - 11:13 AM
KaoS #4
Posted 03 August 2012 - 01:11 PM
if you want it to keep looping when use 'while' instead of 'if'
KaoS #5
Posted 03 August 2012 - 01:13 PM
ah luanub caught it too :ph34r:/>/>

hope this all helps, another thing:

the loop will stop as soon as it does not detect something but if you want it to keep looping and checking forever then use this


while true do
if turtle.detect() then
turtle.dig()
turtle.forward()
else
sleep(0.5)
end
end
Mtdj2 #6
Posted 03 August 2012 - 01:14 PM
Hi. In lua, there are no such things as a 'when'. If you want it to loop, do:

while turtle.detect() do
turtle.dig()
turtle.forward()
end
Or if it is only one time it shall detect, do:

if turtle.detect() do
turtle.dig()
turtle.forward()
else
turtle.back() --Only an example of the "else". You can exclude the else and back.
end
Hope this helped.