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

[1.3] Dice

Started by Kazimir, 13 August 2012 - 10:59 AM
Kazimir #1
Posted 13 August 2012 - 12:59 PM
For two blocks require three terminals with modems, 24 bundled cable, a pair of non-ferrous wire and 14 redstone lamps.
How to separate the wires can be seen in the picture.

Two terminals that are on the dice are the receivers, and a third transmitter signal from the player.

Pictures
Spoiler



Code
SpoilerTransmitter:


while true do
   term.clear()
   term.setCursorPos(1,1)
   term.write("Press Enter to roll the dice")
   local Event, d = os.pullEvent("key")
      if Event == "key" and d == 28 then
          rednet.open("top")
          rednet.send(1, "start")    --ID of the first computer and command.
          sleep(0,7)
          rednet.send(2, "start")    --ID of the second computer and command.
      end
end

Receiver:


while true do
rednet.open("top")
i, s = rednet.receive()
  if s == "start" and i == 3 then     --Your command and the ID of the transmitter.
      local n = math.random(6)
      term.write(n)
      cell = {}
        cell[1] = colors.combine(colors.yellow)
        cell[2] = colors.combine(colors.orange, colors.white)
        cell[3] = colors.combine(colors.gray, colors.yellow, colors.pink)
        cell[4] = colors.combine(colors.gray, colors.magenta, colors.lime, colors.pink)
        cell[5] = colors.combine(colors.gray, colors.magenta, colors.lime, colors.pink, colors.yellow)
        cell[6] = colors.combine(colors.gray, colors.magenta, colors.white, colors.orange, colors.lime, colors.pink)

     numb = cell[n]
     rs.setBundledOutput("back", 0)
     sleep(1)
     rs.setBundledOutput("back", numb)
  end
end
Cranium #2
Posted 13 August 2012 - 03:52 PM
I like this! Would you be able to convert this to display on a screen? That would be neat to do! *IDEA*
Cranium #3
Posted 14 August 2012 - 03:00 AM
Finished the screen version of the program! http://www.computercraft.info/forums2/index.php?/topic/3401-dice/
Pharap #4
Posted 14 August 2012 - 10:39 AM
Impressive, a much simpler Dice Program than a textual one
Cranium #5
Posted 14 August 2012 - 02:27 PM
I find the text based ones just more difficult to line up the characters…
Pharap #6
Posted 14 August 2012 - 05:53 PM
I find the text based ones just more difficult to line up the characters…

Working on a fix for that. My gui api is currently in production. As soon as I sort out the attempt to index error I will let you have a go with it.
I've already sorted text alignment and I've got plans for other stuff, it's just that one bug getting in my way and it doesn't make sense.
TanisHalfelven #7
Posted 12 February 2014 - 01:38 AM
quick update to this script as redpower is no longer a thing and redstone wires from project red arent working with CC yet. basically, i routed the math to output an analog redstone signal dependant on the roll which i feed into wireless redstone transmitters(though i reckon you could just go straight to the colored cable) and then from the reciever to the colored wire. i use the wireless redstone simply because i had to mount my dice displays in awkward places so… meh. first script (the Transmitter) stays the same, the changes are made exclusively in the reciever script as follows below.

instead of using:
cell[1] = colors.combine(colors.yellow)

to denote the number rolled, i used:
cell[1] = 2
then:
numb = cell[n]
redstone.setAnalogOutput("back", 0)
sleep(1)
redstone.setAnalogOutput("back", numb)

hope this helps anyone who needs the help and stumbles upon this thread
Lyqyd #8
Posted 12 February 2014 - 12:33 PM
You can use MFR's rednet cables as direct replacements for RedPower bundled cables, no need to change the program.