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

program terminates because of one line

Started by ChiknNuggets, 04 January 2013 - 03:49 PM
ChiknNuggets #1
Posted 04 January 2013 - 04:49 PM
i got this code

else fs.move(InstallDirectory..input..".temp",InstallDirectory..filelist[slot])term.setBackgroundColor(colors.red);term.setCursorPos(x+2,y+2);write(string.rep(" ",24));term.setCursorPos(x+2,y+2);write("App Name allready Taken");sleep(3) end

only when this parameter is met it seems to terminate, but there is no code and no reason why it should be terminateing, there is no error or anything, thanks in advance
thislooksfun #2
Posted 04 January 2013 - 04:53 PM
Please post the entire code and point out the part that breaks. Also, does it give you an error?
ChunLing #3
Posted 04 January 2013 - 05:59 PM
else
print("Checkpoint1:",InstallDirectory..input..".temp",InstallDirectory..filelist[slot])
  fs.move(InstallDirectory..input..".temp",InstallDirectory..filelist[slot])
print("Checkpoint2:",colors.red)
  term.setBackgroundColor(colors.red)
print("Checkpoint3: ",x+2,y+2)
  term.setCursorPos(x+2,y+2)
print("Checkpoint4: ",string.rep(" ",24))
  write(string.rep(" ",24))
print("Checkpoint5: ",x+2,y+2)
  term.setCursorPos(x+2,y+2)
  write("App Name allready Taken")
  sleep(3)
end
Hey, it's what I do.
ChiknNuggets #4
Posted 04 January 2013 - 06:59 PM
lol nope still doesnt work it goes through it all and does it all, but the problem is that it seems that it terminates the rest of the script its in a while true statement, id post the whole thing but it requires a folder with images in it so i its a bit harder… anyway there is no reason why it should stop if it doesnt run into the file already existing it works fine, but when it does it just exits my program
ChiknNuggets #5
Posted 04 January 2013 - 07:03 PM

if e == "mouse_click" and (p2 >= x + 24 - #button2 and p2 <= x + 25 and p3 == y+3.5) then drawIcons(currenticonnumber,#filelist)
elseif e == "mouse_click" and (p2 >= x + 2 and p2 <= x + 3 + #button1 and p3 == y+3.5) then
  if fs.exists(InstallDirectory..input) then
   fs.move(InstallDirectory..filelist[slot],InstallDirectory..input..".temp")
   if fs.exists(InstallDirectory..input) == false then
    fs.move(InstallDirectory..input..".temp",InstallDirectory..input)
   else fs.move(InstallDirectory..input..".temp",InstallDirectory..filelist[slot])term.setBackgroundColor(colors.red);term.setCursorPos(x+2,y+2);write(string.rep(" ",24));term.setCursorPos(x+2,y+2);write("App Name allready Taken") end
  else fs.move(InstallDirectory..filelist[slot],InstallDirectory..input) end
  if fs.exists(InstallDirectory..filelist[slot]..".ico") and fs.exists(InstallDirectory..input) then fs.move(InstallDirectory..filelist[slot]..".ico", InstallDirectory..input..".ico") end
end
end

this is basically the main section of code thats got to do with the renameing, just doesnt make sense not to be working
ChunLing #6
Posted 05 January 2013 - 03:17 AM
You've got one too many ends there. What are you trying to do?
if e == "mouse_click" and (p2 >= x + 24 - #button2 and p2 <= x + 25 and p3 == y+3.5) then
    drawIcons(currenticonnumber,#filelist)
elseif e == "mouse_click" and (p2 >= x + 2 and p2 <= x + 3 + #button1 and p3 == y+3.5) then
    if fs.exists(InstallDirectory..input) then
        fs.move(InstallDirectory..filelist[slot],InstallDirectory..input..".temp")
        if fs.exists(InstallDirectory..input) == false then
            fs.move(InstallDirectory..input..".temp",InstallDirectory..input)
        else
            fs.move(InstallDirectory..input..".temp",InstallDirectory..filelist[slot])
            term.setBackgroundColor(colors.red)
            term.setCursorPos(x+2,y+2)
            write(string.rep(" ",24))
            term.setCursorPos(x+2,y+2)
            write("App Name allready Taken")
        end
    else
        fs.move(InstallDirectory..filelist[slot],InstallDirectory..input)
    end
    if fs.exists(InstallDirectory..filelist[slot]..".ico") and fs.exists(InstallDirectory..input) then
        fs.move(InstallDirectory..filelist[slot]..".ico", InstallDirectory..input..".ico")
    end
end
end
One of the steps of trying to solve something yourself is to properly indent your code to see if you've made this kind of basic error. It is also one of the steps of making it reasonably possible to help you.
Edited on 05 January 2013 - 02:21 AM
ChiknNuggets #7
Posted 05 January 2013 - 03:39 AM
i do have it all properly indented, infact its like an ocd for me,just when you copy and paste it ddoesnt seem to come across, idk maybe my program that i use to edit code, anyway i dont know what it was that was causing the reason to terminate, but as i was fixing up some dud code(as in was not very logical and could potentially throw errors) it fixed its self, it probably was an extra end that was causing it, but its all fixed now thank you
ChunLing #8
Posted 05 January 2013 - 03:59 AM
The forum only does indentation in code boxes. And I guess it's not like the previous posting out of the code box had the extra end, so that wasn't a big deal.

The thing about Lua is that there are a couple of other identifiers for chunk ends, and while they aren't mixable, loadstring (which the shell uses to run a program) seems to only check if all the chunks end before attempting to execute the function it makes.