var1 = math.random(1,3)
if var1 = (1,2) then
os.reboot()
else
paintutils.loadImage("PrometeoOS/Images/PrometeoOS_Images/image1")
sleep(1)
term.clear()
paintutils.loadImage("PrometeoOS/Images/PrometeoOS_Images/image2")
term.setCursorPos(15,15)
print("LoL")
sleep(3)
term.clear()
os.reboot
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Help me whit this math.random :P
Started by PrometeoPrime, 02 June 2014 - 04:22 PMPosted 02 June 2014 - 06:22 PM
Hey people, this is a part of a my program.. i want to make a little easter egg but.. it do not works because this is the first time i use math.random and infact the program give me an error can someone help me to fix my program?
Edited on 02 June 2014 - 04:56 PM
Posted 02 June 2014 - 06:26 PM
Just formatting your code so it is easier to read.PrometeoPrime said:var1 = math.random(1,3) if var1 = (1,2) then os.reboot() else paintutils.loadImage("PrometeoOS/Images/PrometeoOS_Images/image1") sleep(1) term.clear() paintutils.loadImage("PrometeoOS/Images/PrometeoOS_Images/image2") term.setCursorPos(15,15) print("LoL") sleep(3) term.clear() os.reboot end
[Edit] Also indented it as well.
Whitecatblack
Edited on 02 June 2014 - 04:27 PM
Posted 02 June 2014 - 06:36 PM
So, to troubleshooting your code:
If so, use this line instead:
Whitecatblack
if var1 = (1,2) then
This line is from your code. It looks like you are trying to see if var1 is equal to 1 or 2, correct?If so, use this line instead:
if var1 == 1 or var1 == 2 then
When you are asking a computer to compare two values to see if they are equal, we use two equal signs (==). Also, we use an (or) statement to see if var1 is equal to either 1 or 2.Whitecatblack
Posted 02 June 2014 - 06:43 PM
Ah ok thanks
Posted 02 June 2014 - 09:21 PM
To expand a little on what Whitecatblack said, You can also use elseif
A little example usage of 'or'
local var = math.random( 1, 3 )
if var == 1 then -- If it's equal to 1
...
elseif var == 2 then -- If it's equal to 2
...
else -- If both statements above are false
...
end
But in this case 'or' would be betterA little example usage of 'or'
local input = read()
if input == "Yes" or input == "yes" then
print("You answered yes, I don't know why though O_o")
elseif input == "No" or input == "no" then
print("What are you saying no to? .-.")
end
Posted 02 June 2014 - 09:29 PM
Even though I understand that you are trying to demonstrate functionality of an (or) statement, I can't help myself but make a comment onto how what you said should really be done. Instead of what you wrote, it would be best if used like this (will demonstrate a use of an (or) statement as well):TheOddByte said:A little example usage of 'or'
local input = string.lower(read())
if input == "yes" or input == "yea" then
print("You answered yes, I don't know why though O_o")
elseif input == "no" or input == "na" then
print("What are you saying no to? .-.")
end
Posted 02 June 2014 - 09:57 PM
That's basically the same thing, except that you lowered the input and are only checking for lowercase strings as that is what the input will have turned into.-Snip-
I wasn't really thinking of the best way todo that code I wrote, since it was just a mere example. The 'or' statements work as they should and all and that's the important thing here.