Jump to content




select a slot, if full drop it

turtle lua

4 replies to this topic

#1 offroadguy56

  • New Members
  • 3 posts

Posted 09 January 2013 - 09:58 PM

Hello.

Sorry for being such a noob. This is the first time I've messed with computer craft within tekkit.

I know nothing about about Lua except for about 30 minutes worth of tutorials (the basics) on youtube.

I have a turtle that uses my own tunnel code and I want it to check each of it's slots. If the slot is full I want the turtle to throw it out then check the next slot.

in slot 1 I have a stack of torches. placing a torch every 10 blocks is part of the tunnel code.
Ive tested the tunnel code and it all works perfectly. I need help figuring out why my test code for the item dump is not working.
When I get it working I will move it over into the main tunnel code and I'll be a happy camper.

this is what I have:
turtle.select(2)
if turtle.getItemCount(2) = 64 then
  turtle.drop(64)
end
turtle.select(3)
if turtle.getItemCount(3) = 64 then
  turtle.drop(64)
end
turtle.select(4)
if turtle.getItemCount(4) = 64 then
  turtle.drop(64)
end

and this is the error code it gives me:
bios:206: [string "test"]:2: 'then'
expected

I've looked at the turtle API on the wiki. and it seems that everything checks out. but apparently not.

Thanks

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 10:10 PM

the problem is that you have = which is an assignment operator, what you are after is the equality operator which is ==

also I would suggest using a for loop to dump the items, as follows:
for slot = 1, 9 do -- 1 is the starting slot, 9 is the finishing slot, change to whatever as long as its a valid slot ( i.e. CC1.3 is 9 slots, CC1.4 is 16 )
  turtle.select( slot )
  if turtle.getItemCount( slot ) == 64 then
	turtle.drop() -- if no number is supplied it will drop all :)/>/>
  end
end

EDIT: Also I would suggest reading this it is a very helpful resource for learning Lua, as well as reading the CC APIs, and any CC programs that have been developed by someone also help. Even reading through some topics in this section can be a very helpful learning tool...

Edited by TheOriginalBIT, 09 January 2013 - 10:11 PM.


#3 offroadguy56

  • New Members
  • 3 posts

Posted 09 January 2013 - 10:29 PM

Thank you very much.

though I usually put a stack of torches in the first slot.
is there a way I can have the code skip slot 1?

do I put it as
for slot = 2, 9 do


#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 10:38 PM

View Postoffroadguy56, on 09 January 2013 - 10:29 PM, said:

for slot = 2, 9 do

That will work to skip the first slot. Side note If say you want to only skip 4 and 5 then you would do this
for slot = 1, 9 do
  if not ( slot == 4 and slot == 5 ) then
    turtle.select( slot )
    turtle.drop( )
  end
end


#5 offroadguy56

  • New Members
  • 3 posts

Posted 09 January 2013 - 10:56 PM

awesome, thanks a bunch.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users