Menu

Random number generator

Anonymous
2001-07-13
2012-09-14
  • Anonymous

    Anonymous - 2001-07-13

    Hello, first of all I would like to say thank you for providing this very cool chat! =)

    Ok, here is my question:
    I would like to create a function where a user could roll some dice. Some thing like /roll 1d6 and the chat would respond with "You roll 1d6 result is 4." Another example would be a graphic of a die somewhere on the chat page. The user would click on the graphic and the chat would respond with "You rolled 1d6 result is 4".

    I know the basics of PHP and have done some research and found that a script like this may work:

    <?php
    // roll the number
    $random_number=rand(1,6);

    // display to screen
    echo $random_number;
    ?>

    Now I can make that work on a regular HTML page, but I don't know how to create/associate a new "/" command in MyPhpChat.

    Can anyone give me an help/hints of how I can do this?

    CJL

     
    • Anonymous

      Anonymous - 2001-07-14

      Ok, how do I add a command like /roll?

      I see that that there are php3 scripts in the /lib directory. I have tried to add a file called random.cmd.php3 that contains the random number generator script as well as adding an If...then statement in the commands.php3 script but when I type /random in the chat room I get a pop up box with "That is not a valid command" does anyone know what I am doing wrong?

       
    • Loïc Chapeaux

      Loïc Chapeaux - 2001-07-17

      Hi Cesar!

      You should also modify a javascript regular expression test in 'chat/lib/index.lib.php3'

      Regards,
      Loc

       
    • Anonymous

      Anonymous - 2001-07-17

      Thank you so much! I had been looking through all the php files for this very expression test!

      Whoot! It now works!

      Thanks again,
      Cesar

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.