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

Smartshop Something Doesn't Get Read :s

Started by plazter, 10 October 2013 - 07:46 AM
plazter #1
Posted 10 October 2013 - 09:46 AM
Hello Pro's! :)/>

im makeing a turtle aka computer shop, right now at the moment im working on the turtle only, and it kinda works sometimes.. but mostly not ..

i was hopeing you could tell me my error here :P/>

link: http://pastebin.com/N2ZYCeLs

Spoiler

rednet.open("right")
local item = turtle.getItemCount(1)
local comp = turtle.compareTo(16)

function ok()
local id, msg = rednet.receive()
 if id == 177 then
  if msg == "ok" then
   turtle.select(1)
   run()
  end
 end
end

function run()
  turtle.suckDown()
   if comp == true then
    if item < 32 then
     print("lower")
     turtle.dropDown()
    elseif item > 32 then
     print("over")
     turtle.transferTo(2,32)
      turtle.dropDown()
     turtle.select(2)
     turtle.dropUp()
    elseif item == 32 then
     print("equal")
     turtle.dropUp()
    end
   else
  print("Error Wrong item.")
  turtle.dropDown()
end
  end

run()
while true do
ok()
sleep(1)
end

The error is that, it keeps saying "Error Wrong item." and, the item is gold and it should return true :S and execute one of the actions,
could you help me, then i will appreciate it alot!, thanks in advance!
Regards Plazter
LBPHacker #2
Posted 10 October 2013 - 09:50 AM
Based on the way your program acts, it's obvious that comp is false. That brings up two questions:
  • Which slot of your turtle is selected when you run this program and what's in it?
  • What's in slot #16?
plazter #3
Posted 10 October 2013 - 09:53 AM
Based on the way your program acts, it's obvious that comp is false. That brings up two questions:
  • Which slot of your turtle is selected when you run this program and what's in it?
  • What's in slot #16?

Slot 1 is selected when it boots up, and when it receives the "ok" then it selects slots 1 again to be safe.
- slot 16 is a gold ingot
and it pulls up gold ingots :P/>
LBPHacker #4
Posted 10 October 2013 - 09:59 AM
and it pulls up gold ingots :P/>
Aha… Thing is, the first slot is checked only once - and that's when the turtle boots up, when it sopposedly has no gold in its first slot. If that's the case, put the slot-checking part into run.
plazter #5
Posted 10 October 2013 - 10:04 AM
and it pulls up gold ingots :P/>
Aha… Thing is, the first slot is checked only once - and that's when the turtle boots up, when it sopposedly has no gold in its first slot. If that's the case, put the slot-checking part into run.


function run()
 turtle.suckDown()
  if comp == true then

its being run every time it has received the message "ok" in the ok() function oO

- Not sure what you mean tho :/
LBPHacker #6
Posted 10 October 2013 - 10:06 AM
Try
if turtle.compareTo(16) then
instead of
if comp == true then
Believe me; in the original code, you call turtle.compareTo only once.
plazter #7
Posted 10 October 2013 - 10:09 AM
Hmm… That made it go on to equal and not the above :/ damn it .. i had it yesterday in a much more messy code and now i lost it so i cant even go back and check xD Damn me!

EDIT: I figured it out, i had to type it insted of makeing a shortcut Sorry
immibis #8
Posted 10 October 2013 - 05:35 PM

function run()
 turtle.suckDown()
  if comp == true then

its being run every time it has received the message "ok" in the ok() function oO

But this part:

local comp = turtle.compareTo(16)
is being run only once, at the start.