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

If And Eof Error Loop When Iterating With For

Started by figgycity50, 28 October 2013 - 04:34 AM
figgycity50 #1
Posted 28 October 2013 - 05:34 AM
I have been developing CASH, the ComputerCraft Advanced Shell. I'm fixing a bug with pastebin, worm and other commands inside subfolders in /rom/programs. I came up with this workaround:

pathEnv = {
'/rom',
'/rom/programs',
'/rom/programs/http',
'/rom/programs/computer',
'/rom/programs/turtle'
}
local function findFile(path)
if fs.exists(dir..path) then
  return true, dir..path
else
for k, v in pairs(pathEnv) do
    if fs.exists(v.."/"..path) then
	   return true, v.."/"..path
    end
	
end
else
  for a,p in pairs(shell.aliases()) do --# is this even a real, and/or iterable function? o.O
   if a == path then
    return true, p
   end
  end
return false
end

But i get this error:

bios:337: [string 'cash.lua']: 43: 'end' expected (to close function at line 31)

Fix it. get this:

bios:337: [string 'cash.lua']: 50: '<eof>' expected

Unfix, get top error, refix, get bottom error. So on and so on.

How do i fix it?
theoriginalbit #2
Posted 28 October 2013 - 05:38 AM
Ok do you know how an if statement works? more importantly do you know how an if else statement works?!

If you don't you need to stop all the projects you're doing immediately and go learn some Lua, we are not here to spoon feed you your answers, this is the third time you've had the same problem, you're clearly not trying to attempt to learn what the problem is and fix it.
figgycity50 #3
Posted 28 October 2013 - 06:01 AM
Ok do you know how an if statement works? more importantly do you know how an if else statement works?!

If you don't you need to stop all the projects you're doing immediately and go learn some Lua, we are not here to spoon feed you your answers, this is the third time you've had the same problem, you're clearly not trying to attempt to learn what the problem is and fix it.

i found out. if statements can only have 1 else.
now i fixed it but everything apart from ls comes up with unknown command. i think i screwed up the alias code.
EDIT= its not everything but ls it's everything in pathEnv folders that isn't an alias
theoriginalbit #4
Posted 28 October 2013 - 06:07 AM
Yeh just start from the basics, write out the steps you wish it to perform and which order and then start to form the logic.
MudkipTheEpic #5
Posted 28 October 2013 - 08:57 AM
Replace the second else with an end. If the else block is true, it will exit the function, so you don't even need the second else.
theoriginalbit #6
Posted 28 October 2013 - 09:03 AM
Replace the second else with an end. If the else block is true, it will exit the function, so you don't even need the second else.
Incorrect. that would leave 1 too many `end`s… you would remove the else keyword instead of replacing it.
MudkipTheEpic #7
Posted 28 October 2013 - 09:04 AM
Replace the second else with an end. If the else block is true, it will exit the function, so you don't even need the second else.
Incorrect. that would leave 1 too many `end`s… you would remove the else keyword instead of replacing it.

The last end is for the function.
theoriginalbit #8
Posted 28 October 2013 - 09:10 AM
The last end is for the function.
I know, I wrote the function for him… But if you replace the second else with an end you'll have one too many, resulting in a EOF error. In any case he's fixed the problem related to that portion of the code, its just bad logic now, which has nothing to do with the extra else.