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

bios:338: [string "setshell"]:7: '<name>" expected

Started by Not_Lazy, 18 February 2015 - 08:59 PM
Not_Lazy #1
Posted 18 February 2015 - 09:59 PM
So, im new to this mod, and was trying to make a "fast" script for creating client, and server computers, since i found an odd thing when using middle click on the floppy disks, allowing me to edit the copied floppy disk in the computer and then also editing the original in my inventory(is this a bug?)

I came across this error:
bios:338: [string "setshell"]:7: '<name>" expected

this is my code:

term.clear()
term.setCursorPos(1, 1)
print("Set Shell to Client or Server?")
soc = read()
local startup = io.open("startup", "w")
if soc == client then
  startup:shell.setDir("disk")
  startup:local monitor = peripheral.wrap( "top" )
  startup:term.clear()
  startup:term.setCursorPos(1, 1)
  startup:monitor.setTextColor(colors.blue)
  startup:monitor.write("LazyOS v1.0 Client")
  startup:term.setTextColor(colors.blue)
  startup:print("LazyOS v1.0 Client")
  startup:term.setTextColor(colors.red)
  startup:print("Work in progress!")
elseif soc == server then
  startup:shell.setDir("disk")
  startup:local monitor = peripheral.wrap( "top" )
  startup:term.clear()
  startup:term.setCursorPos(1, 1)
  startup:monitor.setTextColor(colors.orange)
  startup:monitor.write("LazyOS v1.0 Server")
  startup:term.setTextColor(colors.orange)
  startup:print("LazyOS v1.0 Server")
  startup:term.setTextColor(colors.red)
  startup:print("Work in progress!")
else
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.red)
print("Incorrect Choice")
sleep(4)
os.reboot
Lyqyd #2
Posted 18 February 2015 - 11:12 PM
I removed a reply to this thread since it was very much off base.

When using the IO API, you need to use the write function in the handle to write to the file. You can also use block quotes to drastically simplify this process. For instance, you can put the entire file contents in a variable and write it to a file like so:


--# other code that opens the file handle like you already are doing

local contents = [[
monitor.clear()
monitor.setCursorPos(1, 1)
print("example")
]]

startup:write(contents)
startup:close()

As for the disks, the post I removed was correct about them, any disks with the same ID will have the same files.
HPWebcamAble #3
Posted 19 February 2015 - 02:24 AM
i found an odd thing when using middle click on the floppy disks, allowing me to edit the copied floppy disk in the computer and then also editing the original in my inventory(is this a bug?)

In MC, middle click duplicates items, whether you are in an inventory, or looking at a block in the world. It should only work in creative mode.
(Note that in survival, middle clicking a block in the world will bring it to your hand if its in your inventory)

Lyqyd pretty much covered the error so I'll just skip it.
Not_Lazy #4
Posted 20 February 2015 - 10:09 AM
i found an odd thing when using middle click on the floppy disks, allowing me to edit the copied floppy disk in the computer and then also editing the original in my inventory(is this a bug?)

In MC, middle click duplicates items, whether you are in an inventory, or looking at a block in the world. It should only work in creative mode.
(Note that in survival, middle clicking a block in the world will bring it to your hand if its in your inventory)

Lyqyd pretty much covered the error so I'll just skip it.

Yes, I am playing in creative, I'm not a patient person so I really can't play in survival. Heh…

I removed a reply to this thread since it was very much off base.

When using the IO API, you need to use the write function in the handle to write to the file. You can also use block quotes to drastically simplify this process. For instance, you can put the entire file contents in a variable and write it to a file like so:


--# other code that opens the file handle like you already are doing

local contents = [[
monitor.clear()
monitor.setCursorPos(1, 1)
print("example")
]]

startup:write(contents)
startup:close()

As for the disks, the post I removed was correct about them, any disks with the same ID will have the same files.

disks: does this mean that an orange disk that has files on it, will be the same as an orange disk taken from the creative inventory?

code: I'll try that tomorrow, I'm about to go to bed at the time of writing this. Although, your explanation doesn't make sense I'll try to work with it.
Lyqyd #5
Posted 20 February 2015 - 03:55 PM
No, a disk freshly taken from the creative menu should not share an ID with any existing disks. A disk created by cloning an existing disk would share its ID.
HPWebcamAble #6
Posted 20 February 2015 - 05:05 PM
your explanation doesn't make sense I'll try to work with it.

Ok lets see if I can explain

First, I'd bet you have experience in another coding language. Just out of curiosity, what is it?

