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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Location
    Pacific Northwest
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    *Resolved* Dice Roller for Classroom: Reading Double-digits Error

    So far I've logged forty hours in total trying to locate and fix the major problems in this code. I've worked with two other forums and a pay-by-minute guru to no avail. I am hopeful that the good folks here at CodingForums will be able to take this code the final distance. I'll try to be verbose without boring anyone.

    Summary: This code was written in 2005/2007 by "Wonder" at ProBoards. I teach a fourth grade game design and applied mathematics class to home-schoolers on a ProBoards forum. It is placed in the global footer of the forum to allow forum members to roll dice in their posts. The code was incomplete. I worked with "Jordan" at ProBoards to fix the parts that were incomplete. A problem with the code resulted.

    Primary resolution I'm seeking: Right now the code does everything I could possibly want. However, it is mistakenly reading double-digit numbers (XY) as X = sides of die and Y = a negative modifier. Once this issue is fixed, I can take the roller back to my students and they can game together.

    Secondary resolutions I'm seeking: (1) I've been told twice that the code should be "tabbed out." Not sure what that means but I guess it makes it less messy. (2) When clicking the "Add Tag" button the code generates, it automatically inserts [dice=6] into a forum post. Would love this to simply be [dice=X]

    The original code from "Wonder":

    Code:
    <style type="text/css">
    .dicebg {background-color: FFFFFF;border:solid 2px #000000;}
    .dicefont {background-color: FFFFFF;color: 000000; font-weight:bold;}
    </style>
    <script>
    //Dice Rolls In Posts v1.1 updated 31 October 2008
    
    //Copyright 4-23-2007 ~Wonder
    //May be reposted anywhere as long as this header remains in tact
    
    //Do you want the dice to line of horizontally(true) or vertically(false)
    diceAlignment=true;
    
    //Enter URL of the image you want to appear as the dice ubbc button
    UBBCdiceImage="http://img100.imageshack.us/img100/6118/diceicon9rx.gif";
    
    //Enter the default # of sides
    defaultSides=6;
    
    //Enable dice in preview? true or false
    enablePreview=true;
    
    rs="";mainForm="";
    if(document.postForm)
    {
    mainForm=document.postForm;
    if(location.href.match(/action\=modifypost/)){enablePreview=true;}
    mainForm.color.parentNode.innerHTML+="<a href=javascript:add(\"[dice="+defaultSides+"]\",\"\")><img src=\""+UBBCdiceImage+"\" alt=\"Insert Dice Roll\" border=\"0\"></a>";
    mainForm.onsubmit=addRand;
    mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
    rs=RegExp.$1; rs=(/\[rand\=/.test(rs))?rs:"";
    if(location.href.match(/quote\=\d+/))
    {
    mainForm.message.value=mainForm.message.value.replace(/(\[dice\=\d+\])/ig,"");
    rs="";
    }
    }
    else if(location.href.match(/action\=display/))
    {
    ta=document.getElementsByTagName("textarea");
    if(ta.length>0 && ta[0].name=="message")
    {
    mainForm=ta[0].parentNode;
    mainForm.onsubmit=addRand;
    }
    }
    
    ///////////////////////
    if(location.href.match(/action\=(display|pmview|recent|userrecentposts|gotopost|search|calendarview)/) || (!location.href.match(/action\=/) && document.postForm && enablePreview))
    {
    hr=document.getElementsByTagName("hr");
    for(i=0;i<hr.length;i++)
    {
    if(typeof(hr[i].parentNode)!="undefined" && hr[i].parentNode.tagName=="TD" && typeof(hr[i].parentNode.lastChild)!="undefined" && typeof(hr[i].parentNode.lastChild.lastChild)!="undefined" && hr[i].parentNode.lastChild.lastChild.nodeType!=1)
    {
    n=hr[i].parentNode.lastChild;
    rand=n.innerHTML.match(/\[rand\=\d+\]/);
    if(rand!=null)
    {
    n.innerHTML=n.innerHTML.replace(rand[0],"");
    rand=rand[0].replace(/[^\d]/g,"");
    dice=n.innerHTML.match(/\[dice\=\d+(\+\d+)?\]/ig);
    if(dice!=null)
    {
    for(k=0;k<dice.length;k++)
    {
    numb=dice[k].match(/\d+(\+\d+)?/);
    numb=numb[0].split("+");
    addon=numb.length>1?parseInt(numb[1],10):0;
    numb=parseInt(numb[0],10);
    roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
    n.innerHTML=n.innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:"")+"</font></font></center></td></tr></table></td></tr></table>&nbsp; ");
    }
    }
    }
    }
    }
    }
    function addRand()
    {
    mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
    if((rs.length==0 && mainForm.message.value.match(/(\[dice\=\d+(\+\d+)?\])/)) && (enablePreview==true || (enablePreview==false && mainForm.nextaction.value=="post")))
    {
    mainForm.message.value+="[rand="+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+( Math.random()+"").replace(/0\./,"")+"]";
    }
    else
    {
    mainForm.message.value+=rs;
    }
    disable(mainForm);
    }
    </script>
    The altered code from "Jordan":

    Code:
    <style type="text/css">
    .dicebg {background-color: FFFFFF;border:solid 2px #000000;}
    .dicefont {background-color: FFFFFF;color: 000000; font-weight:bold;}
    </style>
    <script>
    //Dice Rolls In Posts v1.1 updated by Jordan October 2009
    
    //Copyright 4-23-2007 ~Wonder
    //May be reposted anywhere as long as this header remains in tact
    
    //Do you want the dice to line of horizontally(true) or vertically(false)
    diceAlignment=true;
    
    //Enter URL of the image you want to appear as the dice ubbc button
    UBBCdiceImage="http://img100.imageshack.us/img100/6118/diceicon9rx.gif";
    
    //Enter the default # of sides
    defaultSides=6;
    
    //Enable dice in preview? true or false
    enablePreview=true;
    
    
    
    rs="";mainForm="";
    if(document.postForm)
    {
    mainForm=document.postForm;
    if(location.href.match(/action\=modifypost/)){enablePreview=true;}
    mainForm.color.parentNode.innerHTML+="<a href=javascript:add(\"[dice="+defaultSides+"]\",\"\")><img src=\""+UBBCdiceImage+"\" alt=\"Insert Dice Roll\" border=\"0\"></a>";
    mainForm.onsubmit=addRand;
    mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
    rs=RegExp.$1; rs=(/\[rand\=/.test(rs))?rs:"";
    if(location.href.match(/quote\=\d+/))
    {
    mainForm.message.value=mainForm.message.value.replace(/(\[dice\=\d+\])/ig,"");
    rs="";
    }
    }
    else if(location.href.match(/action\=display/))
    {
    ta=document.getElementsByTagName("textarea");
    if(ta.length>0 && ta[0].name=="message")
    {
    mainForm=ta[0].parentNode;
    mainForm.onsubmit=addRand;
    }
    }
    
    
    
    ///////////////////////
    if(location.href.match(/action\=(display|pmview|recent|userrecentposts|gotopost|search|calendarview)/) || (!location.href.match(/action\=/) && document.postForm && enablePreview))
    {
    hr=document.getElementsByTagName("hr");
    for(i=0;i<hr.length;i++)
    {
    if(typeof(hr[i].parentNode)!="undefined" && hr[i].parentNode.tagName=="TD" && typeof(hr[i].parentNode.lastChild)!="undefined" && typeof(hr[i].parentNode.lastChild.lastChild)!="undefined" && hr[i].parentNode.lastChild.lastChild.nodeType!=1)
    {
    n=hr[i].parentNode.lastChild;
    rand=n.innerHTML.match(/\[rand\=\d+\]/);
    if(rand!=null)
    {
    n.innerHTML=n.innerHTML.replace(rand[0],"");
    rand=rand[0].replace(/[^\d]/g,"");
    dice=n.innerHTML.match(/\[dice\=\d+((\+|\-)\d+)?\]/ig);
    if(dice!=null)
    {
    for(k=0;k<dice.length;k++)
    {
    numb=dice[k].match(/\d+((\+|\-)\d+)?/);
    numb=numb[0].split(RegExp.$2);
    unsigned = (RegExp.$2 == "+") ? true : false;
    addon=numb.length>1?parseInt(numb[1],10):0;
    if(!unsigned)addon = addon - addon * 2;
    numb=parseInt(numb[0],10);
    roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
    n.innerHTML=n.innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:addon)+"</font></font></center></td></tr></table></td></tr></table> ");
    }
    }
    }
    }
    }
    }
    function addRand()
    {
    mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
    if((rs.length==0 && mainForm.message.value.match(/(\[dice\=\d+((\+|\-)\d+)?\])/)) && (enablePreview==true || (enablePreview==false && mainForm.nextaction.value=="post")))
    {
    mainForm.message.value+="[rand="+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+( Math.random()+"").replace(/0\./,"")+"]";
    }
    else
    {
    mainForm.message.value+=rs;
    }
    disable(mainForm);
    }
    </script>
    My incredibly detailed account of my last few weeks with this code:

    Back in 2005, a user named "Wonder" wrote a nifty piece of code that fits into any ole ProBoard's global footer. Once installed on a forum, it allows users to type the command [dice=X] where X is the number of sides for the single die they want to roll and it gives them a random result that's very attractive (a small white box with a black border and a bold, large result with smaller text below that reads: Xsides) and not "easy" to change/alter/cheat. To roll more than one die, you simply string the command like [dice=X][dice=X][dice=X][dice=X]. The code also allows for positive modifiers (bonuses) such as [dice=X+Y] where the result has the same compact, attractive format and the small text reads: Xsides+Y

    Wonder posted that his code would also allow negative modifiers (penalties) but, actually, no one seems to have ever tested that part... until September 2009 when along came pesky me.

    I went over to the ProBoards support forum because Wonder's code is included in their official database. I posted the problem and a user named Jordan tweaked the code several times, each time getting it closer to providing the correct result. The correct result being that when a user types the command [dice=X-Y] the result is the attractive box, the larger number above and the smaller text below that reads Xsides-Y (in addition to continuing to accept [dice=X] and [dice=X+Y] and offer the same format of results).

    Jordan's version of the code now does all this. But when I started testing it I realized that whenever a user types a command that gives the die double-digit sides (10, 12, 20, etc), the code now reads it like this: [dice=10] results in 1sides-0 or [dice=12] results in 1sides-2. So double-digit numbers are being read as the number of sides and a negative modifier *sigh* Very bad news.

    Jordan needed to pass on further work on the code because (understandably) it was taking too much time and it was "messy." Since I am not a coder myself, most JavaScript looks messy to me but I believe Jordan.

    I then took the code to a pay-by-minute help website but was gently told that the code was so messy that it would take too long to debug and it wouldn't be worth the charge since the roller is being used for a non-profit classroom project for my fourth graders. I thought that was very thoughtful... but I'm back at square one, really.

    I have attached everything I have: The very original code from Wonder (the one that doesn't read negative modifiers at all) and the latest from Jordan (that reads double-digits incorrectly).

    The only other cute/attractive thing about the code that I'll point out (so you don't see it in the code and wonder, "What the heck is that?" is: When you install the code into a forum, it adds a tiny die-shaped button to the Add Tags menu. Users can click the little thing and the code automatically inserts [dice=6] for them. Personally, this doesn't help my students and I would love it if the button just inserted [dice=X] but that's fine.

    *deep breath*

    Whew! That's about it. Thank you for putting up with my blather. I sincerely appreciate any help you can offer. I know your time is valuable and I've taken quite a bit just posting my full report... I just wanted to try to be verbose :)

    Jennifer
    Last edited by mamajenn; 10-22-2009 at 08:08 AM. Reason: Posted correct code.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    I am afraid that unless you post the whole thing including the HTML it is, as you rightly say, too messy to disentangle.

  • #3
    New to the CF scene
    Join Date
    Oct 2009
    Location
    Pacific Northwest
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Absolutely, Philip. Do you mean I need to go to my ProBoard where it is installed, right-click, view source, copy and paste that here for you? (I'm very sorry if this is a stupid question.) I've done that below and in the next post (the post was over the CodingForums limit).

    Jennifer

    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <html>
    <head>
    <title>Mardi Gras 3000 Forum - Dice-Roller Testing</title>
    <script type="text/javascript" src="http://partner.googleadservices.com/gampad/google_service.js"></script>
    <script type="text/javascript">
      GS_googleAddAdSenseService("ca-pub-4696585109196199");
      GS_googleEnableAllServices(); </script>
    <script type="text/javascript">
      GA_googleAddSlot("ca-pub-4696585109196199", "728x90_ROS");
      GA_googleAddSlot("ca-pub-4696585109196199", "336x280_ROS");
      GA_googleAddSlot("ca-pub-4696585109196199", "336x280_2_ROS");
      GA_googleAddSlot("ca-pub-4696585109196199", "Text_Links");
    </script>
    <script type="text/javascript"> GA_googleAddAdSensePageAttr("google_color_border", "FFCC66");
    GA_googleAddAdSensePageAttr("google_alternate_ad_url", "http://banners.proboards.com/a/b.cgi");
    GA_googleAddAdSensePageAttr("google_color_bg", "171717");
    GA_googleAddAdSensePageAttr("google_color_link", "FF6600");
    GA_googleAddAdSensePageAttr("google_color_url", "FF6600");
    GA_googleAddAdSensePageAttr("google_color_text", "FFFFFF");
    GA_googleAddAdSensePageAttr("google_ui_features","rc:10");
    GA_googleAddAdSensePageAttr("google_cust_gender", "2");
    GA_googleAddAttr("G", "F");
    GA_googleAddAdSensePageAttr("google_cust_age", "1002");
    GA_googleAddAttr("A", "28");GA_googleAddAttr("user", "ej");GA_googleAddAttr("C","9");GA_googleAddAttr("forum", "mardigras3000");
    GA_googleAddAdSensePageAttr("google_hints", "DiceRoller Testing");
    </script>
    <script type="text/javascript">
    GA_googleFetchAds();
    </script>
    <script language="JavaScript1.2" type="text/javascript">
    <!--
    
    if((navigator.appVersion.substring(0,1) == "5" && navigator.userAgent.indexOf('Gecko') != -1) ||navigator.userAgent.search(/Opera/) != -1)document.write('<META HTTP-EQUIV="pragma" CONTENT="no-cache">');
    function doConfirm(m,u){if(confirm(m)) location.href = u;}
    function popWindow(x){var xWin=window.open("index.cgi?action="+x,"popWindow","directories=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0,top=100,left=100,width=400,height=275");xWin.focus();}
    function disable(form){for(i=0;i<form.length;i++){if(form.elements[i].type == 'submit')form.elements[i].disabled=true;if(form.elements[i].type == 'reset')form.elements[i].disabled=true;if(form.elements[i].type == 'button')form.elements[i].disabled=true;}}
    var pb_bubble = 0;
    var pb_skinid = 2;
    var pb_username = 'ej';
    var pb_displayname = 'EJ';
    var pb_adfloat = 1;
    var pb_admovement = "center";
    var pb_adx = 0;
    var pb_VersionNo = 4.5;
    var pb_this = '74';
    // -->
    </script>
    
    <script type="text/javascript">
    
    var removePageSpan = "";
    var pageSpan = document.getElementById('pagedropmenu');
    
    function loadPageSpan(obj,action,b,c) {
    	pageSpan = document.getElementById('pagedropmenu');
    	var curleft = curtop = 0;
    	if (obj.offsetParent) {
    		curleft = obj.offsetLeft;
    		curtop = obj.offsetTop;
    		while (obj = obj.offsetParent) {
    			curleft += obj.offsetLeft;
    			curtop += obj.offsetTop;
    		}
    	}
    
    	pUp = (c <= 3) ? 6 : c + 3;
    	pDown = (b == c) ? c - 4 : c - 2;
    
    	pageSpan.innerHTML = (c != 1) ? '[go to: <a href="/index.cgi?'+action+1+'" onmouseover="showPageSpan();" class="nav">1</a>'+ ((c <= 5) ? " " : " ... ") : '[ go to: ';
    
    	for (z=pDown;z<pUp;z++)
    		if (z != c && z > 1 && z < b)
    			pageSpan.innerHTML+='<a href="/index.cgi?'+action+z+'" onmouseover="showPageSpan();" class="nav">'+z+'</a> ';
    		else if (z == c)
    			pageSpan.innerHTML+='<b>'+z+'</b> ';
    
    	pageSpan.innerHTML += (c != b) ? ((c >= b-3) ? "" : "... ") + '<a href="/index.cgi?'+action+b+'" onmouseover="showPageSpan();" class="nav">'+b+'</a> ]' : ']';
    	pageSpan.style.cssText = "position: absolute; top: "+ (curtop+15) +"px; left: "+curleft+"px; display: ;";
    }
    
    function hidePageSpan (event,a) {
    	x = (navigator.appName=="Microsoft Internet Explorer") ? event.srcElement : event.target;
    
    	if (x.id == 'pagedropmenu' || a == 1)
    		removePageSpan = window.setTimeout('pageSpan.style.display="none";',1500);
    }
    
    function showPageSpan () {
    	pageSpan.style.display="";
    	window.clearTimeout(removePageSpan);
    }
    
    </script>
    
    <style type="text/css"><!--
    body          { font-family: Georgia;font-size:12px; margin: 0px; padding: 0px; background-image: url(http://i487.photobucket.com/albums/rr240/MardiGras3000/new%20forum%20images/background-1.jpg);background-attachment: fixed;}
    td            { font-family: Georgia; color: #FFFFFF; font-size:11px; }
    input         { font-family: Georgia; font-size: 9pt; color: #000000; }
    textarea      { font-family: Georgia; font-size: 9pt; color: #000000; }
    select        { font-family: Georgia; font-size: 7pt; color: #000000; }
    optgroup        { font-family: Georgia; font-size: 7pt; color: #000000; }
    A:link        { text-decoration: none; color: #FF6600; }
    A:visited     { text-decoration: none; color: #FF6600; }
    A:hover       { text-decoration: underline overline; color: #FF6600; }
    .nav          { font-size: 10px; text-decoration: none; color: #FFFFFF; }
    .nav:link     { font-size: 10px; text-decoration: none; color: #FF6600; }
    .nav:visited  { font-size: 10px; text-decoration: none; color: #FF6600; }
    .nav:hover    { font-size: 10px; text-decoration: none; color: #FF6600;  text-decoration: underline; }
    .windowbg     { background-color: #171717; font-size: 11px; color: #FFFFFF; }
    .windowbg2    { background-color: #080808; font-size: 11px; color: #FFFFFF; }
    .titlebg      { background-color: #ff6600; font-style: normal; font-weight: bold; font-size: 12px; color: #FFFFFF; background-image: url(http://gradients.proboards.com/FF660000000035.gif);}
    .titletext A  { color: #FFFFFF;}
    .popuptitlebg { background-color: #FFCC66; font-style: normal; font-weight: bold; font-size: 12px; color: #000000; }
    .catbg        { background-color: #000000; color: #FFFFFF; font-weight: bold; font-size: 13px; ; }
    .hr           { color: #FFFFFF; background-color: #FFFFFF;}
    .bordercolor  { background-color: #FFCC66; }
    .quote        { font-size: 10px; color: #FFFFFF; background-color: #080808; }
    .code         { font-size: 10px; font-family: Courier New; color: #FFFFFF; background-color: #080808; }
    .menubg       { background-image: url(http://gradients.proboards.com/00000008080835.gif);}
    #pagedropmenu {border: 1px solid #FFCC66; background-color: #080808; font-family: Verdana; font-size: 11px; padding: 5px; text-align: center;}
    .newstitlebg      { background-color: #FF6600; font-style: normal; font-weight: bold; font-size: 12px; color: #FFFFFF; background-image: url(http://gradients.proboards.com/FF660000000035.gif);}
     --></style>
    </head>
    <body text="FFFFFF" bgcolor="000000" link="FF6600" vlink="FF6600" alink="FF6600">
    
    
    <br />
    <table width="92%" cellspacing="1" cellpadding="0" border="0" align="center" bgcolor="FFCC66" class="bordercolor">
    <tr>
    <td width="100%">
    <table border="0" width="100%" cellpadding="0" cellspacing="0">
    <tr>
    <td height="50" align="center" class="welcomebg" bgcolor="000000"><font size="+1"><img src="http://i487.photobucket.com/albums/rr240/MardiGras3000/new%20forum%20images/logo-1.jpg" border="0" alt="Mardi Gras 3000 Forum"/></font><br />
    <font size="-1"> Dice-Roller Testing </font></td>
    <td class="welcomebg" bgcolor="000000">
    <p><font size="2">
    Hey, EJ, you have <a href="/index.cgi?action=pm">3 messages</a>, 0 are new.<br/>Oct 21, 2009, 7:16am
    </font><br /></p>
    </td>
    </tr>
    </table>
    </td>
    </tr><tr>
    <td align="center">
    <table width="100%" cellspacing="0" cellpadding="0" align="center">
    <tr>
    <td width="100%" align="center">
    <table border="0" width="100%" cellpadding="3" cellspacing="0" align="center">
    <tr>
    <td class="menubg" valign="middle" bgcolor="171717" align="center"><font size="1">
    <a href="/index.cgi"><img src="http://s4.images.proboards.com/menu/home.gif" alt="[Home]" border="0"/></a>&nbsp;<a href="http://help.proboards.com/"><img src="http://s4.images.proboards.com/menu/help.gif" alt="[Help]" border="0"/></a>&nbsp;<a href="/index.cgi?action=search"><img src="http://s4.images.proboards.com/menu/search.gif" alt="[Search]" border="0"/></a>&nbsp;<a href="/index.cgi?action=members"><img src="http://s4.images.proboards.com/menu/members.gif" alt="[Members]" border="0"/></a>&nbsp;<a href="/index.cgi?action=viewprofile"><img src="http://s4.images.proboards.com/menu/profile.gif" alt="[Profile]" border="0"/></a>&nbsp;<a href="/index.cgi?action=logout"><img src="http://s4.images.proboards.com/menu/logout.gif" alt="[Logout]" border="0"/></a>&nbsp;<a href="/index.cgi?action=chat"><img src="http://s4.images.proboards.com/menu/chat.gif" alt="[Live Chat]" border="0"/></a>
    </font></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    <br />
    
    
    <center>
    <script type="text/javascript">
    GA_googleFillSlot("728x90_ROS");
    </script>
    </center>
    
    <br />
    <span id="pagedropmenu" class="nav" style="display: none;" onmouseout="hidePageSpan(event,0);" onmouseover="window.clearTimeout(removePageSpan);"></span>
    
    
    
    <table width="92%" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td valign="top" width="100%">
          <br />
    <a href="/index.cgi" class="nav">Mardi Gras 3000 Forum</a> :: <a href="/index.cgi#general" class="nav">For Everyone</a> :: <a href="/index.cgi?board=general" class="nav">General</a> :: Dice-Roller Testing<br/><table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="FFCC66" class="bordercolor"><tr><td><table cellpadding="4" cellspacing="1" border="0" width="100%"><tr><td colspan="2" width="100%" class="titlebg" bgcolor="ff6600"><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td width="50%"> &nbsp; &nbsp;<a href="javascript:popWindow('searchpopup&board=general&thread=330');"><img src="http://s4.images.proboards.com/search2.gif" alt="[Search This Thread]" border="0"/></a> <a href="/index.cgi?action=addbookmark&board=general&thread=330&page=1"><img src="http://s4.images.proboards.com/buttons/bookmark.gif" alt="[Add Bookmark]" border="0"/></a></td><td width="50%" align="right"><a href="/index.cgi?board=general&action=createpoll&thread=330&page=1"><img src="http://s4.images.proboards.com/buttons/addpoll.gif" alt="[Add Poll]" border="0"/></a> <a href="/index.cgi?board=general&action=post&thread=330&page=1"><img src="http://s4.images.proboards.com/buttons/reply.gif" alt="[Reply]" border="0"/></a> <a href="/index.cgi?board=general&action=sendtopic&thread=330"><img src="http://s4.images.proboards.com/buttons/sendtopic.gif" alt="[Send Topic To Friend]" border="0"/></a> <a href="/index.cgi?board=general&action=print&thread=330"><img src="http://s4.images.proboards.com/buttons/print.gif" alt="[Print]" border="0"/></a> </td></tr></table></td></tr><tr><td valign="middle" align="left" width="20%" bgcolor="000000" class="catbg"><font size="-1" class="cattext" color="FFFFFF"><img src="http://s4.images.proboards.com/thread.gif" alt=" " border="0"/> <b>Author</b></font></td><td valign="middle" align="left" bgcolor="000000" class="catbg" width="80%"><font size="-1" class="cattext" color="FFFFFF">Topic: Dice-Roller Testing (Read 1 time)</font></td></tr><tr><td valign="top" align="left" width="20%" bgcolor="171717" class="windowbg"><a name="1890"></a>
    <a name="1256127388"></a><b><a href="/index.cgi?action=viewprofile&amp;user=ej" class="group0">EJ</a></b><br/>MG3K Forum Member<br/>Universe Designer and Writer<br/>member is <b>online</b><br/><br/><center><img src="http://i487.photobucket.com/albums/rr240/MardiGras3000/Angel/ej.gif" alt="[avatar]" border="0" width="100" height="100"/><br/><br/><br/><a href="/index.cgi?action=pmsend&to=ej"><img src="http://s4.images.proboards.com/buttons/message_sm.gif" alt="[send pm]" border="0"/></a> </center><br/>Joined: Sept 2009<br/>Gender: Female <img src="http://s4.images.proboards.com/female.gif" alt=" " border="0"/><br/>Posts: 525<br/></td><td valign="top" align="left" bgcolor="171717" class="windowbg" width="80%" height="100%"><table width="100%" height="100%" border="0" cellpadding="2" cellspacing="2"	><tr><td align="left" valign="middle" width="5%"><img src="http://s4.images.proboards.com/xx.gif" alt=" " border="0"/></td><td align="left" valign="middle" width="55%"><font size="2"><b>Dice-Roller Testing</b></font><br/><font size="1"> Thread Started <b>Today</b> at 7:16am </font></td><td align="right" valign="bottom" height="20" width="40%"><font size="-1"><a href="/index.cgi?board=general&action=post&thread=330&quote=1890&page=1"><img src="http://s4.images.proboards.com/buttons/quote.gif" alt="[Quote]" border="0"/></a> <a href="/index.cgi?board=general&action=modifypost&thread=330&post=1890"><img src="http://s4.images.proboards.com/buttons/modify.gif" alt="[Modify]" border="0"/></a> <a href="javascript:doConfirm('Are you sure you want to delete this post?','/index.cgi?board=general&action=deletepost&thread=330&post=1890&page=1')"><img src="http://s4.images.proboards.com/buttons/delete.gif" alt="[Delete]" border="0"/></a></font></td></tr><tr><td colspan="3" valign="top"><hr width="100%" size="1" class="hr"><font size="2">
    <!-- google_ad_section_start -->
    Dice-Roller Testing
    <!-- google_ad_section_end -->
    </font></td></tr><tr><td valign="bottom" align="left" bgcolor="171717" class="windowbg" colspan="3"><table width="100%" border="0"><tr><td align="left"><font size="1"></font></td><td align="right"><font size="1"><a href="/index.cgi?board=general&action=display&thread=330&page=1#1890">Link to Post</a> - <a href="#">Back to Top</a>&nbsp;&nbsp;</font><font size="1"><img src="http://s4.images.proboards.com/ip.gif" alt="IP: " border="0"/> Logged</font></td></tr></table><font size="1"><hr width="100%" size="1" class="hr"><a href="http://ejangel.blogspot.com/" target="_blank" rel="nofollow">Gamer Grrl in Small Doses: The Offical (E.J.) Angel Blog</a><br/><img src="http://www.mardigras3000.com/downloads/EJANGEL2.JPG" alt="[image] " border="0"/></font></td></tr></table></td></tr><tr><td colspan="2" width="100%" class="titlebg" bgcolor="ff6600"><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td width="50%"> &nbsp; &nbsp;<a href="javascript:popWindow('searchpopup&board=general&thread=330');"><img src="http://s4.images.proboards.com/search2.gif" alt="[Search This Thread]" border="0"/></a> <a href="/index.cgi?action=addbookmark&board=general&thread=330&page=1"><img src="http://s4.images.proboards.com/buttons/bookmark.gif" alt="[Add Bookmark]" border="0"/></a></td><td width="50%" align="right"><a href="/index.cgi?board=general&action=createpoll&thread=330&page=1"><img src="http://s4.images.proboards.com/buttons/addpoll.gif" alt="[Add Poll]" border="0"/></a> <a href="/index.cgi?board=general&action=post&thread=330&page=1"><img src="http://s4.images.proboards.com/buttons/reply.gif" alt="[Reply]" border="0"/></a> <a href="/index.cgi?board=general&action=sendtopic&thread=330"><img src="http://s4.images.proboards.com/buttons/sendtopic.gif" alt="[Send Topic To Friend]" border="0"/></a> <a href="/index.cgi?board=general&action=print&thread=330"><img src="http://s4.images.proboards.com/buttons/print.gif" alt="[Print]" border="0"/></a> </td></tr></table></td></tr></table></td></tr></table><br/><br/><table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="FFCC66" class="bordercolor"><tr><td><table cellpadding="4" cellspacing="1" border="0" width="100%"><tr><td width="100%" class="titlebg" bgcolor="ff6600"><font size="2"><b>Quick Reply</b></font></td></tr><tr><td width="100%" class="windowbg" bgcolor="171717"><font size="2">Message:<br/><form action="/index.cgi" method="post" onsubmit="disable(this)"><input type="hidden" name="action" value="post2"/><input type="hidden" name="board" value="general"/><input type="hidden" name="thread" value="330"/><input type="hidden" name="notify" value="0"/><input type="hidden" name="icon" value="xx"/><input type="hidden" name="subject" value="Re: Dice-Roller Testing"/><textarea rows="5" cols="100" name="message" accesskey="q"></textarea><br/><input type="submit" value="Post Reply" accesskey="s"/> <font size="1">Shortcut to Quick Reply box: Alt+Q.  Shortcut to post message: Alt+S.</font></form></font></td></tr></table></td></tr></table>       <table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="right"><select id="forumjump" onchange="if(this.options[this.selectedIndex].value) window.location=this.options[this.selectedIndex].value;"><option value="">Forum Jump</option><option value="">--------------------</option><option value="/index.cgi"> Home</option><option value="">--------------------</option><option value="/index.cgi#general"> For Everyone</option><option value="">--------------------</option><option value="/index.cgi?board=general">- General</option><option value="/index.cgi?board=chatter">- Random Chatter</option><option value="/index.cgi?board=misc">- MG3K Miscellaneous</option><option value="/index.cgi?board=announcements">- Official Annoucements & Events</option><option value="/index.cgi?board=officialfiction">- Official Fiction</option><option value="/index.cgi?board=fanfiction">- Fan Fiction</option><option value="">--------------------</option><option value="/index.cgi#writers"> For MG3K Writers</option><option value="">--------------------</option><option value="/index.cgi?board=mg3kuniverse">- The MG3K Universe</option><option value="/index.cgi?board=celestials">- Celestials</option><option value="/index.cgi?board=terrapyres">- Terrapyres</option><option value="/index.cgi?board=others">- Others</option><option value="/index.cgi?board=cardedcelestials">- Carded Celestials</option><option value="/index.cgi?board=fictioncelestials">- Fiction Celestials</option><option value="/index.cgi?board=cardedterrapyres">- Carded Terrapyres</option><option value="/index.cgi?board=fictionterrapyres">- Fiction Terrapyres</option><option value="/index.cgi?board=cardedothers">- Carded Others</option><option value="/index.cgi?board=fictionothers">- Fiction Others</option><option value="/index.cgi?board=officialwriters">- Official Writers</option><option value="">--------------------</option><option value="/index.cgi#players"> For MG3K Players</option><option value="">--------------------</option><option value="/index.cgi?board=mg3kccg">- MG3K Collectible Card Game</option><option value="/index.cgi?board=vmg3k">- vMG3K (The CCG Online)</option><option value="/index.cgi?board=mg3kbbmorpg">- MG3K Online Roleplaying</option><option value="/index.cgi?board=mg3krpg">- MG3K Roleplaying Game</option><option value="">--------------------</option><option value="/index.cgi#parallel"> MG3K Parallel Lines</option><option value="">--------------------</option><option value="/index.cgi?board=divinitymx">- Divinity MX</option><option value="/index.cgi?board=dmxintro"> --- Introduction</option><option value="/index.cgi?board=leatherladybird">- Leather Ladybird</option><option value="/index.cgi?board=llintro"> --- Introduction</option><option value="/index.cgi?board=llfiction"> --- Fiction</option></select></td></tr></table>
        </td>
      </tr>
    </table>
    <br />
    Last edited by mamajenn; 10-21-2009 at 01:20 PM. Reason: Added code.

  • #4
    New to the CF scene
    Join Date
    Oct 2009
    Location
    Pacific Northwest
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Second half of html and code:

    Code:
    <style type="text/css">
    .dicebg {background-color: FFFFFF;border:solid 2px #000000;}
    .dicefont {background-color: FFFFFF;color: 000000; font-weight:bold;}
    </style>
    <script>
    //Dice Rolls In Posts v1.1
    
    //Copyright 4-23-2007 ~Wonder updated by Jordan October 2009
    //May be reposted anywhere as long as this header remains in tact
    
    //Do you want the dice to line of horizontally(true) or vertically(false)
    diceAlignment=true;
    
    //Enter URL of the image you want to appear as the dice ubbc button
    UBBCdiceImage="http://img100.imageshack.us/img100/6118/diceicon9rx.gif";
    
    //Enter the default # of sides
    defaultSides=6;
    
    //Enable dice in preview? true or false
    enablePreview=true;
    
    
    
    rs="";mainForm="";
    if(document.postForm)
    {
    mainForm=document.postForm;
    if(location.href.match(/action\=modifypost/)){enablePreview=true;}
    mainForm.color.parentNode.innerHTML+="<a href=javascript:add(\"[dice="+defaultSides+"]\",\"\")><img src=\""+UBBCdiceImage+"\" alt=\"Insert Dice Roll\" border=\"0\"></a>";
    mainForm.onsubmit=addRand;
    mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
    rs=RegExp.$1; rs=(/\[rand\=/.test(rs))?rs:"";
    if(location.href.match(/quote\=\d+/))
    {
    mainForm.message.value=mainForm.message.value.replace(/(\[dice\=\d+\])/ig,"");
    rs="";
    }
    }
    else if(location.href.match(/action\=display/))
    {
    ta=document.getElementsByTagName("textarea");
    if(ta.length>0 && ta[0].name=="message")
    {
    mainForm=ta[0].parentNode;
    mainForm.onsubmit=addRand;
    }
    }
    
    
    
    ///////////////////////
    if(location.href.match(/action\=(display|pmview|recent|userrecentposts|gotopost|search|calendarview)/) || (!location.href.match(/action\=/) && document.postForm && enablePreview))
    {
    hr=document.getElementsByTagName("hr");
    for(i=0;i<hr.length;i++)
    {
    if(typeof(hr[i].parentNode)!="undefined" && hr[i].parentNode.tagName=="TD" && typeof(hr[i].parentNode.lastChild)!="undefined" && typeof(hr[i].parentNode.lastChild.lastChild)!="undefined" && hr[i].parentNode.lastChild.lastChild.nodeType!=1)
    {
    n=hr[i].parentNode.lastChild;
    rand=n.innerHTML.match(/\[rand\=\d+\]/);
    if(rand!=null)
    {
    n.innerHTML=n.innerHTML.replace(rand[0],"");
    rand=rand[0].replace(/[^\d]/g,"");
    dice=n.innerHTML.match(/\[dice\=\d+((\+|\-)\d+)?\]/ig);
    if(dice!=null)
    {
    for(k=0;k<dice.length;k++)
    {
    numb=dice[k].match(/\d+((\+|\-)\d+)?/);
    numb=numb[0].split(RegExp.$2);
    unsigned = (RegExp.$2 == "+") ? true : false;
    addon=numb.length>1?parseInt(numb[1],10):0;
    if(!unsigned)addon = addon - addon * 2;
    numb=parseInt(numb[0],10);
    roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
    n.innerHTML=n.innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:addon)+"</font></font></center></td></tr></table></td></tr></table> ");
    }
    }
    }
    }
    }
    }
    function addRand()
    {
    mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
    if((rs.length==0 && mainForm.message.value.match(/(\[dice\=\d+((\+|\-)\d+)?\])/)) && (enablePreview==true || (enablePreview==false && mainForm.nextaction.value=="post")))
    {
    mainForm.message.value+="[rand="+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+( Math.random()+"").replace(/0\./,"")+"]";
    }
    else
    {
    mainForm.message.value+=rs;
    }
    disable(mainForm);
    }
    </script> <center><form method="get" action="http://www.google.com/custom" target="_top"><table border="0"><tr><td nowrap="nowrap" valign="top" align="left" height="32"><a href="http://www.google.com/"><img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google"></img></a></td><td nowrap="nowrap"><input type="hidden" name="domains" value="www.mardigras3000.proboards.com"></input><input type="text" name="q" size="31" maxlength="255" value=""></input> <input type="submit" name="sa" value="Search"></input></td></tr><tr><td> </td><td nowrap="nowrap"><table><tr><td><input type="radio" name="sitesearch" value="" checked="checked"></input><font size="-1" color="#000000">Web</font></td><td><input type="radio" name="sitesearch" value="www.mardigras3000.proboards.com"></input><font size="-1" color="#000000">www.mardigras3000.proboards.com</font></td></tr></table><input type="hidden" name="client" value="pub-4696585109196199"></input><input type="hidden" name="forid" value="1"></input><input type="hidden" name="ie" value="ISO-8859-1"></input><input type="hidden" name="oe" value="ISO-8859-1"></input><input type="hidden" name="safe" value="active"></input><input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#FFFFF0;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;"></input><input type="hidden" name="hl" value="en"></input></td></tr></table></form></center><script language="javascript">
        vb_a_api_version='Rover::VBA::Toolkit/0.4';
        vb_a_stracker='a1f9015c15922698596d7c5bdd1561c2';
        vb_a_forumid='mardigras3000';
        vb_a_forumtitle='Mardi Gras 3000 Forum';
        vb_a_threadid='330';
        va_a_threadtitle='Dice-Roller Testing';
        vb_a_userid='ej';
        vb_a_username='ej';
        vb_a_postid='1890';
        vb_a_posttitle='Dice-Roller Testing';
        vb_a_data='general';
        vb_a_security='';
        document.write(unescape("%3Cscript src='http://pigeon1.vbanalytics.com:80/pigeon_m2.php' type='text/javascript'%3E%3C/script%3E"));
    </script>
    
    <center><a href="http://www.proboards.com/credit-purchase.cgi?mardigras3000.proboards.com">Click Here To Make This Board Ad-Free</a></center><br />
    <center>
    
    <script type="text/javascript">
    GA_googleFillSlot("Text_Links");
    </script>
    </center>
    <br/><center><font face="Verdana,Arial" size="-2">This Board Hosted For FREE By <a href="http://www.proboards.com/" target="_blank">ProBoards</a><br/>Get Your Own <a href="http://www.proboards.com/" target="_blank">Free Message Board</a>!</font></center>
    </body>
    </html>
    If I actually posted the wrong stuff, just let me know and I'll correct.

    Jennifer
    Last edited by mamajenn; 10-21-2009 at 11:13 PM.

  • #5
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    It may be just a regular expression problem, but someone else coming along looking at this post could get distracted by the ProBoard forum code (I have no idea what a Proboard is). One of the experienced javascript/regex here people may be able to fix this at a glance. The code itself isn't as complex as the problem description.

    The meat of the code appears to be in this section (lines 58-77 of the Jordan version):
    Code:
    if(rand!=null)
    {
    	n.innerHTML=n.innerHTML.replace(rand[0],"");
    	rand=rand[0].replace(/[^\d]/g,"");
    	dice=n.innerHTML.match(/\[dice\=\d+((\+|\-)\d+)?\]/ig);
    	if(dice!=null)
    	{
    		for(k=0;k<dice.length;k++)
    		{
    			numb=dice[k].match(/\d+((\+|\-)\d+)?/);
    			numb=numb[0].split(RegExp.$2);
    			unsigned = (RegExp.$2 == "+") ? true : false;
    			addon=numb.length>1?parseInt(numb[1],10):0;
    			if(!unsigned)addon = addon - addon * 2;
    			numb=parseInt(numb[0],10);
    			roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
    			n.innerHTML=n.innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:addon)+"</font></font></center></td></tr></table></td></tr></table> ");
    		}
    	}
    }
    There are only 2 regex and a few array index references. I suspect something isn't quite right in one of those.
    Are you a Help Vampire?

  • #6
    New to the CF scene
    Join Date
    Oct 2009
    Location
    Pacific Northwest
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you so much, Tom. Yes, I'm sure you're right. My description is far more complicated than the code is. Jordan's revisions were all done in just a few minutes, it seemed. If I should contact someone specific here at CodingForums please let me know. If not, I'll just keep checking back and be on the look out for any ways I can possibly help :}

    Jennifer

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    I am afraid that in spite of the explanation I do not understand what the idea of the thing is. Can the random numbers (dies) take values other than 1-6? How do the bonuses and penalties come about and who awards them? How do these modifiers affect the result? Without the ability to test the code in action I find it impossible to identify the supposed bug, although I am sure that tomws's diagnosis is right.

  • #8
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Here's some code to experiment with. This is the for loop that runs from lines 65 through 75 in the Jordan version. I can't say that it will fix all of your problems, but it seems to handle multiple digit faces. No idea if anything actually calculates correctly since I can't test that.

    Before making changes to your code, make sure you can revert to the original version if something breaks.

    EDIT: Give me a minute more. I forgot I tweaked the output line. Let me fix that up and I'll submit a new post.
    Last edited by tomws; 10-21-2009 at 06:12 PM. Reason: line breaks and bad code
    Are you a Help Vampire?

  • #9
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I think I repaired the output line. Try this one instead of the previous block.
    Code:
            for(k=0;k<dice.length;k++)
            {
                numb=dice[k].match(/\d+(([\+|\-])\d+)?/);
                modifiersign=numb[2] ? numb[2] : null;
                numb=modifiersign ? numb[0].split(modifiersign) : numb[0];
                unsigned = (modifiersign == "+") ? true : false;
                addon=typeof(numb)=='object'&&(numb instanceof Array) ? parseInt(numb[1],10) : 0;
                if(!unsigned)addon = addon - addon * 2;
                numb=parseInt(numb[0],10);
                roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
                n.innerHTML=n.innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:(addon != 0 ? addon : ''))+"</font></font></center></td></tr></table></td></tr></table> ");
            }
    Are you a Help Vampire?

  • #10
    New to the CF scene
    Join Date
    Oct 2009
    Location
    Pacific Northwest
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Can the random numbers (dies) take values other than 1-6? How do the bonuses and penalties come about and who awards them? How do these modifiers affect the result? Without the ability to test the code in action I find it impossible to identify the supposed bug, although I am sure that tomws's diagnosis is right.
    I'm sorry, Philip. This is my first time working with code that is beyond me and I've never had to ask for help before. I will try to be more *specifically* verbose

    Users can give their die any value (any number of sides) they can imagine, even ones not found on real dice.

    The users also manually type in their bonuses and/or penalties as awarded by me, the big mean teacher

    The modifiers modify the roll of the multi-sided die. For instance, is a user uses this command [dice=6] (that's with no modifier) he might have a result of any number between 1 and 6. But if the user uses the command [dice=6+2] he can get any result between 3 and 8. Meaning he can get any result that is possible rolling one six-sided die and adding 2 to that roll. Likewise, if using the command [dice=6-2], the result can be -1 to 8.

    There is a forum running the script for me while I try to find help. They have a thread just for the roller where you can test the script if you wish. If you'd like me to register an account for you (it's just the standard with activation sent to you through email), please let me know.
    http://www.mardigras3000.proboards.c...lay&thread=330

  • #11
    New to the CF scene
    Join Date
    Oct 2009
    Location
    Pacific Northwest
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Okay, Tom. I replaced the "meat" in Jordan's code with the code you supplied. I installed the new altered code at the forum. The little button that automatically inserted the default command was gone. When I typed in the command manually, nothing happened. It's as if the script is no longer recognized. When posting the post it simply displays the command line instead of a generated result.

    I have reverted to Jordan's code.

    Should I register a guest account at the forum and PM a password? Maybe if you saw the code in action?

    Jennifer

    Edit: Went ahead for both Philip and Tom. Created the account "dicetester" at the gaming forum that's letting me test the script. P/w is "tester" I'll delete the account once you're done with it. Access to the thread where you can run the script is:

    http://www.mardigras3000.proboards.c...lay&thread=330
    Last edited by mamajenn; 10-21-2009 at 11:41 PM.

  • #12
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Well, I'm lost. The code does something on that site, but I have no idea how it's tied in behind the scenes. All I see is that the form's action is pointing back to the thread itself (index.cgi).

    The source shows the formatted die, not the special markup, so something must be happening in the form handling portion of the page loads - possibly even before the post is submitted to the database. I really don't know what's happening. The logic is in a black box and can't be observed, as far as I can tell.

    FWIW, though, it's not the duoble digit numbers that are broken - they work on that site when used with a modifier.
    Are you a Help Vampire?

  • Users who have thanked tomws for this post:

    mamajenn (10-22-2009)

  • #13
    New to the CF scene
    Join Date
    Oct 2009
    Location
    Pacific Northwest
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you so very much! So, the code is different now (after Jordan's work). It *requires* a modifier. I hadn't thought of that because the code didn't originally force a modifier to be assigned. This "work-around" will allow me to move forward with the code. I'll just tell students to always add a +0 modifier.

    Two questions:

    When I have been told that the code is "messy" and should be "tabbed out," what does this mean and can I do it? (Does a tutorial exist somewhere? I am more than willing to do it.)

    I have changed the code now to post a 20-sided die as the default (instead of the 6-sided default in the original code). Is there a way that you can see that I could add a default modifier?

    Thank you again, Tom.

    Jennifer
    Last edited by mamajenn; 10-22-2009 at 02:07 AM. Reason: Added another question.

  • #14
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Yes, the "tabbing out" is something you could do, but it's more a matter of learning convention. Helps greatly with code readability. I've added tabs to Jordan's version above:
    Code:
    <style type="text/css">
    .dicebg {background-color: FFFFFF;border:solid 2px #000000;}
    .dicefont {background-color: FFFFFF;color: 000000; font-weight:bold;}
    </style>
    <script>
    //Dice Rolls In Posts v1.1 updated by Jordan October 2009
    
    //Copyright 4-23-2007 ~Wonder
    //May be reposted anywhere as long as this header remains in tact
    
    //Do you want the dice to line of horizontally(true) or vertically(false)
    diceAlignment=true;
    
    //Enter URL of the image you want to appear as the dice ubbc button
    UBBCdiceImage="http://img100.imageshack.us/img100/6118/diceicon9rx.gif";
    
    //Enter the default # of sides
    defaultSides=6;
    
    //Enable dice in preview? true or false
    enablePreview=true;
    
    
    
    rs="";mainForm="";
    if(document.postForm)
    {
    	mainForm=document.postForm;
    	if(location.href.match(/action\=modifypost/)){enablePreview=true;}
    	mainForm.color.parentNode.innerHTML+="<a href=javascript:add(\"[dice="+defaultSides+"]\",\"\")><img src=\""+UBBCdiceImage+"\" alt=\"Insert Dice Roll\" border=\"0\"></a>";
    	mainForm.onsubmit=addRand;
    	mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
    	rs=RegExp.$1; rs=(/\[rand\=/.test(rs))?rs:"";
    	if(location.href.match(/quote\=\d+/))
    	{
    		mainForm.message.value=mainForm.message.value.replace(/(\[dice\=\d+\])/ig,"");
    		rs="";
    	}
    }
    else if(location.href.match(/action\=display/))
    {
    	ta=document.getElementsByTagName("textarea");
    	if(ta.length>0 && ta[0].name=="message")
    	{
    		mainForm=ta[0].parentNode;
    		mainForm.onsubmit=addRand;
    	}
    }
    
    
    
    ///////////////////////
    if(location.href.match(/action\=(display|pmview|recent|userrecentposts|gotopost|search|calendarview)/) || (!location.href.match(/action\=/) && document.postForm && enablePreview))
    {
    	hr=document.getElementsByTagName("hr");
    	for(i=0;i<hr.length;i++)
    	{
    		if(typeof(hr[i].parentNode)!="undefined" && hr[i].parentNode.tagName=="TD" && typeof(hr[i].parentNode.lastChild)!="undefined" && typeof(hr[i].parentNode.lastChild.lastChild)!="undefined" && hr[i].parentNode.lastChild.lastChild.nodeType!=1)
    		{
    			n=hr[i].parentNode.lastChild;
    			rand=n.innerHTML.match(/\[rand\=\d+\]/);
    			if(rand!=null)
    			{
    				n.innerHTML=n.innerHTML.replace(rand[0],"");
    				rand=rand[0].replace(/[^\d]/g,"");
    				dice=n.innerHTML.match(/\[dice\=\d+((\+|\-)\d+)?\]/ig);
    				if(dice!=null)
    				{
    					for(k=0;k<dice.length;k++)
    					{
    						numb=dice[k].match(/\d+((\+|\-)\d+)?/);
    						numb=numb[0].split(RegExp.$2);
    						unsigned = (RegExp.$2 == "+") ? true : false;
    						addon=numb.length>1?parseInt(numb[1],10):0;
    						if(!unsigned)addon = addon - addon * 2;
    						numb=parseInt(numb[0],10);
    						roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
    						n.innerHTML=n.innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:addon)+"</font></font></center></td></tr></table></td></tr></table> ");
    					}
    				}
    			}
    		}
    	}
    }
    function addRand()
    {
    	mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
    	if((rs.length==0 && mainForm.message.value.match(/(\[dice\=\d+((\+|\-)\d+)?\])/)) && (enablePreview==true || (enablePreview==false && mainForm.nextaction.value=="post")))
    	{
    		mainForm.message.value+="[rand="+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+( Math.random()+"").replace(/0\./,"")+"]";
    	}
    	else
    	{
    		mainForm.message.value+=rs;
    	}
    	disable(mainForm);
    }
    </script>
    Be sure to update that with any changes you've already made.

    Since I don't know how all of this is wired up, I'm not really sure where to put a default modifier. If I was guessing, I'd try it in this line (about line 30 of Jordan's version):
    Code:
    mainForm.color.parentNode.innerHTML+="<a href=javascript:add(\"[dice="+defaultSides+"+"+defaultModifier+"]\",\"\")><img src=\""+UBBCdiceImage+"\" alt=\"Insert Dice Roll\" border=\"0\"></a>";
    And then add the defaultModifier variable maybe up under the defaultSides variable and assign it, say, 0.
    Are you a Help Vampire?

  • The Following 2 Users Say Thank You to tomws For This Useful Post:

    mamajenn (10-22-2009), Philip M (10-22-2009)

  • #15
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    Jennifer - I have to say that like Tomws I am baffled and simply do not understand how the scripts work. I would like to have been able to help - but I am afraid that this one is just too difficult for me.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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