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

OS bugs

Started by LeotomasMC, 01 July 2014 - 03:25 PM
LeotomasMC #1
Posted 01 July 2014 - 05:25 PM
can someone debug this code
error: bios:338: [string "startup"]:2: '<name>' expected


local input; --input
local 1 = "1"
local 2 = "2"
local 3 = "3"
local 4 = "4"
local 5 = "5"
function clear()
term.clear()
end
clear
print("Leocraft OS 1.0.0")
print("REWRITTEN")
function drawMenu()
clear()
print("1-5")
input = read( )
end
drawMenu()
if input = 1 then
print("Shell")
print("'back' to go back")
shell.run("shell")
elseif input = 2 then
shell.run("reboot")
elseif input = 3 then
shell.run("shutdown")
elseif input = 5 then
shell.run("worm")
elseif input = 4 then
shell.run("adventure")
else
drawMenu()

thanks
Edited on 01 July 2014 - 04:35 PM
NanoBob #2
Posted 01 July 2014 - 05:29 PM
You can not use a number as a variable.

you should do:

number1="1"
etc.

instead of

1="1"
Edited on 01 July 2014 - 03:29 PM
LeotomasMC #3
Posted 01 July 2014 - 05:40 PM
thanks oh ive prereleased this its Leocraft OS in operating systems

error: bios:338: [string "startup"]:28: 'then' expected

please help debug this it will help i did NanoBob's help so change that for now
NanoBob #4
Posted 01 July 2014 - 05:50 PM
Couple things, if you check a something in an if or elseif statement use

if i==1 then

end

not


if i=1 then

end

Also your elseif statement near the end of the file
SpoilerThis one:
if input = 1 then
print("Shell")
print("'back' to go back")
shell.run("shell")
elseif input = 2 then
shell.run("reboot")
elseif input = 3 then
shell.run("shutdown")
elseif input = 5 then
shell.run("worm")
elseif input = 4 then
shell.run("adventure")
else
drawMenu()
Misses an end.
LeotomasMC #5
Posted 01 July 2014 - 05:51 PM
Couple things, if you check a something in an if or elseif statement use

if i==1 then

end

not


if i=1 then

end

Also your elseif statement near the end of the file
SpoilerThis one:
if input = 1 then
print("Shell")
print("'back' to go back")
shell.run("shell")
elseif input = 2 then
shell.run("reboot")
elseif input = 3 then
shell.run("shutdown")
elseif input = 5 then
shell.run("worm")
elseif input = 4 then
shell.run("adventure")
else
drawMenu()
Misses an end.

where do i put the end
NanoBob #6
Posted 01 July 2014 - 05:53 PM
Couple things, if you check a something in an if or elseif statement use

if i==1 then

end

not


if i=1 then

end

Also your elseif statement near the end of the file
SpoilerThis one:
if input = 1 then
print("Shell")
print("'back' to go back")
shell.run("shell")
elseif input = 2 then
shell.run("reboot")
elseif input = 3 then
shell.run("shutdown")
elseif input = 5 then
shell.run("worm")
elseif input = 4 then
shell.run("adventure")
else
drawMenu()
Misses an end.

where do i put the end
You put it at the end of the if statement.


if i==something then
--code
elseif i==somethingElse then
--code
else
--code
end
^ An example of an if statement
LeotomasMC #7
Posted 01 July 2014 - 05:55 PM
thanks

it prints near middle lines
why
NanoBob #8
Posted 01 July 2014 - 05:57 PM
Could you update your code so I can look at it? And please give a better explanation of your problem
LeotomasMC #9
Posted 01 July 2014 - 06:06 PM
pastebin get 56xf1c6x

run above and debug, put on pastebin and give me code please
there you go

thats updated

thanks
Edited on 01 July 2014 - 04:05 PM
NanoBob #10
Posted 01 July 2014 - 06:07 PM
This paste has been removed, and I'm unable to gon ingame so can't debug. just tell me what the problems are and errors you get
LeotomasMC #11
Posted 01 July 2014 - 06:10 PM
that the best i can do

how do i copy in game
LeotomasMC #12
Posted 01 July 2014 - 06:21 PM

local input; --input
local shell = "1"
local reboot = "2"
local shutdown = "3"
local adventure = "4"
local worm = "5"
function clear()
term.clear()
end
clear()
print("Leocraft OS 1.0.0")
print("REWRITTEN")
function drawMenu
clear()
print("1-5")
input = read( )
end
drawMenu()
if input == shell then
print("shell")
print("type 'back' to go back")
shell.run("Shell")--error
elseif input == reboot then
shell.run("reboot")--error
elseif input == shutdown then
shell.run("shutdown")--error
elseif input == worm then
shell.run("worm")--error
elseif input == adventure then
shell.run("adventure")--error
else
drawMenu()
end

