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

[LUA][ERROR]Getting false " 'then' expected " error?

Started by ShinyJijo, 13 January 2013 - 09:22 PM
ShinyJijo #1
Posted 13 January 2013 - 10:22 PM
Ok guys. I am just trying to make a program that will build a cobblestone generator for you but i keep getting errors. What I am trying to do is add an interactive menu but when I start the program I get an error relating to an if-statement I am using to allow the user to select options. Here is the snippet of code causing me problems:

function bMenu()
  local m=1
  k=os.pullEvent()
  term.clear()
  term.setCursorPos(1,1)
  print("Welcome to Shiny's Cobblestone Generator and Miner!")
  print("To begin choose an option:")
  print("")
  print(" >  Build Generator  <")
  print("	 Mine Cobble")
  print("------------------------------")
  os.pullEvent()
  if m=1 and k=28 then	   |	   This statement here is causing me
	cobbleBuild()	   |-----  problems. It keeps telling me
  end			   |	   'then expected' even though the
				   'then' is obviously there.
Anybody know what is happenng?
NOTE: The function has no end because it keeps going past this statement.
crazyguymgd #2
Posted 13 January 2013 - 10:27 PM
m == 1 and k == 28 instead of one =
Andy586 #3
Posted 13 January 2013 - 10:28 PM
First off you need to use == to check an expression.

if m == 1 and k == 28 then

also try both of the following

if (m == 1) and (k == 28) then

if (m == 1 and k == 28) then

Hope that fixes your problem. :)/>
sjele #4
Posted 13 January 2013 - 10:29 PM

function bMenu()
  local m=1
  k=os.pullEvent()
  term.clear()
  term.setCursorPos(1,1)
  print("Welcome to Shiny's Cobblestone Generator and Miner!")
  print("To begin choose an option:")
  print("")
  print(" >  Build Generator  <")
  print("		Mine Cobble")
  print("------------------------------")
  os.pullEvent()
  if m==1 and k==28 then	 |	   This statement here is causing me, (You had single ='s there)
		cobbleBuild()	  |-----  problems. It keeps telling me
  end

== compares, = sets a value


edit: Double ninjaed
remiX #5
Posted 14 January 2013 - 01:00 AM
A single = is for setting variables,
double = is for comparing