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

[LUA][Error] Setting Points

Started by Ridous, 29 October 2012 - 01:41 PM
Ridous #1
Posted 29 October 2012 - 02:41 PM
I'm having trouble getting this program to work. It keeps giving me an error
'then' expected on line 14, it's there and it just won't run.

Spoiler


tBoard1={" ";" ";" ";" ";" ";}
tBoard2={" ";" ";" ";" ";" ";}
tHeader={1;2;3;4;5;}
sSColumn=0
sSRow=0
sGColumn=0
sGrow=0
print([[ Enter starting point by typing in the column number first. ]])
sSColumn=read()
if tonumber(sSColumn) = nil then
print([[You entered an invaild column number.]])
else

  while true do
  
  print([[now enter the row number.]])
  sSRow=[read()]
  
   if tonumber(sSRow) = nil then --right here
   print([[you entered an invaild row number. try again.]])
   end
  break
end
end  
print([[ Enter goal point by typing in the column number first. ]])
sGColumn=read()
if tonumber(sGColumn) = nil then

print([[You entered an invaild column number.]])

else

  while true do
  
  print([[now enter the row number.]])
  sGRow=[read()]
  
   if tonumber(sGRow) = nil then
   print([[you entered an invaild row number. try again.]])
   end
  break
end
end
if sSColumn=sGColumn or sSRow=sGRow then
print([[Error]])
restart()
end
if sSRow = 1 then
tBoard1[sSColumn] = "S"
else
tBoard2[sSColumn] = "S"
end
if sGRow = 1 then
tBoard1[sGColumn] = "G"
else
tBoard2[sGColumn] = "G"
end
print(tHeader)
print(tBoard1)
print(tBoard2)

Khento #2
Posted 29 October 2012 - 02:48 PM
Instead of
if tonumber(sSColumn) = nil then

It's supposed to be
if tonumber(sSColumn) == nil then

This applies to every if.
Lyqyd #3
Posted 29 October 2012 - 02:50 PM
Not sure what change the above poster was suggesting. All equality comparisons need the symbol ==, not just =.
Ridous #4
Posted 29 October 2012 - 03:06 PM
Now I'm having trouble making the tables to display

I tried using (" ") (, ,) (' ') ( ) ([ ])(… …) (.. ..) and I'm getting error on line 68 for unexpected symbol
Lyqyd #5
Posted 29 October 2012 - 04:41 PM
You can't just tell it to print the table. You either have to use one of the table functions to concatenate the table into a single string or you have to print individual values from it.
remiX #6
Posted 29 October 2012 - 05:17 PM
Yeah, you will have to use a for loop to display what is in the table


table = {"This","table","is","being","printed"}
for i=1,#table do
  print(table[i])
end

Result:
SpoilerThis
table
is
being
printed

Or to make it into one line


table = {"This","table","is","being","printed"}
for i=1,#table do
  write(table[i].." ")
end

Result:
SpoilerThis table is being printed
Ridous #7
Posted 29 October 2012 - 05:26 PM
Yeah, you will have to use a for loop to display what is in the table


table = {"This","table","is","being","printed"}
for i=1,#table do
  print(table[i])
end

Result:
SpoilerThis
table
is
being
printed

Or to make it into one line


table = {"This","table","is","being","printed"}
for i=1,#table do
  write(table[i].." ")
end

Result:
SpoilerThis table is being printed

Thanks! I was looking that up awhile ago :P/>/>