Second, I don't have any experience with the io API. Can we please switch to the fs api? It is really similar.
*assuming you said 'ok'*

So, with the fs API, first you need to open the file (I think its the same as the io API for this)

local file = fs.open("filename","w") --#'w' is obviously write mode, and 'filename' is the path.

Then you can write stuff in the file:

file.write("hi")
file.write("test")
If you did that, the file would just be 'hitest' because you didn't tell it to go to a new line.
To do that, use the new line thing (cant remember name): \n

So then this:

file.write("hi\n")
file.write("test")
Would put 'hi' and 'test' on two lines

You can also use multi-line strings with brackets: [[]]

file.write([[
hi
test
]])
This will also put 'hi' and 'test' on two lines.
In this case, you don't need the \n, because it pretty much just copies what you write.

Finally, you need to save and close the file.

file.close()
You can use 'file.flush()' to save it too, but that won't close it, so you can continue to add to the file.

Sorry if this is long, but hopefully it helped!
Not_Lazy #7
Posted 21 February 2015 - 05:52 AM
your explanation doesn't make sense I'll try to work with it.

Ok lets see if I can explain

First, I'd bet you have experience in another coding language. Just out of curiosity, what is it?

Second, I don't have any experience with the io API. Can we please switch to the fs api? It is really similar.
*assuming you said 'ok'*

So, with the fs API, first you need to open the file (I think its the same as the io API for this)

local file = fs.open("filename","w") --#'w' is obviously write mode, and 'filename' is the path.

Then you can write stuff in the file:

file.write("hi")
file.write("test")
If you did that, the file would just be 'hitest' because you didn't tell it to go to a new line.
To do that, use the new line thing (cant remember name): \n

So then this:

file.write("hi\n")
file.write("test")
Would put 'hi' and 'test' on two lines

You can also use multi-line strings with brackets: [[]]

file.write([[
hi
test
]])
This will also put 'hi' and 'test' on two lines.
In this case, you don't need the \n, because it pretty much just copies what you write.

Finally, you need to save and close the file.

file.close()
You can use 'file.flush()' to save it too, but that won't close it, so you can continue to add to the file.

Sorry if this is long, but hopefully it helped!

so, would this code work? (i cant test it right now :s)


term.clear()
term.setCursorPos(1, 1)
print("Set Shell to Client or Server?")
soc = read()
local startup = fs.open("startup", "w")
if soc == client then
fs.write("shell.setDir("disk")\n")
fs.write("local monitor = peripheral.wrap( "top" )\n")
fs.write("term.clear()\n")
fs.write("term.setCursorPos(1, 1)\n")
fs.write("monitor.setTextColor(colors.blue)\n")
fs.write("monitor.write("LazyOS v1.0 Client")\n")
fs.write("term.setTextColor(colors.blue)\n")
fs.write("print("LazyOS v1.0 Client")\n")
fs.write("term.setTextColor(colors.red)\n")
fs.write("print("Work in progress!")")
elseif soc == server then\n")
fs.write("shell.setDir("disk")\n")
fs.write("local monitor = peripheral.wrap( "top" )\n")
fs.write("term.clear()\n")
fs.write("term.setCursorPos(1, 1)\n")
fs.write("monitor.setTextColor(colors.orange)\n")
fs.write("monitor.write("LazyOS v1.0 Server")\n")
fs.write("term.setTextColor(colors.orange)\n")
fs.write("print("LazyOS v1.0 Server")\n")
fs.write("term.setTextColor(colors.red)\n")
fs.write("print("Work in progress!")")
else
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.red)
print("Incorrect Choice")
sleep(4)
os.reboot
HPWebcamAble #8
Posted 21 February 2015 - 06:57 AM
so, would this code work? (i cant test it right now :s)

There are a few typos, but the theory is good.

Also, since you are writing so many lines, you should use the mulit-line string:
(And I commented where the typos are)

term.clear()
term.setCursorPos(1, 1)
print("Set Shell to Client or Server?")
soc = read()
local startup = fs.open("startup", "w")
if soc == "client" then --# 'client' needs quotes around it, since it should be a string
  startup.write([[ --# 'fs' should be 'startup', thats the variable you used
  shell.setDir("disk")
  local monitor = peripheral.wrap( "top" )
  term.clear()
  term.setCursorPos(1, 1)
  monitor.setTextColor(colors.blue)
  monitor.write("LazyOS v1.0 Client")
  term.setTextColor(colors.blue)
  print("LazyOS v1.0 Client")
  term.setTextColor(colors.red)
  print("Work in progress!")
  ]])
  startup.close() --#REMEMBER to close your files! If you don't, java keeps the file on your actual computer read-only
