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

for loop- "in"

Started by Apfeldstrudel, 01 June 2013 - 11:55 AM
Apfeldstrudel #1
Posted 01 June 2013 - 01:55 PM
Hi! i have written a turtle program and while improving it i got the following error :'in expexted' in this function:

function drop(fslot,lslot)
for fslot,lslot do
  turtle.select(i)
  while turtle.drop() == false and turtle.getItemCount(fslot) ~= 0 do
   print("Can't drop items- full?")
  end
end
end
Any ideas? Thanks
popdog15 #2
Posted 01 June 2013 - 01:58 PM
turtle.select(i)


i is not declared anywhere in this.
Bubba #3
Posted 01 June 2013 - 01:59 PM
turtle.select(i)


i is not declared anywhere in this.

You didn't even read the error did you?

———-

@op: You really should provide the whole code.

As for your issue, you are using an invalid for loop.

A for loop can be written in one of two ways:
1) for i=1, 100 do
2) for a, b in iterator(stuff) do

You are using neither. My guess is that you are trying to do the former. If so, try this instead:

function drop(fslot,lslot)
  for i=fslot,lslot do --# It looks like you just forgot to set i=fslot
    turtle.select(i)
    while turtle.drop() == false and turtle.getItemCount(i) ~= 0 do
    print("Can't drop items- full?")
    end
  end
end
Apfeldstrudel #4
Posted 01 June 2013 - 02:14 PM
turtle.select(i)


i is not declared anywhere in this.

You didn't even read the error did you?

———-

@op: You really should provide the whole code.

As for your issue, you are using an invalid for loop.

A for loop can be written in one of two ways:
1) for i=1, 100 do
2) for a, b in iterator(stuff) do

You are using neither. My guess is that you are trying to do the former. If so, try this instead:

function drop(fslot,lslot)
  for i=fslot,lslot do --# It looks like you just forgot to set i=fslot
	turtle.select(i)
	while turtle.drop() == false and turtle.getItemCount(i) ~= 0 do
	print("Can't drop items- full?")
	end
  end
end

Oh! i thought that i could just use another variable for that, Thanks!
Bomb Bloke #5
Posted 01 June 2013 - 07:16 PM
i is not declared anywhere in this.

You didn't even read the error did you?
Given that your suggested fix is to declare i, I think it's pretty clear that he did read it, yes? ;)/>