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

What is wrong with this code?

Started by AndreWalia, 19 November 2012 - 12:24 PM
AndreWalia #1
Posted 19 November 2012 - 01:24 PM
I have looked over it a TON and i don't see why it isn't working, its supposed to install my OS that I'm currently making. but that's not what happens. By the way the code your about to see is in disk/install.


code:

installing = 0.2
toprograms = "qxxdvX98"
variables = "GGj4taRD"
about = "JRNvCN2v"
checkVersion = "uZ2J4w7z"
edit = "P64PEtHd"
perry = "reT5iT41"
startup = "xwZ8CK0T"
local function installed()
  if fs.exists("black/variables") then
    return true
  else
    return false
  end
end
local function put(AeO,location)
  shell.run("pastebin","get",Ae0,location)
 
end
if installed() then
  print("Black OS is already installed!")
  print("if you want to update Black OS then")
  print("when this screen dissapers type in update")
elseif not installed() then
  shell.run("mkdir","Black")
  put(toprograms,"Black/toprograms")
  put(variables,"Black/variables")
  put(startup,"startup")
  put(perry,"perry")
  put(edit,"edit")
  put(about,"about")
  put(checkVersion,"checkVersion")
  if fs.exists("about") then
    print("Installation succesful =D Congrats!")
  else
    print("Installation un-succesful :(/>/>")
  end
else
  print("Installation un-succesful :(/>/>")
end
 

when I run it it just says the usage of pastebin alot then it says installation un-succesful. Please help me
Grim Reaper #2
Posted 19 November 2012 - 01:28 PM
It may help if you specified the problem. Are you getting an actual interpretation error, or does it appear to be a logic bug?
We can't exactly help you if you can't point us in the direction of your problem.
AndreWalia #3
Posted 19 November 2012 - 01:29 PM
It may help if you specified the problem. Are you getting an actual interpretation error, or does it appear to be a logic bug?
We can't exactly help you if you can't point us in the direction of your problem.
when i run it there is no error. just a logic bug.
Kingdaro #4
Posted 19 November 2012 - 01:39 PM
A couple things. The installed function can be reduced. Also, "black" should probably be capitalized.

local function installed()
  return fs.exists('Black/variables')
end

The main installing chunk, it'll never go down to the "else" at the end, because bools are only either true or false. It could be reduced:

if installed() then
  print("Black OS is already installed!")
  print("if you want to update Black OS then")
  print("when this screen dissapers type in update")
else
  shell.run("mkdir","Black")
  put(toprograms,"Black/toprograms")
  put(variables,"Black/variables")
  put(startup,"startup")
  put(perry,"perry")
  put(edit,"edit")
  put(about,"about")
  put(checkVersion,"checkVersion")
  if fs.exists("about") then
    print("Installation succesful =D Congrats!")
  else
    print("Installation un-succesful :(/>/>/>/>")
  end
end
You could also reduce this even more with tables magic, but that's not really necessary, and your logic here is pretty sound.

Last note, is http enabled?
AndreWalia #5
Posted 19 November 2012 - 01:40 PM
A couple things. The installed function can be reduced. Also, "black" should probably be capitalized.

local function installed()
  return fs.exists('Black/variables')
end

The main installing chunk, it'll never go down to the "else" at the end, because bools are only either true or false. It could be reduced:

if installed() then
  print("Black OS is already installed!")
  print("if you want to update Black OS then")
  print("when this screen dissapers type in update")
else
  shell.run("mkdir","Black")
  put(toprograms,"Black/toprograms")
  put(variables,"Black/variables")
  put(startup,"startup")
  put(perry,"perry")
  put(edit,"edit")
  put(about,"about")
  put(checkVersion,"checkVersion")
  if fs.exists("about") then
	print("Installation succesful =D Congrats!")
  else
	print("Installation un-succesful :(/>/>/>/>/>")
  end
end
You could also reduce this even more with tables magic, but that's not really necessary, and your logic here is pretty sound.

