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

Turtle select gets totally wrong slot numbers

Started by Boss Nomad, 15 December 2012 - 09:13 AM
Boss Nomad #1
Posted 15 December 2012 - 10:13 AM
I managed to make turtle miner, but when it needs to drop items it takes slot numbers from some other place. I want it to drop all items in 2-9 slots, but it drops slot 1 too.
OmegaVest #2
Posted 15 December 2012 - 10:18 AM
Can you post your code? We cannot help you if we don't know what is happening to the code itself.
Boss Nomad #3
Posted 15 December 2012 - 11:12 AM
I remade it but i still get same problems. also there was some attempt to call nil at line 57. Slot 1 should have block that will make turtle turn on right place when coming back from mine, but because turtle will drop slot 1 items too it will not turn on next time.

Also i want to ask is there other way than writing code to get it into multiplayer?

local i = 2
while true do
–Mining
local f = 1
repeat
turtle.dig()
turtle.forward()
turtle.digUp()
f = f + 1
until f == 6

–At end of mines
turtle.turnRight()
turtle.turnRight()

–back from mines
turtle.select(1)
repeat
turtle.forward()
until turtle.compare()

–To the station
turtle.turnRight()
local m = 1
repeat
turtle.forward()
m = m + 1
until m == i

–Dropping
turtle.select(2)
turtle.drop()
turtle.select(3)
turtle.drop()
turtle.select(4)
turtle.drop()
turtle.select(5)
turtle.drop()
turtle.select(6)
turtle.drop()
turtle.select(7)
turtle.drop()
turtle.select(8)
turtle.drop()
turtle.select(9)
turtle.drop()

–heading back to mines
turtle.turnRight()
turtle.turnRight()

i = i + 1

local m = 1
repeat
turtle.forward()
m = m + 1
until m == i

turtle.turnRight()
turtle.select(1)
while turtle.compare() do
turtle.turnRight()
turtle.turnRight()
end
end
remiX #4
Posted 15 December 2012 - 12:25 PM
Try and use this code, but I'm not sure If I understood your code correctly but I'm not seeing the reason for it to drop slot 1 too. I'll test it later sometime.

Spoiler
while true do
    --Mining
    for i = 1, 6 do
        turtle.dig()
        turtle.forward()
        turtle.digUp()
    end

    --At end of mines
    turtle.turnRight()
    turtle.turnRight()

    --back from mines
    turtle.select(1)
    repeat
        turtle.forward()
    until turtle.compare()

    --To the station
    turtle.turnRight()
    
    --[[
   	 At this moment you made this occur until m is equal to i.
        m was 1, i is 2 so therefor it only happens once?
    --]]
    turtle.forward()

    turtle.select(16)    -- Just select a blank slot to make sure it doesn't have slot 1 selected
    
    for i = 2, 9 do -- quicker way to drop the stuff from slots 2 to 9
        turtle.select(i)
        turtle.drop()
    end

    --heading back to mines
    turtle.turnRight()
    turtle.turnRight()

    --[[
   	 At this moment you made this occur until m is equal to i.
        m was 1, i is now 3 so therefor it only happens twice?
    --]]
    turtle.forward() turtle.forward()

    turtle.turnRight()
    turtle.select(1)
    while turtle.compare() do
        turtle.turnRight()
        turtle.turnRight()
    end
end

Also i want to ask is there other way than writing code to get it into multiplayer?

Use pastebin :)/> It has to be enabled on the server though.

P.S. it never hurts to use code tags ;)/>

[*code]Your actually code here[*/code] (Without the *)
theoriginalbit #5
Posted 15 December 2012 - 02:13 PM
here is come code, should fix a few bugs, I've done some comments to help you, and also pointed out some potential bugs i can see.
Spoiler


i = 1

while true do
-- Mining
for p = 1, 6 do
turtle.digUp()

while not turtle.forward() do -- while the turtle cant move forward
turtle.dig() -- dig the block
sleep(0.8) -- wait for sand and gravel to fall
end
end

-- At end of mines
turtle.turnRight()
turtle.turnRight()

turtle.select(1)

