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

Turtle pyramid?

Started by Pixelmnkey, 12 January 2013 - 02:16 AM
Pixelmnkey #1
Posted 12 January 2013 - 03:16 AM
I have no clue about lua, but i want to make a huge pyramid, about 100x100 base with them, i think that the program will be something like:

Input the size of the pyramid.

Place under x amount of and move forward 1

repeat untill the pyramid base size

then turn right, repeat.


But i really have no clue how to do it, is there any script done already or a fast way someone could code it for me? Or tell me the comands for placing a block and repeat, if you can ofcourse.

Thanks!
theoriginalbit #2
Posted 12 January 2013 - 03:19 AM
it has been done by one of the people ages ago on Pahicraft (now Forgecraft) SMP…

http://pastebin.com/YcSh5SB9
Pixelmnkey #3
Posted 12 January 2013 - 03:52 AM
Thanks!
Pixelmnkey #4
Posted 12 January 2013 - 04:21 AM
Why it can't load library " kurtle" ? I'm using a mining one, do i need to use a normal one?
remiX #5
Posted 12 January 2013 - 04:31 AM
Looks like those are API's the guy used with this, not sure where they are though.
ChunLing #6
Posted 12 January 2013 - 04:39 AM
kurtle is the name of a custom api that this program uses, looks like. You'd either need to find a copy of that api or rewrite this code entirely (which I'm guessing is beyond your current skills).

Generally we help people with programming rather than do programming for them. In this case, what you want is simple enough that I think meeting you halfway isn't too much. Here's how you could make the base layer of the pyramid:
write("Specify base: ")
base = tonumber(read())
for i=1,base do
    for j=1,base do
        turtle.digDown()
        turtle.placeDown()
        turtle.forward()
    end
    if i%2 ~= 0 then
        turtle.turnRight()
        turtle.digDown()
        turtle.placeDown()
        turtle.forward()
        turtle.turnRight()
    else
        turtle.turnLeft()
        turtle.digDown()
        turtle.placeDown()
        turtle.forward()
        turtle.turnLeft()
    end
end
This makes the turtle excavate a layer under it and place blocks from it's selected inventory slot there. If the selected slot contains enough blocks, you can make a square foundation of up to 8x8.

Play around with this, then see if you can't figure out how to make the turtle go up and over to make the next layer (start with a base smaller than 8, or you'll be out of blocks).
Pixelmnkey #7
Posted 12 January 2013 - 04:43 AM
Thanks i know, but i have no clue how to program it, i'll work with the codes u gave me, thanks for your help :)/>
Pixelmnkey #8
Posted 12 January 2013 - 04:50 AM
Ok, there are a few typos but i can world with that, can i use it to place the items in ALL the inventory slots instead of the first one?
ChunLing #9
Posted 12 January 2013 - 05:17 AM
A good question. There are a couple of ways to approach this. One is a simple function that selects the first slot that has anything in it. This is not so suitable for this since there is some excavating and if the base is larger than 8x8, we'll end up with some dirt/sand/whatever in our inventory and that would mess things up. So we want to track the slot and make sure to increment when it's empty. First we declare our selected slot tracking variable at the top of the program so it will have scope throughout the program, and initialize it to the first slot:
local sslot = 1
Then we create a function that looks for the next slot that has inventory and selects it:
function selectNextSlot()
    while turtle.getItemCount(sslot) == 0 and sslot < 16 do
        sslot = sslot+1
    end
    turtle.select(sslot)
return turtle.getItemCount(sslot) end
This function also returns the item count for the selected slot, since I made it so it stops when it gets to 16, even if it's empty. You probably won't need that return, since if you're out of building blocks then your out of building blocks. But it's there if you need it.

Now you can call this right after each turtle.place(), and it will check and see if the selected slot is empty, and if so, will select the next slot that has inventory (or 16, if you are out of inventory in the remaining slots).
Pixelmnkey #10
Posted 12 January 2013 - 05:28 AM
Uhm, yeah, that should work for a standard pyramid builder, in my case i just need to build a pyramid ( empty inside, sorry i've forgot to tell you that ) and the base is already flat, so it would be easier to just ask for the base, for example 100 in my case, and do a while untill it reaches 100 with turtle.place() and turtle.forward(), when it reachs the base number, turn right and do the same base -1, repeat 3 more times, then move up, turn right and start by base -2, then turn base -1 repeat 3… and so on, you know what i mean? So i get a hollow pyramid with the base i've told him, i'll try to work on a code and see if it works.

Really thanks for your help :)/>

Something like this should do a full square with the base i told him?


write("Specify base: ")
base = tonumber(read())
for i=1,base do
    for i=1,base do
	  
	    turtle.placeDown()
	    function selectNextSlot()
    while turtle.getItemCount(sslot) == 0 and sslot = 0 do
	    sslot = sslot+1
    end
    turtle.select(sslot)
return turtle.getItemCount(sslot) end
	    turtle.forward()
    end
    if i%2 ~= 0 then
	    turtle.digDown()
	    turtle.turnRight()
	  
	    turtle.placeDown()
	    turtle.forward()
	  
    end
end
ChunLing #11
Posted 12 January 2013 - 08:53 AM
Ah…not so much.

You've got the function declaration inside of the inner for loop, and then don't call it. So it won't really do anything (Lua will allocate the function, but it's just wasting interpretation/memory since it's never called).

That basically just means that you'll only be placing from the selected slot.

You want to declare functions at the beginning of their intended scope, and make them local.
Pixelmnkey #12
Posted 12 January 2013 - 09:55 AM
Roger that, thanks.
theoriginalbit #13
Posted 12 January 2013 - 11:02 AM
Oops sorry about that, forgot they did that. Could have just clicked the pastebin username and got it all tho.