errors when i do programs in shell.run("program")
Edited on 01 July 2014 - 04:34 PM
LeotomasMC #13
Posted 01 July 2014 - 06:37 PM
this is in tekkit lite fyi
NanoBob #14
Posted 01 July 2014 - 06:44 PM
you have a capital S in shell.
LeotomasMC #15
Posted 01 July 2014 - 07:28 PM
oh typo i looked in minecraft its correct ignore that
Lyqyd #16
Posted 01 July 2014 - 07:30 PM
You blasted away the shell "API" on line two of the code above. You can't expect it to hold two values at once, so it will either hold "1" (or whatever other value you gave it), or it will hold the table of functions (including the run function you try to call later), but not both at once.
LeotomasMC #17
Posted 01 July 2014 - 07:40 PM
You blasted away the shell "API" on line two of the code above. You can't expect it to hold two values at once, so it will either hold "1" (or whatever other value you gave it), or it will hold the table of functions (including the run function you try to call later), but not both at once.
what do you mean i do not get what you said

its suposed to when you type 1 this.
Quick Shell
Type 'back' to go back
CraftOS 1.5
>_

when 2 restart 3 shutdown 4 run adventure 5 run worm

anyone can help

you can look at prerelase in operating systems/Leocraft OS
LeotomasMC #18
Posted 01 July 2014 - 07:48 PM
fixed: near middle printing
bug: type invalid then again starts blinking again
fixed: nothing works
added: can also type program name to run the error,LOL.
bug: when typeing out the program its invalid
bug: invalid > correct input wont read
Edited on 01 July 2014 - 06:18 PM
NanoBob #19
Posted 01 July 2014 - 07:56 PM
You blasted away the shell "API" on line two of the code above. You can't expect it to hold two values at once, so it will either hold "1" (or whatever other value you gave it), or it will hold the table of functions (including the run function you try to call later), but not both at once.
what do you mean i do not get what you said
In the begining of your proghrams you assign shell to be "1". And by default shell is a table holding certain functions from the shell API, so by defining shell as a string you can no longer use those functions.
LeotomasMC #20
Posted 01 July 2014 - 08:11 PM
ok
LeotomasMC #21
Posted 01 July 2014 - 08:16 PM
bug: wont read if u do an invalid then a correct
theoriginalbit #22
Posted 02 July 2014 - 02:30 AM
have you tried to fix it yourself?

Here in Ask a Pro, the effort people are willing to expend helping you is usually about equal to the effort you are putting in.
Edited on 02 July 2014 - 12:30 AM
LeotomasMC #23
Posted 02 July 2014 - 06:53 PM
yeah

fixed: near middle printing <– fixed on my own w/o help
bug: type invalid then again starts blinking again
fixed: nothing works
added: can also type program name to run the error,LOL.
bug: when typeing out the program its invalid
bug: invalid > correct input wont read
LeotomasMC #24
Posted 03 July 2014 - 12:18 AM
bios:338: [string "startup"]:54: 'end' expected (to close 'function' at line 34)
line 34 is

function readUsersInput()
Obnoxious_Ninja #25
Posted 03 July 2014 - 03:42 AM
You need to close a function with "end" just as you would with an if statement.


function foobar()
  --foo
  --bar
  --baz
end --This is what your're missing

