Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Looking for help from a semi-experienced coder (for a drinking game)

    Hey, Sorry to do this but I have 0 experience with coding, yet would like to make just a simple widget, or website which has a semi random text generator when you press a button.

    Basically, I have a drinking game that we've made up with friends with a game of jenga (jumbling towers). But some of the blocks have things that are cool to have often, and some things are cool to have but way less often, and also I have way more rules than I have blocks, which is 48 total so a website is better than the current number coding system currently written on the blocks.

    So some, for example "give a drink" that can happen often, but some like, "go outside onto the street and sing a song at the top of your lungs," I would like that to happen once, because it gets annoying otherwise. Hopefully I've painted a good picture for what I'm looking for. Not just a random text generator, but one that has values say from 1-3, or 1-5 which could determine the degree of the randomness. I could easily make an excel sheet putting the respective value for each one, but I have no idea how to make it into a widget for a website, or just something embedded into a website. The idea is to be able to take the blocks anywhere and just go to a bookmarked URL so we can play at multiple people's houses, or spread it around since it's a pretty cool game.

    If anyone can help me out please let me know!

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,078
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question Clarification please

    Should be easy enough to do with the information given.

    Do you have an HTML layout example?
    Can you provide a sample of your commands along with their probabilities?
    What are the 48 rules and do the effect the display somehow?

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,932
    Thanks
    56
    Thanked 552 Times in 549 Posts
    the simplest way I can think of to make things happen randomly but with a higher probability would be to stack the array with multiple instances of that command, something like this:

    Code:
    <!HTML>
    <html>
    <head>
    <title>Untitled Document</title>
    </head>
    
    <body>
    <input type="button" id="but" value="show command"/>
    <div id="mess"></div>
    <script>
    (function(){
    var comms;
    
    function setUp(){
    comms=["happens once", "also happens once"];
    addMulti("happens twice",2);
    addMulti("also happens twice",2);
    addMulti("happens three times",3);
    }
    
    function addMulti(str, num){
    for (var i = 0; i < num; i++) {
    comms.push(str);
    	}
    }
    
    document.getElementById("but").onclick= function(){
    var thenum=Math.floor(Math.random()*comms.length)
    document.getElementById("mess").innerHTML=comms.splice(thenum,1);
    if(comms.length==0){
    setUp(); // or do something else once all the commands have been displayed
    }
    
    }
    
    setUp();
    })();
    </script>
    </body>
    </html>


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •