Jump to content




Why is this function not working?


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

#1 AndreWalia

  • Members
  • 294 posts
  • LocationSt.Louis, MO

Posted 17 December 2012 - 10:50 AM

i = 1
fName = ""
fTable = ""
function needAName()
  if fName == fTable[i] then
	return true
  else
	return false
  end
end
function is(fName,fTable)
  for i = 1,#fTable do
	if needAName() and fName == fTable[i] then
	  ball = true
	else
	  ball = false
	end
  end
  if ball == true then
	return true
  else
	return false
  end
end
word = {
  "left",
  "right",
  "up",
  "down",
  "back",
  "front"
}
One = io.read()
if is(One,word) then
  print("correct!")
else
  print(One.." is not a side.")
end
It's not returning an error, The problem is that when i type in left it says left is not a side.
its supposed to check if fName is equal to any value in fTable and if it is then it will return true. But that's not the case I guess.

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 10:56 AM

I think your problem is with the need nameAName() i think it should be something like this

function needAName( index )
  return fName == fTable[ index ]
end

ok can I suggest this:

function isSide(side)
  tSides = rs.getSide() -- this is a call the the redstone api which returns an array of the sides

  for i = 1, #tSides do
	if if not needAName( i ) and tSide[i] == side then
	  return true
  end

  return false
end

one = string.lower( read() )

if isSide(one) then
  print("Correct!)
else
  print(one.." is not a side")
end



#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 11:11 AM

Not sure about this but the problem might lie with the fact that you use i as a variable and in a for loop.

But TheOriginalBit's code should work just fine.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users