Page 1 of 1

help with function

Posted: Sat Jan 03, 2009 6:27 pm
by leonpoi
Could someone help me out with this?

I've edited the function file and included:

Code: Select all

function attack(hit)	{	
	var die = 20;
		
	row.setLabel("d20");	
	var roll = Math.floor(Math.random() * die) + 1;
	
	if (roll <= hit) row.setBackgroundColor(0, 255, 0);	
	
	return parseInt(roll);	
}
The function works, but my problems are two-fold:
1. the result of the roll is a floating point number (like when you roll using the cumulative setting) and not just an integer like when you roll multiple dice
2. if the last roll in the list is highlighted then the row separating rolls is also highlighted green

Image

I assume that these 2 problems are caused by something in dicetool that I cannot modify in the functions file, but can anyone help me fix these 2 problems?

Re: help with function

Posted: Tue Jan 13, 2009 3:41 pm
by giliath
I believe the results of javascript functions are always floating point numbers, but it has been a long time since this code was messed with.

The coloration issue seems like a bug in DiceTool, so I doubt there is a work around.

~David

Re: help with function

Posted: Thu Jan 15, 2009 6:44 am
by leonpoi
giliath wrote:I believe the results of javascript functions are always floating point numbers, but it has been a long time since this code was messed with.

The coloration issue seems like a bug in DiceTool, so I doubt there is a work around.

~David
Thanks. I've never programmed in javascript before this but I did read that results of javascript functions are always floating point numbers. I tried some of the parsing functions and some other things, but nothing worked.

Oh well.