17 posts
Location
Read my location form for my location.
Posted 25 October 2012 - 04:11 PM
This likely won't get anywhere, but here it is. I've been working on yesterday, a random number generator.
I have updated it recently to only work on turtles, but output letters, and make the turtle move. Later, yes, I wll add a ton of more modes. For now, I just want to make sure it works, and it works well and works like I wanted it. Still, it wasn't how I wanted it, but it's good enough.
SPECIAL EDITION, Turtle Maze v.0.1337 (Lasts for the first hour):
http://pastebin.com/T4GcZjghTurtle Maze v.0.4:
http://pastebin.com/mXsCXkN2Older Versions:
Spoiler
v.0.1: Mlf
v.0.2: mlf
v.0.3: http://pastebin.com/1Nu5b1x3
v.0.4: http://pastebin.com/mXsCXkN2
521 posts
Location
Stockholm, Sweden
Posted 25 October 2012 - 04:26 PM
2088 posts
Location
South Africa
Posted 25 October 2012 - 04:26 PM
Make it so you have type a string or a decimal number in anywhere it fails and restarts. ^_^/>/>
17 posts
Location
Read my location form for my location.
Posted 25 October 2012 - 04:28 PM
About half-a-second delay between outputs, so it doesn't crash.
Make it so you have type a string or a decimal number in anywhere it fails and restarts. ^_^/>/>
So, you can terminate it with the press of any key? I'll have to look into that, but it'll happen.
2088 posts
Location
South Africa
Posted 25 October 2012 - 04:34 PM
About half-a-second delay between outputs, so it doesn't crash.
If I'm not mistake, for loops don't need pauses to stop crashes.
Make it so you have type a string or a decimal number in anywhere it fails and restarts. ^_^/>/>
So, you can terminate it with the press of any key? I'll have to look into that, but it'll happen.
No. If you were to type a string, such as 'asd' into where it asks for range. It will give an error saying that number expected, got string.
521 posts
Location
Stockholm, Sweden
Posted 25 October 2012 - 04:35 PM
About half-a-second delay between outputs, so it doesn't crash.
Well
for loops dosen't crash, it's
while and
repeat loops that does..
521 posts
Location
Stockholm, Sweden
Posted 25 October 2012 - 04:37 PM
& Upon large (any, but rarer) maximum number inputs, sometimes the output says "nan" between outputs.
NaN = Not a number
Self explanatory…
17 posts
Location
Read my location form for my location.
Posted 25 October 2012 - 04:42 PM
& Upon large (any, but rarer) maximum number inputs, sometimes the output says "nan" between outputs.
NaN = Not a number
Self explanatory…
Yup, I know that. Trying to fix it now, i might release a quick bufix patch soon…
In the meantime,
http://pastebin.com/CpNxixXF is the Turtle Movement number generator, which randomly makes a turtle move, better than built-in dance, and also outputs the movements as letters.
About half-a-second delay between outputs, so it doesn't crash.
Well
for loops dosen't crash, it's
while and
repeat loops that does..
Oh, I thought all crashed.
2088 posts
Location
South Africa
Posted 25 October 2012 - 04:46 PM
Why not make turtle go up and down? ^_^/>/>
17 posts
Location
Read my location form for my location.
Posted 25 October 2012 - 04:49 PM
Why not make turtle go up and down? ^_^/>/>
http://pastebin.com/1Nu5b1x3It also digs, provided you use a Pickaxe Turtle.
521 posts
Location
Stockholm, Sweden
Posted 25 October 2012 - 04:58 PM
Well your code got too many sleep(0).
You could make it "shorter" by doing:
(I'm not sure if you can have functions in tables, and because the minecraft login is down I can't test it)
print("I will dance now. RUN FOR YOUR LIFE!!!!!")
sleep(2.5)
local r = 0
local moves = {
{char="f",move=turtle.forward}
{char="b",move=turtle.back}
{char="l",move=turtle.turnLeft}
{char="r",move=turtle.turnRight}
{char="u",move=turtle.up}
{char="d",move=turtle.down}
}
while true do
r = math.random(1, #moves)
write(moves.[r].char)
moves.[r].move()
end
Because the moves takes time to operate the loop wont crash.
EDIT: The login is back up again!
17 posts
Location
Read my location form for my location.
Posted 25 October 2012 - 05:03 PM
Well your code got too many sleep(0).
You could make it "shorter" by doing:
(I'm not sure if you can have functions in tables, and because the minecraft login is down I can't test it)
print("I will dance now. RUN FOR YOUR LIFE!!!!!")
sleep(2.5)
local r = 0
local moves = {
{char="f",move=turtle.forward}
{char="b",move=turtle.back}
{char="l",move=turtle.turnLeft}
{char="r",move=turtle.turnRight}
{char="u",move=turtle.up}
{char="d",move=turtle.down}
}
while true do
r = math.random(1, #moves)
write(moves.[r].char)
moves.[r].move()
end
Because the moves takes time to operate the loop wont crash.
EDIT: The login is back up again!
Thanks. I've never really understood tables and their positive features, so I never really used them. I'll probably add this in the next update. Ah, what the heck, I'll do it now.
2088 posts
Location
South Africa
Posted 25 October 2012 - 05:05 PM
Well your code got too many sleep(0).
You could make it "shorter" by doing:
(I'm not sure if you can have functions in tables, and because the minecraft login is down I can't test it)
print("I will dance now. RUN FOR YOUR LIFE!!!!!")
sleep(2.5)
local r = 0
local moves = {
{char="f",move=turtle.forward}
{char="b",move=turtle.back}
{char="l",move=turtle.turnLeft}
{char="r",move=turtle.turnRight}
{char="u",move=turtle.up}
{char="d",move=turtle.down}
}
while true do
r = math.random(1, #moves)
write(moves.[r].char)
moves.[r].move()
end
Because the moves takes time to operate the loop wont crash.
EDIT: The login is back up again!
Tables have so many uses, it's just AMAZING. lol
17 posts
Location
Read my location form for my location.
Posted 25 October 2012 - 05:21 PM
Jag, yew bwoke it!
fix ite!
Nah, don't worry, I'll fix it. I'll bore myself to death reading about tables, and then fix it myself.
521 posts
Location
Stockholm, Sweden
Posted 25 October 2012 - 05:24 PM
Don't get too comfortable with this solution!
It didn't work!!
I tried multiple ways to solve the error but nothing worked…
Error:
bios:338: [string "newDance"]:6: '}'
expected (to close '{' at line 6)
17 posts
Location
Read my location form for my location.
Posted 25 October 2012 - 05:26 PM
Don't get too comfortable with this solution!
It didn't work!!
I tried multiple ways to solve the error but nothing worked…
Error:
bios:338: [string "newDance"]:6: '}'
expected (to close '{' at line 6)
This is why, I stick with simplicity. Even if it's long and boring, it's just easier. I shall revert the code to an earlier version. I will never do tables, unless the sciprt absolutely completely urgently utterly requires it.
521 posts
Location
Stockholm, Sweden
Posted 25 October 2012 - 05:56 PM
Hey you know what?
It was a derpy error!!
I forgot the comma ( , ) between the tables…
I got another error now that I'm trying to solve
bios:338: [string "newDance"]:14:
'<name>' expected
17 posts
Location
Read my location form for my location.
Posted 25 October 2012 - 06:20 PM
Your code, your problem. ^_^/>/>
That's simple, isn't it? On line 14 somewhere, you didn't supply a name or something like that for a variable, is that not it?
474 posts
Posted 25 October 2012 - 07:31 PM
Hey you know what?
It was a derpy error!!
I forgot the comma ( , ) between the tables…
I got another error now that I'm trying to solve
bios:338: [string "newDance"]:14:
'<name>' expected
You failed here:
write(moves.[r].char)
moves.[r].move()
It should be:
write(moves[r].char)
moves[r].move()
If I'm correct.
1054 posts
Posted 25 October 2012 - 07:40 PM
About half-a-second delay between outputs, so it doesn't crash.
Well
for loops dosen't crash, it's
while and
repeat loops that does..
for i=1,math.huge do
print(i)
end
It has nothing to do with the kind of loop. Technically you could write a huge script that runs long enough to crash the program. It's just that it runs to long without yielding, regardless of how it runs.
Edit:
If you find that I'm cheating because this technically is 'while true do', this will still crash:
for i=1,10^6 do
print(i)
end
521 posts
Location
Stockholm, Sweden
Posted 25 October 2012 - 10:38 PM
Hey you know what?
It was a derpy error!!
I forgot the comma ( , ) between the tables…
I got another error now that I'm trying to solve
bios:338: [string "newDance"]:14:
'<name>' expected
You failed here:
write(moves.[r].char)
moves.[r].move()
It should be:
write(moves[r].char)
moves[r].move()
If I'm correct.
You are correct!!!
Either you do
moves[r].move()
or
moves[r]["move"]()
So the final code:
(Also on pastebin:
uVSjref1)
print("I will dance now. RUN FOR YOUR LIFE!!!!!")
sleep(2.5)
local r = 0
local moves = {
{char="f",move=turtle.forward},
{char="b",move=turtle.back},
{char="l",move=turtle.turnLeft},
{char="r",move=turtle.turnRight},
{char="u",move=turtle.up},
{char="d",move=turtle.down}
}
while true do
r = math.random(1, #moves)
write(moves[r].char)
moves[r].move()
end
17 posts
Location
Read my location form for my location.
Posted 27 October 2012 - 11:04 AM
SNIP
Okay, thanks a lot. I'll probably use that, and upgrade it when I see fit.
Just thought of adding a few options, and a main menu. I'll do that. Thanks again for all of your help, and everyone else's.