Last note, is http enabled?
yes
Grim Reaper #6
Posted 19 November 2012 - 01:45 PM
What exactly isn't happening properly?
AndreWalia #7
Posted 19 November 2012 - 01:50 PM
What exactly isn't happening properly?
When i type in list on the computer After the installation nothing new is there accept for Black the directory, and nothing is in that.

A couple things. The installed function can be reduced. Also, "black" should probably be capitalized.

local function installed()
  return fs.exists('Black/variables')
end

The main installing chunk, it'll never go down to the "else" at the end, because bools are only either true or false. It could be reduced:

if installed() then
  print("Black OS is already installed!")
  print("if you want to update Black OS then")
  print("when this screen dissapers type in update")
else
  shell.run("mkdir","Black")
  put(toprograms,"Black/toprograms")
  put(variables,"Black/variables")
  put(startup,"startup")
  put(perry,"perry")
  put(edit,"edit")
  put(about,"about")
  put(checkVersion,"checkVersion")
  if fs.exists("about") then
	print("Installation succesful =D Congrats!")
  else
	print("Installation un-succesful :(/>/>/>/>/>")
  end
end
You could also reduce this even more with tables magic, but that's not really necessary, and your logic here is pretty sound.

Last note, is http enabled?
I tried that and it doesnt work either
Kingdaro #8
Posted 19 November 2012 - 01:51 PM
What exactly isn't happening properly?
My guess is that his files aren't being downloaded. Either that, or they are being downloaded, and the program is saying they aren't.

walia6, do a ls on the command line and see what's there.


Ninja'd yet again.
AndreWalia #9
Posted 19 November 2012 - 01:54 PM
What exactly isn't happening properly?
My guess is that his files aren't being downloaded. Either that, or they are being downloaded, and the program is saying they aren't.

walia6, do a ls on the command line and see what's there.


Ninja'd yet again.
What does Ninja'd yet again mean?
Grim Reaper #10
Posted 19 November 2012 - 01:55 PM
No idea. But what appears to be the problem, walia6?
AndreWalia #11
Posted 19 November 2012 - 01:57 PM
Just test it out for yourself YOU WILL SEE. Ive answered that once before

No idea. But what appears to be the problem, walia6?

It is not installing my os!
Grim Reaper #12
Posted 19 November 2012 - 02:02 PM
That sure is helpful. Which of the files is not being downloaded properly?
AndreWalia #13
Posted 19 November 2012 - 02:04 PM
That sure is helpful. Which of the files is not being downloaded properly?
ALL of them are not downloading properly
Kingdaro #14
Posted 19 November 2012 - 02:11 PM
Perhaps, instead of using a shell.run on pastebin, you should probably do an http.request on your files and write them manually. Here's a rewritten "put" function.

function put(AeO, location)
  http.request('http://pastebin.com/raw.php?i='..AeO)

  while true do
    local ev, url, source = os.pullEvent()

    if ev == 'http_success' then
      local file = fs.open(location, 'w')
      file.write(source.readAll())
      file.close()
      source.close()

      print('Downloaded '..location)
      break
    elseif ev == 'http_failure' then
      print('Failure to download '..location)
      break
    end
  end
end
AndreWalia #15
Posted 19 November 2012 - 02:52 PM
Perhaps, instead of using a shell.run on pastebin, you should probably do an http.request on your files and write them manually. Here's a rewritten "put" function.

function put(AeO, location)
  http.request('http://pastebin.com/raw.php?i='..AeO)

  while true do
	local ev, url, source = os.pullEvent()

	if ev == 'http_success' then
	  local file = fs.open(location, 'w')
	  file.write(source.readAll())
	  file.close()
	  source.close()

	  print('Downloaded '..location)
	  break
	elseif ev == 'http_failure' then
	  print('Failure to download '..location)
	  break
	end
  end
end
You are Awesome. I'll make sure to credit you for the installation on the fourms when im done making it in a few minutes
Kingdaro #16
Posted 19 November 2012 - 03:03 PM
Have you tested it first? I want to make sure I'm not credited for a broken function :(/>/>
AndreWalia #17
Posted 19 November 2012 - 04:14 PM
Have you tested it first? I want to make sure I'm not credited for a broken function :(/>/>
Works! the topic is here :(/>/>