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

Odd End And Eof Error That Loops Errors (sort Of)

Started by figgycity50, 27 October 2013 - 09:56 AM
figgycity50 #1
Posted 27 October 2013 - 10:56 AM
So i was making an alternative shell in computercraft. when I was doing the main logic loop, i made lots of ifs and got lost in them. now cc says this:

bios: 337: [string "dontseethenameofmyprotject.lua"]: 42: 'end' expected (to close 'while' on line 22)
So i fix it, and… another error.

bios: 337: [string "oymandontseeit.lua"]: 43: '<eof>' expected
So i untype the end i get first error, readd it, second error so on, so on.

My code:
Spoiler

print "figgycity50 poject dev-0.1"
--the user know it project, lets load project.
tArgs = {...}
startDir = shell.dir()
configLocation = "/.project/proj.conf"
dir = startDir
if tArgs[0] == "--homeDir" then
homeDir = tArgs[1]
else
homeDir = "/"
end
--all proj vars initialized, let's read from proj.conf.
--lol nothing in this version
--everything initialized, let's have FUN!
while true do
write("root@"..os.computerID().." $ "..dir)
shellCommand = read()
if shellCommand == "exit" then
break
else
if fs.exists(dir..shellCommand) then
shell.run(shellCommand)
else
if fs.exists("/rom/programs/"..shellCommand) then
shell.run("/rom/programs/"..shellCommand)
else
for alias, programName in shell.aliases() do
if alias == shellCommand then
shell.run(programName)
end
end
end
end
end
else
print(shellCommand..": Command not found")
end

How do I fix it?
theoriginalbit #2
Posted 27 October 2013 - 11:11 AM
Indenting is your friend. take a look at this properly indented code and you'll see your mistake.

print "figgycity50 poject dev-0.1"
--the user know it project, lets load project.
tArgs = {...}
startDir = shell.dir()
configLocation = "/.project/proj.conf"
dir = startDir
if tArgs[0] == "--homeDir" then
  homeDir = tArgs[1]
else
  homeDir = "/"
end
--all proj vars initialized, let's read from proj.conf.
--lol nothing in this version
--everything initialized, let's have FUN!
while true do
  write("root@"..os.computerID().." $ "..dir)
  shellCommand = read()
  if shellCommand == "exit" then
    break
  else
    if fs.exists(dir..shellCommand) then
      shell.run(shellCommand)
    else
      if fs.exists("/rom/programs/"..shellCommand) then
        shell.run("/rom/programs/"..shellCommand)
      else
        for alias, programName in shell.aliases() do
          if alias == shellCommand then
            shell.run(programName)
          end
        end
      end
    end
  end
else
  print(shellCommand..": Command not found")
end
figgycity50 #3
Posted 27 October 2013 - 11:20 AM
Indenting is your friend. take a look at this properly indented code and you'll see your mistake.
-ssnip-

i dont see my mistake, also blame notepad++ for its very bad code block highlighting system
theoriginalbit #4
Posted 27 October 2013 - 11:30 AM
i dont see my mistake, also blame notepad++ for its very bad code block highlighting system
You have an else on the while loop. Only if statements can have an else.
figgycity50 #5
Posted 27 October 2013 - 11:47 AM
i dont see my mistake, also blame notepad++ for its very bad code block highlighting system
You have an else on the while loop. Only if statements can have an else.


while true do
  write("root@"..os.computerID().." $ "..dir)
  shellCommand = read()
  if shellCommand == "exit" then
    break
  else
    if fs.exists(dir..shellCommand) then
	  shell.run(shellCommand)
    else
	  if fs.exists("/rom/programs/"..shellCommand) then
	    shell.run("/rom/programs/"..shellCommand)
	  else
	    for alias, programName in shell.aliases() do
		  if alias == shellCommand then
		    shell.run(programName)
		  end
	    end
   else
   print(shellCommand..": Command not found")
    end
  end
end
that's my new code, still error:
39: expected 'end ' to close 'if' on line 28
theoriginalbit #6
Posted 27 October 2013 - 11:54 AM

while true do
  write("root@"..os.computerID().." $ "..dir)
  shellCommand = read()
  if shellCommand == "exit" then
	break
  else
	if fs.exists(dir..shellCommand) then
	  shell.run(shellCommand)
	else
	  if fs.exists("/rom/programs/"..shellCommand) then
		shell.run("/rom/programs/"..shellCommand)
	  else
		for alias, programName in shell.aliases() do
		  if alias == shellCommand then
			shell.run(programName)
		  end
		end
   else
   print(shellCommand..": Command not found")
	end
  end
end
that's my new code, still error:
39: expected 'end ' to close 'if' on line 28
You've still got too many statements there, you've got the following structure

while true do
  if [exit check] then
    break
  else [not exit] then
    --# file existence check
  else [rogue else]
    print("not a valid command")
  end
end
You need to revise how you wish this to work at the basic level, you've just got way too much confusion for yourself in all the if statements and you're adding logic in the wrong spots because of this.
figgycity50 #7
Posted 27 October 2013 - 12:08 PM
-snip-
You've still got too many statements there, you've got the following structure

while true do
  if [exit check] then
	break
  else [not exit] then
	--# file existence check
  else [rogue else]
	print("not a valid command")
  end
end
You need to revise how you wish this to work at the basic level, you've just got way too much confusion for yourself in all the if statements and you're adding logic in the wrong spots because of this.
i still dont get how to fix it
theoriginalbit #8
Posted 27 October 2013 - 12:20 PM
i still dont get how to fix it
*insert face into palm* have you read my signature lately? … this is your one and only free answer from me…

local function findFile(path)
  if fs.exists(dir..path) then
    return true, dir..path
  elseif fs.exists("/rom/programs/"..path) then
    return true, "/rom/programs/"..path
  else
    for a,p in shell.aliases() do --# is this even a real, and/or iterable function? o.O
      if a == path then
        return true, p
      end
    end
  end
  return false
end

while true do
  write("root@"..os.computerID().." $ "..dir)
  local command = read()
  if command == "exit" then
    break
  else
    local exists, path = findFile(command)
    if exists then
      shell.run(path)
    else
      print("Unknown command: "..command)
    end
  end
end
figgycity50 #9
Posted 27 October 2013 - 12:26 PM
i still dont get how to fix it
*insert face into palm* have you read my signature lately? … this is your one and only free answer from me…
–snip–

bit that code does not work! error only appears when there is an invalid command/alias:

prog.lua: 29: attempt to call table

EDIT:never mind, i fixed it myself by using pairs(shell.aliases())
theoriginalbit #10
Posted 27 October 2013 - 12:29 PM
bit that code does not work! error only appears when there is an invalid command/alias:
prog.lua: 29: attempt to call table
You've got a polluted environment, that error I'm going to assume (since like 29 is an `end`) is on the `print` line. You've named a variable somewhere print and its remained in the global table, make sure to disable startup scripts and reboot the computer.