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

if stament is not working like expected

Started by Termanater13, 23 December 2012 - 06:28 AM
Termanater13 #1
Posted 23 December 2012 - 07:28 AM
I am working on getting a building program working and for some reason 2 lines are not working as expected. but the rest works fine as expected.
Spoiler

local tArgs = { ... }
if #tArgs < 1 then
print( "house size <straight> <right>" )
return
end
x=tArgs[1]
z=tArgs[2]
print(x)
print(z)
PI.mFw()
for i = 1, z do
for I = 1, x do
  if not PI.pBD() then
   PI.bBD()
   PI.pBD()
  end
  print("I: "..I.." x: "..x)
  if I ~= x then --line 18
   PI.mFw()
  end
end
m = i%2
print("i % 2 = "..m)
print("i: "..i.." z: "..z)
if i ~= z then  --line 25
  if (m) == 1 then
   PI.tR()
   PI.mFw()
   PI.tR()
  else
   PI.tL()
   PI.mFw()
   PI.tL()
  end
end
end
If statmenst on line 18 and 25 are to check if the for loop is at the end and if it is not exicute the lines of code otherwise ignore them if it is at the end. this uses my own turtle movement API, "PI".
API functions used:
  1. PI.mFw() = move Forward
  2. PI.tL() == turn Left
  3. PI.tR() == turn Right
  4. PI.pBD() = place Block Down
  5. PI.bBD() = break Block Down
Lyqyd #2
Posted 23 December 2012 - 07:33 AM
You need to tonumber numerical arguments to compare them correctly:

x = tonumber(args[1])
remiX #3
Posted 23 December 2012 - 07:33 AM
Try changing these two lines:

x=tArgs[1]
z=tArgs[2] 
to

x=tonumber(tArgs[1])
z=tonumber(tArgs[2]) 
Termanater13 #4
Posted 23 December 2012 - 07:38 AM
that fixed it, I never thought of that. I thought if I passed a number it would work as a number not a string.