Please read Lua's official website (www.lua.org) for more information, as it seems this thread has become one for people to solve all your problems. Don't get me wrong; I (and I'm sure many others here) enjoy helping people, but as this sub-forum and it's populace has stated many times:
Here in Ask a Pro, the effort people are willing to expend helping you is usually about equal to the effort you are putting in.
Saldor010 #26
Posted 03 July 2014 - 04:02 AM
I'm sorry, but if you know this little about Lua and need this much help, you really shouldn't be writing an Operating System.
Obnoxious_Ninja #27
Posted 03 July 2014 - 04:07 AM
I'm sorry, but if you know this little about Lua and need this much help, you really shouldn't be writing an Operating System.
You have to start somewhere. I'm not saying everyone should start with an OS (especially if they have no previous programming experience), but it's a good way to learn the basics of CC (and by extension Lua), even if the result isn't all that great.
Edited on 03 July 2014 - 02:08 AM
Saldor010 #28
Posted 03 July 2014 - 03:07 PM
I'm sorry, but if you know this little about Lua and need this much help, you really shouldn't be writing an Operating System.
You have to start somewhere. I'm not saying everyone should start with an OS (especially if they have no previous programming experience), but it's a good way to learn the basics of CC (and by extension Lua), even if the result isn't all that great.

Yes, everyone has to start somewhere, but trying to run before you can even crawl is a terrible, terrible idea. I suggest that the OP puts aside his Operating System for now, and works on some more simple programs before he comes back to this.
LeotomasMC #29
Posted 03 July 2014 - 06:17 PM
You need to close a function with "end" just as you would with an if statement.


function foobar()
  --foo
  --bar
  --baz
end --This is what your're missing

Please read Lua's official website (www.lua.org) for more information, as it seems this thread has become one for people to solve all your problems. Don't get me wrong; I (and I'm sure many others here) enjoy helping people, but as this sub-forum and it's populace has stated many times:
Here in Ask a Pro, the effort people are willing to expend helping you is usually about equal to the effort you are putting in.

1. i have tried
2. i have an end

and another im working on this for fun it may an probaly will stop getting updates. so im not working on this 24/7. more like 2/5.

oh and this is not my first program. ive made a movie theatre with computercraft and it works 100%
LeotomasMC #30
Posted 03 July 2014 - 06:25 PM
the thing is, it looks fine to me!
Obnoxious_Ninja #31
Posted 03 July 2014 - 06:35 PM
the thing is, it looks fine to me!
Then can you please post the entire file here?

[Edit]: In <CODE></CODE> tags (replace the "<>" with "[]").
Edited on 03 July 2014 - 04:44 PM
LeotomasMC #32
Posted 03 July 2014 - 07:03 PM

local input; --input
local leo = "1"
local reboot = "2"
local shutdown = "3"
local adventure = "4"
local worm = "5"
function clear()
term.clear()
end
clear()
term.setCursorPos(1,1)
print("Leocraft OS 1.1.0 beta")
print("by Leotomas")
sleep(2)
function drawMenu()

clear()
term.setCursorPos(1,1)
term.setTextColor(colors.lime)
print("1-5") --5 lines after  this are print() then 1. shell etc
term.setTextColor(colors.yellow)
print("Ver  1.1.0")
input = read()
readUsersInput()
end

function readUsersInput()
if input == leo then
print("shell")
shell.run("shell")
else
print("hi")
end

now done!
Edited on 03 July 2014 - 11:36 PM
Lyqyd #33
Posted 03 July 2014 - 07:39 PM
And what is the full text of the error message when you run that exact code?
Obnoxious_Ninja #34
Posted 03 July 2014 - 07:48 PM

local input; --input
local leo = "1"
local reboot = "2"
local shutdown = "3"
local adventure = "4"
local worm = "5"
function clear()
term.clear()
end
clear()
term.setCursorPos(1,1)
print("Leocraft OS 1.1.0 beta")
print("by Leotomas")
sleep(2)
function drawMenu()
clear()
term.setCursorPos(1,1)
term.setTextColor(colors.lime)
print("1-5") --5 lines after  this are print() then 1. shell etc
term.setTextColor(colors.yellow)
print("Ver  1.1.0")
input = read()
readUsersInput()
end

to be completed
You need to end a function before you define a second one. In this case, you make a function called "drawMenu", but you don't end it before you try to make a second one "readUserInput"

I withdraw my statement.
Edited on 03 July 2014 - 08:04 PM
Dog #35
Posted 03 July 2014 - 07:55 PM
He isn't 'making' readUserInput(), he's calling it as if it already exists, but it doesn't exist since it's not defined/created anywhere. In addition to that, there *appears* to be at least one other error in the code that I can see.

I defer to Lyqyd's question.
Lyqyd #36
Posted 03 July 2014 - 09:06 PM
He's also just plain wrong. You can define functions within other functions just fine.
LeotomasMC #37
Posted 04 July 2014 - 01:37 AM
im calling drawMenu() after i make the readUsersInput()

i can do pastebin

c0untQe7
Obnoxious_Ninja #38
Posted 04 July 2014 - 01:56 AM
im calling drawMenu() after i make the readUsersInput()

i can do pastebin

c0untQe7
You are ending the "if" block in readUsersInput(), but not the function itself. It should be this:

function readUsersInput()
  if input == leo then
    print("Quick Shell")
    print("Type 'back' to go back")
    shell.run("shell")
  elseif input == reboot then
    shell.run("reboot") 
  elseif input == shutdown then
    shell.run("shutdown")
  elseif input == worm then
    shell.run("worm") 
  elseif input == adventure then
    shell.run("adventure") 
  else
    drawMenu()
  end --You just had this one originally; this ends the if block
end--This one ends the function

He's also just plain wrong. You can define functions within other functions just fine.
Oh…I don't know what posessed me to believe that. I was aware you could do it in other languages, but it just didn't click then :P/>
LeotomasMC #39
Posted 04 July 2014 - 06:33 PM
works thanks I'm releasing the update now.
installer error: bios:338: [string "install"]:1: unexpected symbol
code is:

1 = shell.run("pastebin get code1 startup") --*code1 is not the code
2 = shell.run("pastebin get code2 os") --*
3 = shell.run("pastebin get code3 back") --*
1
2
3
if 1 == true and 2 == true and 3 == true then
    shell.run("clear")
    print("Success. Now rebooting")
    sleep(2)
    shell.run("reboot")
  else
    print("Failed. Check your internet connection, and try again")
  end

print("oh man i please help")
if help == true then
print("thanks")
else
print("why no help")
end

textutils.slowPrint("LOL")

LOL
Obnoxious_Ninja #40
Posted 04 July 2014 - 06:39 PM
You can't assign numbers as variables.

I'm not certain, but it looks like you're trying to check if you can reach these places before you download stuff.

Try:

if http then
  print("Installing")
  shell.run("pastebin","get", "PASTEBIN LINK", "back")
  shell.run("pastebin","get","LINK","os")
  shell.run("pastebin","get","LINK","startup")
  print("Installed successfully!")
  sleep(1)
  shell.run("startup")
else
  print("HTTP is not enabled.")
end

This was on a phone, so forgive typos.
LeotomasMC #41
Posted 04 July 2014 - 06:41 PM
thanks

help == true