hey, id like a code to check if a disks label is stored in a a table and then to get its location in the table and get the data in that location in a second table and save it to a variable and then eject disk and do shell.run().
if label is in table and more
Started by makerimages, Sep 28 2012 11:13 AM
6 replies to this topic
#1
Posted 28 September 2012 - 11:13 AM
#2
Posted 28 September 2012 - 02:32 PM
Ah, what? Let me see if I can break this down a bit.
You want us (ie the people who are meant to check code, not create it) to make a program that does the following.
Detects a disk (like with os.pullEvent())
Checks that disk's label (I don't know this can actually be done. . . I'm looking into it)
Compares that label to a table, such as user list (if lbl == lblTbl[v])
Run the code stored in the spot in said table at said index (then loadstring(lblTbl[lbl])).
Then ejects the disk (peripheral.wrap(side), disk.eject())
Okay, so I think I have it. Actually, none of this is too hard, you could probably do it yourself with what I've given you and a look at the Lua reference document.
So, some pseudocode to get you started, whereafter you can come back and ask us for advice, bugfixes (assuming you've tried it yourself) and so forth. But, please, do not use the Ask the Pros section for something you don't want to try yourself.
So, go at it. I've given you the really hard code, you just need to figure out the other bits.
You want us (ie the people who are meant to check code, not create it) to make a program that does the following.
Detects a disk (like with os.pullEvent())
Checks that disk's label (I don't know this can actually be done. . . I'm looking into it)
Compares that label to a table, such as user list (if lbl == lblTbl[v])
Run the code stored in the spot in said table at said index (then loadstring(lblTbl[lbl])).
Then ejects the disk (peripheral.wrap(side), disk.eject())
Okay, so I think I have it. Actually, none of this is too hard, you could probably do it yourself with what I've given you and a look at the Lua reference document.
So, some pseudocode to get you started, whereafter you can come back and ask us for advice, bugfixes (assuming you've tried it yourself) and so forth. But, please, do not use the Ask the Pros section for something you don't want to try yourself.
disk = peripheral.wrap(side) while true do pullEvent if a disk is injected get disk''s lbl (literally disk.getLabel(), who knew?) for i, v in pairs(lblTbl) do if the disk''s label (lbl) is v function lblFunc = loadtring(lblTbl[v]) disk.eject() end end end end
So, go at it. I've given you the really hard code, you just need to figure out the other bits.
#3
Posted 28 September 2012 - 03:47 PM
You can use this function to check if contant is in a table:
function table.contains(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end
And to check if a disk is inserted you can just check if the directory DISK exists withfs.exists("disk")
#4
Posted 28 September 2012 - 03:52 PM
I just made a simple script, that will operate like this:
here's the code:
A little bit messy, but it will do the job
• if theres a disk inserted: ↳ • check if the disk got its name in a table ↓ ↳ • copy the programs from the disk ↓ ↳ • eject the disk ↓ ↳ • run its program ↓ • end • endBut the disk must have a folder named program where it got it's program(s), and inside that folder, the file that will be executed must be named startprog.
here's the code:
Spoiler
Also on pastebin: Jw36BFRtA little bit messy, but it will do the job
#5
Posted 29 September 2012 - 08:57 AM
good, but ill have 2 tables and so if the disk label is in t1 i want the data in t2 on the lable`s location in t1 to be read too.
#6
Posted 29 September 2012 - 11:16 AM
makerimages, on 29 September 2012 - 08:57 AM, said:
good, but ill have 2 tables and so if the disk label is in t1 i want the data in t2 on the lable`s location in t1 to be read too.
You really need to make you sentences more understandable!
#7
Posted 29 September 2012 - 11:06 PM
Jag, he's looking for a program that looks for the disk's label in one table, then, if it finds it, uses the index of that label in a second table, then runs that code.
So, something akin to this (supposing you have the label).
Although to be honest, this methods sucks.
So, something akin to this (supposing you have the label).
function runLblProg(dskLbl, tUno, tDos)
for k, v in pairs(tUno) do
if v = diskLbl then
shell.run("DiskProgs/" .. tDos[k])
end
end
end
Although to be honest, this methods sucks.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











