Jump to content




for loop- "in"


  • You cannot reply to this topic
4 replies to this topic

#1 Apfeldstrudel

  • Members
  • 161 posts

Posted 01 June 2013 - 12: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

#2 popdog15

  • Members
  • 82 posts

Posted 01 June 2013 - 12:58 PM

turtle.select(i)


i is not declared anywhere in this.

#3 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 01 June 2013 - 12:59 PM

View Postpopdog15, on 01 June 2013 - 12:58 PM, said:

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


#4 Apfeldstrudel

  • Members
  • 161 posts

Posted 01 June 2013 - 01:14 PM

View PostBubba, on 01 June 2013 - 12:59 PM, said:

View Postpopdog15, on 01 June 2013 - 12:58 PM, said:

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!

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 June 2013 - 06:16 PM

View PostBubba, on 01 June 2013 - 12:59 PM, said:

View Postpopdog15, on 01 June 2013 - 12:58 PM, said:

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? ;)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users