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

Program Selector

Started by Silent_Devil, 06 July 2015 - 02:33 AM
Silent_Devil #1
Posted 06 July 2015 - 04:33 AM
I don't know if this is the right area because i'm new to this site but I really need some help with my startup program I am making for my pocket computer

Basically, this program is meant to run a program that the user specifies form the list of available programs but whenever I try to run a program, I just get the message: "bios:365 Expected string,string".

Here is the code:

pastebin get Z8T25RQa

It would mean a lot to get some help in this!

Thank you in advance!

~Silent_Devil

P.S: I'm kind of a n00b at programming, but if you want to see the code for the 2 available programs I'm trying to get this one to run, just ask ;)/>
Cranium #2
Posted 06 July 2015 - 05:25 AM
Moved to Ask a Pro.
Bomb Bloke #3
Posted 06 July 2015 - 07:56 AM
if input == "Door" then
os.run(Door)

elseif

input == "Lift" then
os.run(Lift)

Two points - Lift and "Lift" are not the same, and that's not how you use os.run(). You might be better off using shell.run() instead.
HPWebcamAble #4
Posted 06 July 2015 - 07:58 AM
First thing I'd like to point out is your formatting isn't very good. Which is fine, since you are just getting into programming :)/>
Extra spaces or enters don't change how the code works, but makes it much easier to read

Like this:
Spoiler

function Options()
  print("Which program would you like ot run?")
  term.setCursorPos(1,4)
  print("Programs:")
  term.setCursorPos(1,6)
  print("Door")
  term.setCursorPos(1,8)
  print("Lift")
  term.setCursorPos(11,4)
end

Options()

input = read()

if input == "Door" then
  os.run(Door)
elseif
  input == "Lift" then
  os.run(Lift)  
else
  os.reboot()
end


Now, for the error

Errors like that can be really annoying, since they don't seem to have anything to do with your code
(You can actually look at the bios.lua file to get an idea of what is wrong, if you have to)

In this case, this is your problem:

if input == "Door" then
  os.run(Door)			   --# This line
elseif
  input == "Lift" then
  os.run(Lift)				 --# And this line
else
  os.reboot()
end

Instead of passing a string (In quotes), you pass a variable (No quotes).
Since you never set 'Door' or 'Lift' to anything, you are passing nil, which confuses os.run()

Also, like Bomb Bloke said, you should be using shell.run(), not os.run(). Similar name, very different use.
Edited on 06 July 2015 - 05:59 AM
meigrafd #5
Posted 06 July 2015 - 12:41 PM
I think you currently also dont need the function 'Option()' and instead of quoting somthing in 'shell.run()' you can also use the input Variable

Something like this:

Spoiler

print("Which program would you like ot run?")

term.setCursorPos(1,4)
print("Programs:")

term.setCursorPos(1,6)
print("Door")

term.setCursorPos(1,8)
print("Lift")

term.setCursorPos(11,4)

input = read()

if input == "Door" then
  shell.run(input)
elseif input == "Lift" then
  shell.run(input)  
else
  os.reboot()
end
and btw its case sensitiv
Silent_Devil #6
Posted 06 July 2015 - 01:18 PM
Everyone, thank you for your feedback! I knew I had to use something like os.run() but I couldn't remember the proper name for it! And thank you all for your tips as they have been very useful to me and I will take them all on board! I will try and sort my scripts in a more organized manner. And as for the function I only put that there because it was easier for me to do that ad it works logically for me… But that's just my mindset! :3 once again, thank you everyone for your help and quick responses, it really means a lot to me!