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

Variable Insert Troubble

Started by candycool1234, 13 August 2013 - 07:35 PM
candycool1234 #1
Posted 13 August 2013 - 09:36 PM
I have worked a bit on this program and just need it to go and cycle the slot's everytime it empty's and I need to at a variable to turtle.select() the pastebin is http://pastebin.com/FzHpvnfB please help I am aware that it is long and culd be shortened but sadly I am not as good at computercraft as I wish to be :/

could*
Yevano #2
Posted 13 August 2013 - 10:13 PM
Could you better describe what it is you're trying to do? If you want to cycle through the turtle's inventory, replace line 7 (which is incorrect syntax) with
turtle.select(x)
and remove the assignments to i and h. Then, if you need to change the slots, just change the numbers in line 5.

You should have a look at http://www.lua.org/pil/4.3.4.html if you're not quite sure how to use for loops.
candycool1234 #3
Posted 13 August 2013 - 10:59 PM
my program is going to build everytime it run's out of stone in that slot I wish to change to a new inventory slot for more material so yes I do need h and I I just wanna do I = 0 + h and h = 0 + 1 so I will begin as 1 then 2 then 3 then 4 to 9 all I need to do is make the variable be in the select(instead of number the variable) then it will go up each time around
MxHn #4
Posted 13 August 2013 - 11:06 PM
For loop? See syntax on the manual http://www.lua.org/manual/5.2/manual.html#3.3.5
Yevano #5
Posted 13 August 2013 - 11:12 PM
my program is going to build everytime it run's out of stone in that slot I wish to change to a new inventory slot for more material so yes I do need h and I I just wanna do I = 0 + h and h = 0 + 1 so I will begin as 1 then 2 then 3 then 4 to 9 all I need to do is make the variable be in the select(instead of number the variable) then it will go up each time around

Add some punctuation to your post. Not trying to be rude, but all I can gather is that you want to change to a different slot when the turtle runs out of material in the current slot. Am I correct? If so, you'll want to use turtle.getItemCount(slot) to check if there are any items left and then increment some variable and use turtle.select to select the next slot.
candycool1234 #6
Posted 14 August 2013 - 12:19 AM
yes, if I use turtle.getItemCount(I) –I being the variable. if ItemCount == 0 then I + 1 turtle.select(I) now how do I get variable I to be accepted into the command's. happy punctuation. if u complain about spelling of which I am aware sucks. Also this is for pro's not kiddie's but help is accepted all the same as long as it work's.
Yevano #7
Posted 14 August 2013 - 12:32 AM
if ItemCount == 0 then I + 1 turtle.select(I) now how do I get variable I to be accepted into the command's.

Exactly as you've written it here. To pass an argument to a function, you use the form someFunction(someArgument). If you mean that you're getting an error when passing that variable to that function, then supply updated code as well as the error that you get.

Also this is for pro's not kiddie's but help is accepted all the same as long as it work's.

The "Kiddie" title is pertinent to post count, not experience.
LordIkol #8
Posted 14 August 2013 - 04:36 AM
Hi there,

did long time not Code and just a bit spare time at the moment so im not sure if my code is completely correct but maybe it helps you to get the clue.

beside i shortened your code a bit using a function for the repeating stuff.

have fun with it


print("building")
actslot = 1

local function checkslot(sn)
if turtle.getItemCount(sn) == 0  and  actslot < 16 then
  turtle.select(actslot+1)
  actslot = actslot + 1
elseif actslot == 16 then
  print("last slot reached")
end
end
local function placeshit()
  turtle.place()
  turtle.back()
  turtle.place()
  turtle.back()
  turtle.place()
  turtle.back()
  turtle.place()
  turtle.turnRight()
  turtle.place()
  turtle.turnLeft()
  turtle.back()
  turtle.turnRight()
  turtle.forward()
  turtle.place()
  turtle.turnLeft()
  turtle.back()
  turtle.turnLeft()
end

local function moveback(x)
for i=1,x do
  turtle.back()
end
end

for x = 1, 4 do
checkslot(actslot)
  for i = 1,2 do
   placeshit()
   moveback(3)
  end
placeshit()
turtle.up()
	turtle.back()
	turtle.back()
	turtle.back()
end

Edit:
just recognized that a while loop would be better for the checkslot function just use it like this to make shure the next slot is not empty too


local function checkslot(sn)
while turtle.getItemCount(sn) == 0  and  actslot < 16 do
  turtle.select(actslot+1)
  actslot = actslot + 1
end
end

Greets
Loki
Edited on 14 August 2013 - 02:42 AM