if bullet == dead or bullet == dead2 or bullet == dead3 or bullet == dead4 or bullet == dead5 then
I just got a feeling that this can be shorter.
Thanks,
Android
if bullet == dead or bullet == dead2 or bullet == dead3 or bullet == dead4 or bullet == dead5 then
in order to better help you we will require further context and/or code.
for example what data does all the `dead` variables contain?
local table = {"var1","var2","var3","etc"}
for i=1,#table do
if input==table[i] then
--do something
break
end
end
if bullet ~= 6 then
if compare == true then
....
elseif compare == false then
monitor.write("")
As far as I know, this does nothing? print has a newline, write doesn't.
shell.run("Russian_Roulette")
No. Bad. Just don't. Do this with a while loop around the main program logic, you can break or return out of it when the program should end. Or Ctrl-T.
monitor.setCursorPos(3,1)
monitor.write("-*-*-*-")
monitor.setCursorPos(3,2)
monitor.write("*-*-*-*")
monitor.setCursorPos(3,3)
monitor.write("You Win!")
monitor.setCursorPos(3,4)
monitor.write("*-*-*-*")
monitor.setCursorPos(3,5)
monitor.write("-*-*-*-")
For loop. Also, monitor function calls take up a LOT of your code. I've only been skimming, but look for ways you can move these long strings of calls into separate functions, this'll make your code cleaner and much more appealing/easier to read.
monitor = peripheral.wrap("top")
You could make "top" a variable instead, and put it somewhere close to the top of the script. Not necessarily… necessary, but it would make it easier to change later on.
dead1 = "1"
dead2 = "2"
dead3 = "3"
dead4 = "4"
dead5 = "5"
Use tables/arrays.
if bullet == dead or bullet == dead2 or bullet == dead3 or bullet == dead4 or bullet == dead5 then
As far as I can see (just skimming the code), this compares the number "bullet" to the strings from before. the if block will never execute.There are a couple ways you could do this with your code. If you simple want to check if something is in a list of variables you can make a table and use a loop to check it like thisFor your code I'd recommend simply checking if it isn't equal to 6.local table = {"var1","var2","var3","etc"} for i=1,#table do if input==table[i] then --do something break end end
if bullet ~= 6 then
you can't only moderators can; they generally don't close Ask a Pro topics. also its better to keep it open incase you have future problems with this same code, you can just continue to post here.P.S. How to close a topic?
you can't only moderators can; they generally don't close Ask a Pro topics. also its better to keep it open incase you have future problems with this same code, you can just continue to post here.P.S. How to close a topic?