elseif soc == "server" then --# Again, 'server' should have quotes
  startup.write([[ --# Changed 'fs' to 'startup' again
  shell.setDir("disk")
  local monitor = peripheral.wrap( "top" )
  term.clear()
  term.setCursorPos(1, 1)
  monitor.setTextColor(colors.orange)
  monitor.write("LazyOS v1.0 Server")
  term.setTextColor(colors.orange)
   print("LazyOS v1.0 Server")
  term.setTextColor(colors.red)
  print("Work in progress!")
  ]])
  startup.close() --#Added close
else
  term.clear()
  term.setCursorPos(1, 1)
  term.setTextColor(colors.red)
  print("Incorrect Choice")
  sleep(4)
  os.reboot() --#Was missing ()
end --#end was missing too

That should work

PS use [.code] and [./code] tags (Without the period)
Edited on 21 February 2015 - 04:24 PM
Not_Lazy #9
Posted 21 February 2015 - 12:50 PM
so, would this code work? (i cant test it right now :s)

There are a few typos, but in the theory is good.

Also, since you are writing so many lines, you should use the mulit-line string:
(And I commented where the typos are)

term.clear()
term.setCursorPos(1, 1)
print("Set Shell to Client or Server?")
soc = read()
local startup = fs.open("startup", "w")
if soc == "client" then --# 'client' needs quotes around it, since it should be a string
  startup.write([[ --# 'fs' should be 'startup', thats the variable you used
  shell.setDir("disk")
  local monitor = peripheral.wrap( "top" )
  term.clear()
  term.setCursorPos(1, 1)
  monitor.setTextColor(colors.blue)
  monitor.write("LazyOS v1.0 Client")
  term.setTextColor(colors.blue)
  print("LazyOS v1.0 Client")
  term.setTextColor(colors.red)
  print("Work in progress!")
  ]])
  startup.close() --#REMEMBER to close your files! If you don't, java keeps the file on your actual computer read-only
elseif soc == "server" then --# Again, 'server' should have quotes
  startup.write([[ --# Changed 'fs' to 'startup' again
  shell.setDir("disk")
  local monitor = peripheral.wrap( "top" )
  term.clear()
  term.setCursorPos(1, 1)
  monitor.setTextColor(colors.orange)
  monitor.write("LazyOS v1.0 Server")
  term.setTextColor(colors.orange)
   print("LazyOS v1.0 Server")
  term.setTextColor(colors.red)
  print("Work in progress!")
  ]])
  startup.close() --#Added close
else
  term.clear()
  term.setCursorPos(1, 1)
  term.setTextColor(colors.red)
  print("Incorrect Choice")
  sleep(4)
  os.reboot() --#Was missing ()
end --#end was missing too

That should work

PS use [.code] and [./code] tags (Without the period)

Ok, thank you very much!

also i know about the code thing, i just forgot about it, was kinda in a rush at the time so i just made quick edits to the code and ctrl+v'd it over here and posted.

Since i'm on my business computer, i'll just send that over to my gaming computer and test it tomorrow(it's 4am for me :s)
Again though, thank you very much, i wouldn't have been able to figure this out myself, and am totally new to actually coding in lua (is this a modified lua just out of curiosity?). the only lua-ish coding i've done was with gmod addons, and that was mainly just configuring stuff(but required some coding.) also, since you asked, i have experience in HTML and batch. well… im good at it, but i have experience in HTML, Lua, C#, Java(very minimal experience, i gave up quickly), Powershell(also gave up pretty quickly), VBScript(been using this for anything batch can't do) and Batch. when i came to learning batch, i taught myself using the built in help things (like "call /?") and with HTML i taught myself using basic web pages and the inspector. everything else I've needed online support.

EDIT2: removed my previous EDIT as i realized what i asked in it was actually put there by me
Edited on 21 February 2015 - 11:53 AM
HPWebcamAble #10
Posted 21 February 2015 - 05:34 PM
(is this a modified lua just out of curiosity?).

It uses Lua 5.1, which might be a bit behind the current version. It also has tons of custom API's (term, shell, and os just to name a few. Some,
like term.write(), use java to actually display things)
There are a few functions that were removed for security reasons. I'm sure you could find a list somewhere
Other than that its just Lua

Good luck with the program :)/>
MKlegoman357 #11
Posted 21 February 2015 - 06:18 PM
You can find all of the CC's APIs on the wiki.