This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jtdavis99's profile picture

Choices

Started by jtdavis99, 03 March 2012 - 12:38 AM
jtdavis99 #1
Posted 03 March 2012 - 01:38 AM
I'm trying to make a dice program where you choose which die you want based on sides, and then it'll print out the results for you. It is getting a lot of weird errors. This is what I have:
local Y = Y
print("Would you like to roll a die? Y or N: ")
input = read()
if input == Y then
print("What die would you like?")
print("1: 6 sided die")
print("2: 12 sided die")
print("3: 20 sided die")
Input = read()
if x = 1 then
print(math.random(1, 6))
sleep(3)
os.shutdown()
end
if x = 2 then
print(math.random(1, 12))
sleep(3)
os.shutdown()
end
if x = 3 then
print(math.random(1, 20))
sleep(3)
os.shutdown()
end
else
print("Ah, ok. Bye!")
sleep(1)
os.shutdown()
end
rerere284 #2
Posted 03 March 2012 - 01:42 AM
The Y = Y should be


Y = ("Y")


And in the dice rolling part, x should be Input.
Also, you need to use == to say, "if this is the same as that, then…" rather than "make this equal that."


if Input == 1 then
MysticT #3
Posted 03 March 2012 - 01:49 AM
Just a few errors I found:
* The first line:

local Y = Y
just asigns what's on Y to Y, wich is nothing (nil). I suppose you wanted to do:

local Y = "Y"
* the lines:

if x = 1 then
if x = 2 then
if x = 3 then
has 2 errors: you are comparing x, wich wasn't defined, so it's nil. You forgot a = sign, it should be:

if Input == 1 then
Also, try to use local variables where you can, like the inputs, use:

local input = read() -- define local variable input and save the results of read() on it
-- some code
input = read() -- reuse local variable input