2 posts
Posted 28 March 2014 - 08:57 AM
Hey there guys! I've been fiddling with Computercraft for a while and every once in a while I like to go out and think of a program that will teach me something new about lua and computercraft. Im comming along slowly but I've hit a bit of a snag. I wanted to create a gameboard (Monopoly) and I wanted to make computercraft display the Dice results. I was able to make it generate the numbers, but what I was hoping for was maybe a pressure plate or a lever next to a computer that, when activated, would display a random message of 16 (The chance cards) On a large monitor overhead. Would anyone happen to know code to do this? I think once I get that I should be able to make the dice program no problem. Thanks for your help!
7083 posts
Location
Tasmania (AU)
Posted 28 March 2014 - 03:08 PM
Something like:
-- Define some card messages in a table:
local chanceCards = {"You got second place in a beauty contest! With two people in it!",
"Get out of jail free!",
"Pay some percent tax per property owned!",
"Go to jail! Go directly to jail! Do not pass go, do not collect $200!"}
-- Wrap a monitor:
local mon = peripheral.wrap("right") -- Or whatever "side" is relevant.
-- Main program loop:
while true do -- Start a loop that repeats indefinitely.
if rs.getInput("left") then -- If receiving a redstone signal from a certain side, then...
mon.clear()
mon.setCursorPos(1,1)
mon.write(chanceCards[math.random(#chanceCards)]) -- "#chanceCards" returns the number of entries in the table.
end
os.pullEvent("redstone") -- Sit and wait until a redstone signal change is detected.
end
Though you may want to expand that to remove entries from the card table as they're dealt, then replace them once the table is empty. This should get you started though.
rs.getInput()os.pullEvent()
2 posts
Posted 28 March 2014 - 06:43 PM
That's amazing! Thank you so much! Works like a charm.