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

"=" Expected At Line 5 Issue, There Is One There!

Started by Birdgeek3, 16 August 2013 - 02:14 PM
Birdgeek3 #1
Posted 16 August 2013 - 04:14 PM
Title: "=" expected at line 5 issue, There is one there!

Hey I am writing a turtle program that will dig a variable sized room. It says that at line 5 I need an = sign when I have one there. Could someone check over my code and see what's giving that error?

-- Variable Box by Bird V0.1
-- Vars
local tArgs = {...}
local length = tonumber tArgs[1]
local width = tonumber tArgs[2]
local height = tonumber tArgs[3]
local isDone = false
local x = 0
local y = 0
local z = 0
local answer

-- Functions
function tfuel(amount)
if turtle.getFuelLevel() < 5 then
  turtle.select(16)
  turtle.refuel(amount)
  turtle.select(1)
end
end
function turnAround()
  turtle.turnRight()
  turtle.turnRight()
end
function digUp()
  repeat
	tfuel(1)
	turtle.digUp()
	turtle.up()
	y = y + 1
  until y == height
  repeat
	tfuel(1)
	turtle.down()
	y = y - 1
  until y == 0
end
function dig()
  while isDone == false do
	if z ~= width then
	  repeat
		digUp()
		turtle.forward()
		x = x + 1
	  until x == length
	  x = 0
	  turnAround()
	  repeat
		tfuel(1)
		turtle.forward()
		x = x + 1
	  until x == length
	  x = 0
	  turtle.turnLeft()
	  turtle.dig()
	  turtle.forward()
	  turtle.turnLeft()
	  z = z + 1
	else
	  isDone = true
	end
  end
end

  --Main Script
textutils.slowPrint("This will dig a room length x width x height")
textutils.slowPrint("First number = length, second = width, third = height")
textutils.slowPrint("You want a room")
print(length)
textutils.slowPrint("by")
print(width)
textutils.slowPrint("by")
print(height)
textutils.slowPrint("hit enter to confirm")
local sEvent, param = os.pullEvent("key")
if sEvent == "key" then
  if param == 28 then
	dig()
  end
end  
svdragster #2
Posted 16 August 2013 - 04:27 PM
shouldn't it be

local length = tonumber(tArgs[1])
local width = tonumber(tArgs[2])
local height = tonumber(tArgs[3])

Also why is there this

local answer
?

:P/>
LeB0ucEtMistere #3
Posted 16 August 2013 - 04:33 PM
yes it comes from the missing brackets in the 3 previous lines.
in a lot of situations, errors come from the previous line but are only detected one line later, because of the syntax of lua which isn't line restricted (like C with ; for example)
Birdgeek3 #4
Posted 16 August 2013 - 04:38 PM
shouldn't it be

local length = tonumber( tArgs[1])
local width = tonumber (tArgs[2])
local height = tonumber (tArgs[3])

Also why is there this

local answer
?

:P/>

Adding the () fixed it, and that was there because I might have used it but never did :P/>
theoriginalbit #5
Posted 16 August 2013 - 04:40 PM
As a point of learning, there is only one time where you don't need to use () for a function call, and that is where you're calling the function with a SINGLE string. Example:


print("This is normal")

print "This works too"