214 posts
Posted 29 October 2012 - 11:45 AM
ok, i doubt any of you are going to be able to answer this because of lack of info from me. but a while ago i was coding (cant remember what) and i tried using multiple else statments. il try and make an example.
local a = peripheral.isPresent("left")
local b = disk.isPresent("left")
if a == true then
print("drive found")
if b == true then
print("disk found")
else
print("drive not found")
else
print("disk not found")
i
so i need this to say weather a disk is found or a drive is found or if there not found. but with this code im pretty sure it would not work. how could i get this to check for a drive, if a drive is found check for a disk. if a disk is not found say. if a drive is not found say and end the program? if someone could help me with this using multiple else statements i would be really grateful.
thanks -Cheeky
if your wondering what this code is for its for a disk manager im making.
2005 posts
Posted 29 October 2012 - 11:59 AM
You need some ends for those ifs. Are you going for an if then if then else end else end structure, or are you wanting to use if then elseif then else end ?
521 posts
Location
Stockholm, Sweden
Posted 29 October 2012 - 12:06 PM
.
147 posts
Location
England
Posted 29 October 2012 - 02:38 PM
You could try some elseifs too
214 posts
Posted 29 October 2012 - 04:29 PM
You could try some elseifs too
thought about that, but it didn't work out too well when i put it into practise.
This would fit better:
local a = peripheral.isPresent("left")
local b = disk.isPresent("left")
if a == true then
print("drive found")
if b == true then
print("disk found")
else
print("disk not found")
end
else
print("drive not found")
end
thats basically what i wrote with indents:P but would this work, im aware i missed out an end.?
2088 posts
Location
South Africa
Posted 29 October 2012 - 05:27 PM
Yes it will work, but you can actually just put if a then – because it returns a Boolean.
214 posts
Posted 29 October 2012 - 09:42 PM
Yes it will work, but you can actually just put if a then – because it returns a Boolean.
i dont really understand, can u code up a quick example:P
1111 posts
Location
Portland OR
Posted 29 October 2012 - 09:53 PM
local a = peripheral.isPresent("left")
local b = disk.isPresent("left")
if a then
print("drive found")
if b then
print("disk found")
else
print("disk not found")
end
else
print("drive not found")
end
214 posts
Posted 30 October 2012 - 12:58 AM
Thanks Guys soooo much, you helped me clean up my disk manager code SOOOOOOOOOOOOO much:D
521 posts
Location
Stockholm, Sweden
Posted 30 October 2012 - 12:54 PM
.
1111 posts
Location
Portland OR
Posted 30 October 2012 - 08:32 PM
local a = peripheral.isPresent("left")
local b = disk.isPresent("left")
if a then
print("drive found")
if b then
print("disk found")
else
print("disk not found")
end
else
print("drive not found")
end
I think I just said that
Read up a little, he wanted an example of "if a then" instead of "if a == true then".
521 posts
Location
Stockholm, Sweden
Posted 31 October 2012 - 01:56 AM
.
2088 posts
Location
South Africa
Posted 31 October 2012 - 02:00 AM
Yes it will work, but you can actually just put if a then – because it returns a Boolean.
i dont really understand, can u code up a quick example:P
local a = peripheral.isPresent("left")
local b = disk.isPresent("left")
if a then
print("drive found")
if b then
print("disk found")
else
print("disk not found")
end
else
print("drive not found")
end
I think I just said that
Read up a little, he wanted an example of "if a then" instead of "if a == true then".
I can remove my code if that is what you want.
Because, both our codes does the same thing and I can't find in his description that he specifically wants "if a then".
I told him about it then he asked how it can be done with an example of a code.
521 posts
Location
Stockholm, Sweden
Posted 31 October 2012 - 02:09 AM
Call it rage quit or whatever you want, but I removed my posts. (Well kind of)