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

[help] Api, how to make it useable.

Started by sjele, 13 August 2012 - 12:22 PM
sjele #1
Posted 13 August 2012 - 02:22 PM
Hi i just made my self a new turtle api, it's sort of a derp mode/ do random moves for a turtle. I made it so i could learn stuff. I read the "How to make a api" thread, but with my stupidity, i did not understand how to make it useable.
If i was to make a new program, and make so it said "Want derp mode Y/n", then have it get a answer, and so on.
And then when i wanted to call derp mode i wanted to do it something like
sjTurtle.derpMode()

My questions: How would i add it to the rom/apis folder?
How would i get that name for it?
Thanks

Code:



function randomWalk
local inf = noStop
  while inf ~= stop do
	sleep(.1)
	way = math.random(1, 6)
	if way == 1 then
	  turtle.forward()
	elseif way == 2 then
	  turtle.back()
	elseif way == 3 then
	  turtle.turnLeft()
	  turtle.forward()
	elseif way == 4 then
	  turtle.turnLeft()
	  turtle.forward()
	elseif way == 5 then
	  turtle.up()
	elseif way == 6 then
	  turtle.down()
	end
  end
end
function content
  print ("Content List")
  print ("Name:		   Usage:")
  print ("RandomWalk	  To be found out")
end


This is my first api, and first time trying :P/>/>
Formatting messed up.
Boldy97 #2
Posted 13 August 2012 - 02:43 PM
First: change this

function randomWalk
to this

function randomWalk()
or



function derpMode()

If you desire.


you have to put your file in the mods/ComputerCraft/lua/rom/apis folder
name your file turtle. the file can't have an extension!

Writing lua on your turtle ingame, then enter, then turtle.derpMode() will start your API.

Good luck :P/>/>


Best regards,
Boldy97


PS: i have no idea how to explain this another way.
KaoS #3
Posted 13 August 2012 - 02:43 PM
Basically you write a list of functions, you save those functions to a file, you place that file in the APIS directory, once you reboot the CC pc it will read, the api name is the name of the file, let's say that you named it 'myapi' and you made the function 'randomWalk()' then in the lua console or in a program to call this function you enter in 'myapi.randomWalk' that is the basics
sjele #4
Posted 13 August 2012 - 03:05 PM
It wasent worse than that, i see.
Thanks :P/>/>
makerimages #5
Posted 14 August 2012 - 08:17 AM
saving without a extension : you usually put "filename" (with the two "-s)