14 posts
Posted 20 November 2012 - 09:29 AM
I used a program on this website called 'streetbuilder' and have edited it.
I am trying to make the turtle return to where it started at the end of the program using the last bit of this code below.
http://pastebin.com/9s120wXNThis generates the error
bios:338: [string "platform"] :24: '=' expected.
line 24 is "when x==a do"
what I would like to know is where i am going wrong or is there a better way to do it?
386 posts
Location
France
Posted 20 November 2012 - 09:42 AM
Thanks for recreate a new topic :(/>/>. It's because
When … then does not exist. You should use if … then instead.
14 posts
Posted 20 November 2012 - 09:56 AM
Ok, i changed 'when' to 'if' but it now says it expects 'then' so I tried that and got "error unexpected symbol" I'm still a bit of a novice but any ideas?
So sorry I was being a div, now I have
if x==a then
etc. etc.
however it chooses to ignore this area of code completely, presumably because x doesn't equal a but i can't think what to do.
yet another edit: after changing x==a to x<=a it registers this code and turns right twice but only goes forward once. How do i make the value of 'a' stay around?
Edited on 20 November 2012 - 09:20 AM
2088 posts
Location
South Africa
Posted 20 November 2012 - 10:15 AM
try
while a == x do
-- code
end
14 posts
Posted 20 November 2012 - 10:32 AM
try
while a == x do
-- code
end
Just tried that, and it didn't execute the coding at all, is it possible that "a" is getting cleared at the first "end" tag?
2088 posts
Location
South Africa
Posted 20 November 2012 - 10:39 AM
No, that means a is not equal to x.
14 posts
Posted 20 November 2012 - 10:48 AM
does x<=a mean x is greater than or equal to a? because that may solve that bit at least.
2088 posts
Location
South Africa
Posted 20 November 2012 - 10:51 AM
x <= a – x is smaller than or equal to a
x >= a – x is greater than or equal to a
x == a – x is equal to a
x ~= a – x it not equal to a
x > a – x is only greater than a
x < a – x is only smaller than a
14 posts
Posted 20 November 2012 - 10:57 AM
So using x>=a should solve it, but I have tried that and it turns right twice and moves forward once.
When a is three.
Because when I run the program it says how much?
So I type in three which I believe should register "a" as three. Am I right there? Or have I missed something with variables etc?
2088 posts
Location
South Africa
Posted 21 November 2012 - 02:02 AM
Can you post the current code you have now?
If a starts of as 3 and x is 1, obviously it's only going to go twice because everytime it does one loop x is increases.
What exactly are you trying to do?
14 posts
Posted 21 November 2012 - 05:45 AM
All of my code as of now:
http://pastebin.com/nr9SzPDNwhat I am trying to achieve is you run the program and it asks how long you want the platform that is to be built to be.
Then the value you input is registered as "a"
then the turtle places a 3 block wide platform "a" times.
hen the turtle does a 180 and goes forward "a" times.
2088 posts
Location
South Africa
Posted 21 November 2012 - 06:12 AM
Oh so it does something like this?
-- If you enter 5, will it do this?
XXX -- start
XXX
XXX
XXX
XXX -- end
then return to start?
I didn't add any turtle.refuel, but you can do that :(/>/>
If so, then try this:
Spoiler
Args = {...}
if not Args[1] or not tonumber(Args[1]) then
print("Usage: " .. fs.getName(shell.getRunningProgram()) .. " <length>")
return
end
l = tonumber(Args[1])
for i = 1, l do
turtle.forward()
turtle.digDown()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.digDown()
turtle.placeDown()
turtle.forward()
turtle.digDown()
turtle.placeDown()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnRight()
end
for i = 1, l-1 do turtle.back() end
14 posts
Posted 21 November 2012 - 06:27 AM
Oh so it does something like this?
-- If you enter 5, will it do this?
XXX -- start
XXX
XXX
XXX
XXX -- end
then return to start?
Yes that's exactly what i'm trying to achieve, i've just ran your code and it works perfectly thank you,
now for the part to actually get better at this.
"I'm assuming "args" means argument.
so your coding is saying:
Argument = {nothing}
if not nothing then execute code?
and the bit of coding that makes the turtle return to start, the
for i = 1, l-1 do turtle.forward() end
does that mean for a <length> of 1 go forward once and multiply by whatever value "i" is?
8543 posts
Posted 21 November 2012 - 06:45 AM
The … isn't "nothing", it's how you catch variable arguments. Putting them into a table happens to be the handiest way of using them.
2088 posts
Location
South Africa
Posted 21 November 2012 - 06:54 AM
Oh so it does something like this?
-- If you enter 5, will it do this?
XXX -- start
XXX
XXX
XXX
XXX -- end
then return to start?
Yes that's exactly what i'm trying to achieve, i've just ran your code and it works perfectly thank you,
now for the part to actually get better at this.
"I'm assuming "args" means argument.
so your coding is saying:
Argument = {nothing}
if not nothing then execute code?
and the bit of coding that makes the turtle return to start, the
for i = 1, l-1 do turtle.forward() end
does that mean for a <length> of 1 go forward once and multiply by whatever value "i" is?
Oh so it does something like this?
-- If you enter 5, will it do this?
XXX -- start
XXX
XXX
XXX
XXX -- end
then return to start?
Yes that's exactly what i'm trying to achieve, i've just ran your code and it works perfectly thank you,
now for the part to actually get better at this.
"I'm assuming "args" means argument.
so your coding is saying:
Argument = {nothing}
if not nothing then execute code?
and the bit of coding that makes the turtle return to start, the
for i = 1, l-1 do turtle.forward() end
does that mean for a <length> of 1 go forward once and multiply by whatever value "i" is?
Yes args is arguments and it is used to catch arguments for when you run the program.
I edited my code before you quoted because I actually forgot about turtle.back() so you can actually remove the 4 turtle.turnLeft() near the end.
The loop basically means while i <= l-1 do turtle.forward() end. I actually am not sure how to explain it but it will just do turtle.forward l (length) - 1 times. - 1 because I made it move forward in the beginning.
14 posts
Posted 21 November 2012 - 07:47 AM
I think I understand it now, thanks a million, now to actually start building…
2088 posts
Location
South Africa
Posted 21 November 2012 - 09:04 AM
I think I understand it now, thanks a million, now to actually start building…
Haha enjoy :(/>/> Once you get use to LUA and turtle coding, you have some awesome times with that you can do with them :(/>/>