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

Working on yet another card game.

Started by Zombie_brine, 19 September 2012 - 10:14 PM
Zombie_brine #1
Posted 20 September 2012 - 12:14 AM
After your guys help with blackjack, I've decided I'd do a more in depth game. I need a program that outputs 1 of 6 random signals to separate dispensers. I need it so that i can use one bundle and just pull individual colors off the line with insulated wire as i go down; preferably white, grey, blue, green, red and black . I know I ask a lot, but I'll gladly give you credit for it in my video and where ever I use it.
Cranium #2
Posted 20 September 2012 - 12:27 AM

local result = math.random(1,6)
if result == 1 then
rs.setBundledOutput("back",colors.white)
sleep(.5)
rs.setOutput("back",0)
elseif result == 2 then
rs.setBundledOutput("back",colors.grey)
sleep(.5)
rs.setOutput("back",0)
elseif result == 3 then
rs.setBundledOutput("back",colors.blue)
sleep(.5)
rs.setOutput("back",0)
elseif result == 4 then
rs.setBundledOutput("back",colors.green)
sleep(.5)
rs.setOutput("back",0)
elseif result == 5 then
rs.setBundledOutput("back",colors.red)
sleep(.5)
rs.setOutput("back",0)
elseif result == 6 then
rs.setBundledOutput("back",colors.black)
sleep(.5)
rs.setOutput("back",0)
end
Put that sucker in your code, and Viola! Randomness complete!
MysticT #3
Posted 20 September 2012 - 02:20 AM
Shorter version, using a table:

local tColors = { colors.white, colors.grey, colors.blue, colors.green, colors.red, colors.black }
local c = tColors[math.random(1, #tColors)]
rs.setBundledOutput("back", c)
sleep(0.5)
rs.setBundledOutput("back", 0)
sleep(0.5)
Also, it works for any number of colors.
Zombie_brine #4
Posted 20 September 2012 - 02:36 AM
Here is how i make the deck btw

[media]http://youtu.be/uj1IO3lI1kc[/media]
Zombie_brine #5
Posted 20 September 2012 - 02:55 AM
tried both, got errors.
Myst yours-
"bios:206: [string "deal"]:5: unfinished string"
Cran yours-
"draw:7: bad argument: int expected, got nil"
solutions?
Fatal_Exception #6
Posted 20 September 2012 - 10:43 AM
Subtle issue with UK vs US spelling and the colors api.

It's colors.gray not colors.grey
KaoS #7
Posted 20 September 2012 - 11:36 AM
MysticT's code seems fine to me, are you sure you have both quotes on rs.setBundledOutput("back", 0)?
Fatal_Exception #8
Posted 20 September 2012 - 11:50 AM
Same problem in Mystic's code, but less obvious because it will only fail randomly.
KaoS #9
Posted 20 September 2012 - 12:01 PM
did you also check Fatal_Exception's suggestion? it is correct as well

it is probably the issue because MysticT's code will only fail if that value is selected but Cranium's would always fail if a color value is wrong
Cranium #10
Posted 20 September 2012 - 03:50 PM
Yeah, the UK spelling is one hurdle to have to randomly fix. Silly Europe. :)/>/>
Zombie_brine #11
Posted 21 September 2012 - 12:53 AM
With mysticT's code I get an error,
"deal:1: attempt to index ? (a number value)"
This is after i fixed 2 other errors :l
MysticT #12
Posted 21 September 2012 - 01:04 AM
It looks like the colors api table was overwriten with a number (you have something like "colors = something"). Try rebooting the computer and running the code again.
Zombie_brine #13
Posted 21 September 2012 - 02:36 AM
It looks like the colors api table was overwriten with a number (you have something like "colors = something"). Try rebooting the computer and running the code again.
problem persists…
MysticT #14
Posted 21 September 2012 - 03:04 AM
Post the code you're using, and anything that runs before it (like startup).
Zombie_brine #15
Posted 21 September 2012 - 04:59 AM
Post the code you're using, and anything that runs before it (like startup).
i got it :)/>/> made a very unnoticeable typo