9 posts
Posted 15 August 2012 - 08:37 PM
so i have been writing a code that first searches the computer's side for any peripheral (this is for smp so no one will have any other type of peripheral other than a disk drive) and then sets the variable g to true and then an if statement to check weather both g and os.exists("startup") == true so then i have it to delete the startup on the computer and then copy the startup from the disk to the computer i'll show you the bit of the code that doesnt work but basically it doesnt copy or do anything that the code written would sudgest it would do and i have tried reloading the saved file and all of the things that would correct it so here it is thanks!:
a = peripheral.isPresent("left")
b = peripheral.isPresent("right")
c = peripheral.isPresent("top")
d = peripheral.isPresent("bottom")
e = peripheral.isPresent("front")
f = peripheral.isPresent("back")
if a == true then
g = true
else
if b == true then
g = true
else
if c == true then
g = true
else
if d == true then
g = true
else
if e == true then
g = true
else
if a == true then
g = true
else
g = false
end
end
end
end
end
end
if g == true and fs.exists("startup") then
fs.delete("startup")
sleep(0.1)
fs.copy("disk/startup","")
else
fs.copy("disk/startup","")
end
if g == true and fs.exists("disk/startup") then
fs.delete("disk/startup")
sleep(0.1)
fs.copy("startup","disk/startup")
else
fs.copy("startup","disk/startup")
end
end
hope you can help my error! thanks
9 posts
Posted 15 August 2012 - 08:41 PM
also before i forget to say this it also gives no error message or anything at all thanks!
3790 posts
Location
Lincoln, Nebraska
Posted 15 August 2012 - 08:44 PM
You want elseif in stead of else if. Should be one word.
9 posts
Posted 15 August 2012 - 08:51 PM
thanks ill try it i'll be right back
oh and also how do i do the in the code in the box it would be much easier to read
9 posts
Posted 15 August 2012 - 08:56 PM
ah… it does make the code much better code wise it doesn't fully fix my problem… i still have the issue where it doesn't want to copy it to the computer after deleting it any help would be appreciated but i could probably sort it. however does it matter that the script is within a while statement?
436 posts
Posted 15 August 2012 - 08:57 PM
Craniumkid22 is right, but this can also be done much better.
local side = ""
for k, v in pairs(rs.getSides) do
if peripheral.isPresent(v) then
side = v
break
end
end
if side and fs.exists("disk/startup") then
if fs.isDir("disk") then
fs.delete("disk/startup")
sleep(0.1)
if not fs.exists("disk/starup") then
fs.copy("startup","disk/startup")
else
print("Bork'd")
end
else
fs.copy("startup","disk/startup")
end
else
print("'disk' is not the name of the directory")
end
Also, for code tags, put [ and ] around the word code at the top, and then around /code at the bottom of the code.EDIT: Added in a small check to see if it worked or not.
9 posts
Posted 15 August 2012 - 10:06 PM
how does one use code tags? i am relatively new to complex coding in lua i am still a low level coder you could say and is this why the code comes up with an error telling me it wants a table but it got a function…
thanks
3790 posts
Location
Lincoln, Nebraska
Posted 15 August 2012 - 10:17 PM
just put the word "code" in square brackets [ ] at the start, and /code in square brackets at the end. Or you can use the button that looks like this: <> to start your code block.
209 posts
Location
In your fridge.
Posted 16 August 2012 - 01:11 AM
just put the word "code" in square brackets [ ] at the start, and /code in square brackets at the end. Or you can use the button that looks like this: <> to start your code block.
Also, as a courtesy, if your code is long (yours isn't this time) but say, 100+ lines, spoiler tag it. so it looks like this (ignore the asterisks):
[*spoiler]
[*code]
– code goes here.
[*/code]
[*/spoiler]
Spoiler
Will look like this.
9 posts
Posted 16 August 2012 - 11:51 AM
thankyou guys! that helped me look instantly cooler
9 posts
Posted 16 August 2012 - 12:01 PM
local side = ""
for k, v in pairs(rs.getSides) do
if peripheral.isPresent(v) then
side = v
break
end
end
if side and fs.exists("disk/startup") then
if fs.isDir("disk") then
fs.delete("disk/startup")
sleep(0.1)
if not fs.exists("disk/starup") then
fs.copy("startup","disk/startup")
else
print("Bork'd")
end
else
fs.copy("startup","disk/startup")
end
else
print("'disk' is not the name of the directory")
end
i have tried this however i get no luck and infact it just gives me an error message this time: bad argument: table expected, got function and i have no idea how to change it from a function to a table because to be frank i thought a function was function
functionname()
2447 posts
Posted 16 August 2012 - 02:35 PM
for k, v in pairs(rs.getSides) do
Should be:
for k, v in pairs(rs.getSides()) do
Also, your statement that as its SMP the only peripheral would be a disk drive is incorrect - it could also be a modem or a monitor. Your check should be:
if peripheral.getType(v) == "disk" then
436 posts
Posted 16 August 2012 - 03:13 PM
:(/>/>
Always one error. Never more, never less. (Most times, anyway)
9 posts
Posted 16 August 2012 - 04:50 PM
thanks! guys this really helped cleaning up my code however it still somehow doesn't copy the startup file from the disk to the computer =(
thanks
9 posts
Posted 16 August 2012 - 04:54 PM
i dont need it to work actually this has really helped but i am going to stop making the code and start a new one: a player sensor using the ccsensors proximity sensor majigy however i am horrible at coding the ccsensors api and whenever i make anything with it it seems just to bug out and not work any help i'll start a new topic soon as soon as i realise how to close this one