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

[Lua][Error] Just started lua coding and having problems with if statements

Started by Raiken94, 31 December 2012 - 09:52 AM
Raiken94 #1
Posted 31 December 2012 - 10:52 AM
I can't figure out why I keep getting "bios:388: [string "digIt"]:5: 'then' expected" in this code, even though there is a 'then' in the code
I just started Lua, so go easy on me if its a stupid question

while true do
print("Enter the direction")
d = read()
if d = "u" then
print("Go Up")
elseif d = "d" then
print("Go Down")
elseif d = "f" then
print("Go Forward")
elseif d = "r" then
print("Go Right")
elseif d = "b" then
print("Go Back")
elseif d = "l" then
print("Go Left")
elseif d = "n" then
print("Shutdown")
break
else
print("Please enter correct direction")
end
By the way I know this code doesn't do anything except print text right now, I will be adding the moving and digging commands later on, after I figure out how to get the the if statements working.
Kingdaro #2
Posted 31 December 2012 - 11:05 AM
The comparison symbol for equality is "==", not "=". In other words, this line


if d = "u" then

should be this:


if d == "u" then

which applies to all other subsequent lines.
Raiken94 #3
Posted 31 December 2012 - 11:11 AM
…I'm an idiot -_-/>

Thanks for the quick reply :lol:/>
Kingdaro #4
Posted 31 December 2012 - 12:19 PM
Nah, you're not an idiot. It's a common mistake even the pros make :lol:/>
Tsa6 #5
Posted 01 January 2013 - 01:46 PM
I get the feeling I'm even noobier than you at this, so can you tell me why you need that break?
ChunLing #6
Posted 01 January 2013 - 01:53 PM
It's to escape the loop.

Given that, a repeat … until d == "n" structure would be more appropriate.