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

[Suggestion] Self-Aware Functions

Started by darkwolf, 24 February 2012 - 04:45 PM
darkwolf #1
Posted 24 February 2012 - 05:45 PM
Is there a possiblity to get a few self aware functions for the turtle?

Examples:

Number x = turtle.getLocX()
Number y = turtle.getLocY()
Number z = turtle.getLocZ()

Number dir = turtle.getLookDir()

String loc = turtle.getLoc()

Number type = turtle.getItemID(Number slot)
Number damage = turtle.getItemDamage(Number slot)


Edit: Added another function.
bepZ #2
Posted 24 February 2012 - 05:50 PM
That would be awesome.
Advert #3
Posted 24 February 2012 - 06:03 PM
I don't really want this, as this is magic; you can code this yourself, in Lua.

An excerpt from my turtle functions:




do -- Movement functions
	function turnLeft()
		tFace = tFace + 1
		turtle.turnLeft()
	end
	
	function turnRight()
		tFace = tFace - 1
		turtle.turnRight()
	end
	
	function moveForward()
		local dX, dY = resolveFace()
		if turtle.forward() then
			tX, tY = dX, dY
			safeMap(dX, dY, true)
			return true
		end
		safeMap(dX, dY, false)
		return false		
	end
	
	function moveBackward()
		local fX, fY = getFaceXY()		
		if turtle.back() then
			tX, tY = tX - fX, tY - fY
			safeMap(tX, tY, true)
			return true
		end
		safeMap(tX - fX, tY - fY, false)
		return false
	end
end


Yes, stuff is missing, such as safeMap, the variables, etc; but this will keep track of the turtle's position, facing, etc.
darkwolf #4
Posted 24 February 2012 - 06:13 PM
I know how to track it manually it just would be nice incase it ever lost its location.

And how is the rest of Computercraft (especially the turtle) not magic?
Advert #5
Posted 24 February 2012 - 06:19 PM
I know how to track it manually it just would be nice incase it ever lost its location.

And how is the rest of Computercraft (especially the turtle) not magic?

You can save the turtle's location in a file; I really feel that this problem should be one that users should solve; obtaining world coordinates in minecraft is magic.

My definition of magic is very loose; Yes, you could consider turtles magic, but they work pretty slowly, and see the world in I can/can't walk there. You can't simply program them to get diamonds; you have to make them mine, then figure out a path to return to, etc.

Turtles are a lot of fun, and adding unreasonable stuff like getting the world coordinates will break that.
darkwolf #6
Posted 24 February 2012 - 06:27 PM
Not everyone thinks like you. Why not just add self aware functions in their own api and make that api toggleable like http.

That way people who don't share your opinion can choose to enable it.
Liraal #7
Posted 24 February 2012 - 07:00 PM
well, users can simply make an api like this
What would you like to see in one? I think I can make it pretty quick (unless you overcomplicate it, that is :P/>/> )
Casper7526 #8
Posted 24 February 2012 - 07:08 PM
Thats what magicblock is for (check the peripheral library)

It allows you to do these "magic" things.
Liraal #9
Posted 24 February 2012 - 07:18 PM
Stop spoiling my api-making fun! :P/>/>
Sebra #10
Posted 24 February 2012 - 08:25 PM
Coords and direction are not so useful as ability to analyze blocks/items around itself.
You can track moving indirectly, but without sensors you are blind. Current detect is boolean only :)/>/>
darkwolf #11
Posted 25 February 2012 - 02:42 AM
Thats what magicblock is for (check the peripheral library)

It allows you to do these "magic" things.

I know about that peripheral but I wanted these functions to be usable on my minecraft server I host for me and my friends.
Liraal #12
Posted 25 February 2012 - 07:54 AM
Well, now they are. Just download the API.