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

ERROR : Line 5 - 'then' expected near ')'

Started by PieCrafted, 03 August 2015 - 02:29 AM
PieCrafted #1
Posted 03 August 2015 - 04:29 AM
This is my error: ERROR : Line 5 - 'then' expected near ')'

This is a portion of my code, starting at line 4:




local update = http.get("http://pastebin.com/raw.php?i=REDACTED")
if update and update.readAll() ~= version) then
  print("REDACTED Update Found!")
  print("Current Version: " .. version)
  print("Update Version: " .. update)
  print()
  print("Your Computer Will Automatically Update REDACTED in 5 seconds. Please wait.")
  sleep(5)
  update.close()
  shell.run("pastebin get REDACTED startup")
  print("Update Complete. Your Computer Will Reboot in 5 seconds. Please DO NOT Press Any Buttons")
  sleep(5)
  os.reboot()
end

The issue is with this line:

if update and update.readAll() ~= version) then

Can someone help please?
Lyqyd #2
Posted 03 August 2015 - 05:16 AM
Why do you have an extra closing parenthesis on that line?
PieCrafted #3
Posted 03 August 2015 - 05:22 AM
Why do you have an extra closing parenthesis on that line?

Copy-Paste of this:


Don't. That would be my simple answer. If people want to update they will - and you can provide the utilities to do that. However checking and automatically fetching updates is pain in the neck for both developer and user - if a program takes several seconds to load because it needs to access a remote server then they'll just remove the update part.

I'm going to presume you have a pastebin account - that means you can preserve the same pastebin ID every time. Then you can fetch the paste every time you load the program, and if you cannot find it then just load a cached version. Alternatively you could have a separate paste containing the latest version number and, if it doesn't match the current version number, update.


local update = http.get("http://pastebin.com/raw.php?i=<version_paste_id>")
if update and update.readAll() ~= "<current_version>") then
update.close()
shell.run("pastebin get <paste_id> turtleAPI")
end

Lyqyd #4
Posted 03 August 2015 - 06:08 AM
Ah. Well, it's extraneous and is likely what's causing your error.
PieCrafted #5
Posted 03 August 2015 - 06:14 AM
Ah. Well, it's extraneous and is likely what's causing your error.

Okay. I will remove it and see what happens. I figured it looked a little fishy because it was missing an open ( but I just left it.
I will keep you posted.

EDIT: Everything worked perfectly. Thanks a lot for your help <3
Edited on 03 August 2015 - 03:56 PM