-- back from mines
while not turtle.compare() do -- while whats infront doesn't match (may cause issues if end actually doesn't, I suggest turtle.detect())
turtle.forward()
sleep(0.1)
end

-- to the station
turtle.turnRight()

for m = 1, i do
turtle.forward()
sleep(0.1)
end

-- dropping
for s = 2, 9 do
turtle.select(s)
turtle.drop()
end

-- head back to mines
turtle.turnRight()
turtle.turnRight()

i = i + 1

for m = 1, i do
turtle.forward()
currently = currently + 1
sleep(0.1)
end

turtle.turnRight()
turtle.select(1)

while turtle.compare() do -- this will cause problem if there is air all around, it will sit there and just spin
turtle.turnRight()
turtle.turnRight()
end
end

if you need any help understanding or just any general questions… just ask :)/>
theoriginalbit #6
Posted 15 December 2012 - 02:17 PM

	turtle.select(16)	-- Just select a blank slot to make sure it doesn't have slot 1 selected

this will actually cause more headaches for him. if you didn't notice he has 9 slots, meaning he is not running CC1.4
using Turtle.select() with a number that is not in the bounds of the slots (i.e. in 1.3 1-9 or 1.4 1-16) i WILL return an error saying that the slot is out of range. In Java it would actually yell at you saying "IndexOutOfBoundsException"
Boss Nomad #7
Posted 15 December 2012 - 09:06 PM
Try and use this code, but I'm not sure If I understood your code correctly but I'm not seeing the reason for it to drop slot 1 too. I'll test it later sometime.

Spoiler
while true do
	--Mining
	for i = 1, 6 do
		turtle.dig()
		turtle.forward()
		turtle.digUp()
	end

	--At end of mines
	turtle.turnRight()
	turtle.turnRight()

	--back from mines
	turtle.select(1)
	repeat
		turtle.forward()
	until turtle.compare()

	--To the station
	turtle.turnRight()
	
	--[[
   	 At this moment you made this occur until m is equal to i.
		m was 1, i is 2 so therefor it only happens once?
	--]]
	turtle.forward()

	turtle.select(16)	-- Just select a blank slot to make sure it doesn't have slot 1 selected
	
	for i = 2, 9 do -- quicker way to drop the stuff from slots 2 to 9
		turtle.select(i)
		turtle.drop()
	end

	--heading back to mines
	turtle.turnRight()
	turtle.turnRight()

	--[[
   	 At this moment you made this occur until m is equal to i.
		m was 1, i is now 3 so therefor it only happens twice?
	--]]
	turtle.forward() turtle.forward()

	turtle.turnRight()
	turtle.select(1)
	while turtle.compare() do
		turtle.turnRight()
		turtle.turnRight()
	end
end

Also i want to ask is there other way than writing code to get it into multiplayer?

Use pastebin :)/> It has to be enabled on the server though.

P.S. it never hurts to use code tags ;)/>

[*code]Your actually code here[*/code] (Without the *)

Its meant to happen once then twice.. etc.


Out of quote: Thanks for ur help. I think turtle.compare change to turtle.detect helped on all problems i had. will try it as soon as possible.


And probadly i dont get headaches if u have done something wrong. My future will be programming so i know how to react to problems :D/>
remiX #8
Posted 15 December 2012 - 09:10 PM
this will actually cause more headaches for him. if you didn't notice he has 9 slots, meaning he is not running CC1.4

Actually didn't think of that ;)/> Thought he was only just using the some slots and not all. :D/>
theoriginalbit #9
Posted 15 December 2012 - 09:14 PM
Out of quote: Thanks for ur help. I think turtle.compare change to turtle.detect helped on all problems i had. will try it as soon as possible.

its good that detect fixed it, i could see issues with compere. also have your fixed the infinite spinning if there is air all around?

this will actually cause more headaches for him. if you didn't notice he has 9 slots, meaning he is not running CC1.4

Actually didn't think of that ;)/> Thought he was only just using the some slots and not all. :D/>

Yeh I at first thought that, its too easy to do when you yourself only use 1.4, but I figured its best not to assume just incase.