Jump to content




movement API


  • You cannot reply to this topic
8 replies to this topic

#1 Jappards

  • Validating
  • 116 posts
  • LocationHolland

Posted 01 June 2013 - 01:09 PM

when i looked at the amount of movement API`s out there, i saw that there aren`t any proper ones, so i created a proper one.

features:
Spoiler

code:
Spoiler
or:
http://pastebin.com/Z2hAcYpu

pastebin get Z2hAcYpu move

Upcoming features:
-diagonal movement

note: this code isn`t tested yet, feel free to test it.

bugs
the most helpful way to report a bug is:
What I expected to happen was:

What actually happened was:

Steps to Reproduce:

#2 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 01 June 2013 - 02:22 PM

Just looking at the code, I can see a bunch of logic errors and syntax errors in it. Why post untested code and claim it to be the one proper movement API? In both of your functions, you are indexing the times variable like you are expecting a table. In your move function, you have unmatched 'end's. Your version function won't work. It looks like you are trying to tell the API user if they have the correct version given what they input. You never return true if the version is correct, and you compare version with a number literal which is incorrectly formatted. In your movement functions, you are trying to compare the direction with variables that don't exist. You need put quotes around them to make them string, assuming that's what you meant to do.

#3 Jappards

  • Validating
  • 116 posts
  • LocationHolland

Posted 02 June 2013 - 01:30 AM

View PostYevano, on 01 June 2013 - 02:22 PM, said:

Just looking at the code, I can see a bunch of logic errors and syntax errors in it. Why post untested code and claim it to be the one proper movement API? In both of your functions, you are indexing the times variable like you are expecting a table. In your move function, you have unmatched 'end's. Your version function won't work. It looks like you are trying to tell the API user if they have the correct version given what they input. You never return true if the version is correct, and you compare version with a number literal which is incorrectly formatted. In your movement functions, you are trying to compare the direction with variables that don't exist. You need put quotes around them to make them string, assuming that's what you meant to do.
i already fixed it and i made the direction into a string, all bugs in this code should be fixed now.

#4 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 02 June 2013 - 01:18 PM

You still didn't fix the if statements in your movement functions, and there's at least one missing end in your code. You have if statements inside of other if statements, which you probably meant to be next to each other. You didn't fix your times variable either. You still didn't test it, did you? :P

#5 Conan1981m

  • Members
  • 28 posts

Posted 07 June 2013 - 01:07 PM

well thats quite useless, if you want something like that, use rom/programs/turtles/go

#6 robotica34

  • Members
  • 28 posts
  • Locationpcapi.location

Posted 18 September 2013 - 12:45 PM

It's pretty cluttered in my opinion, always use TAB for safety.
Now that's something I should write (btw, it's short, because I got tired of typing XD):
function turn(dir, times)
 if dir == "left" then
  for i = 1, times do
   turtle.turnLeft()
  end
 elseif dir == "right" then
  for i = 1, times do
   turtle.turnRight()
  end
end
function refuel(times)
 local i = 0
 while turtle.getFuelLevel() == 0 then
   i = i+1
   turtle.select(i)
   turtle.refuel(times)
 end
end
function go(dir, times)
 for i = 1, times do
  shell.run("go", dir)
 end
end


#7 Dave-ee Jones

  • Members
  • 456 posts
  • LocationVan Diemen's Land

Posted 19 September 2013 - 02:43 AM

View PostJappards, on 01 June 2013 - 01:09 PM, said:

when i looked at the amount of movement API`s out there, i saw that there aren`t any proper ones, so i created a proper one.

-snip-

You know that your API is basically just the basic Turtle API? It doesn't really add anything else in.

#8 robotica34

  • Members
  • 28 posts
  • Locationpcapi.location

Posted 19 September 2013 - 03:28 AM

View PostAutoLocK, on 19 September 2013 - 02:43 AM, said:

View PostJappards, on 01 June 2013 - 01:09 PM, said:

when i looked at the amount of movement API`s out there, i saw that there aren`t any proper ones, so i created a proper one.

-snip-

You know that your API is basically just the basic Turtle API? It doesn't really add anything else in.
I agree with you, but he tried to do something "simpler". I made a turtle API once, but lost it (whatever), it had options like
function dig(dir, tillGravelEnds)
if tillGravelEnds == nil then tillGravelEnds = true end
if dir == nil then dir = "frwd" end
if dir == "left" then
  turtle.turnLeft()
  if tillGravelEnds then
   while turtle.detect() do
	turtle.dig()
	sleep(0.6) -- Was the best time for me
   end
  else
   turtle.dig()
  end
  turtle.turnRight()
end
end
That's a part of my "dig" function. Turtle API should contain every function that interacts with the Minecraft world.
I can see that your code contains critical function bugs (that means it won't function at all because of that bug).
What you wrote:
for i = 1, times[1] do
...
end
You try to access the times variable as a table (a collection of information in one variable). It should be:
for i = 1, times do
...
end
Anyways, I don't really like turtles, because I don't play Minecraft, unless coding :D If you're just like me, PM me for some more help. I'd like to help you =)

#9 robotica34

  • Members
  • 28 posts
  • Locationpcapi.location

Posted 19 September 2013 - 03:37 AM

Spoiler






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users