help with function

Thoughts, Help, Feature Requests

Moderators: dorpond, Azhrei, giliath

Post Reply
leonpoi
Kobold
Posts: 2
Joined: Sat Jan 03, 2009 4:28 pm

help with function

Post 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?

User avatar
giliath
RPTools Founder
Posts: 275
Joined: Tue Jan 31, 2006 11:10 am
Location: Austin, TX

Re: help with function

Post 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
~Giliath

leonpoi
Kobold
Posts: 2
Joined: Sat Jan 03, 2009 4:28 pm

Re: help with function

Post 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.

Post Reply

Return to “DiceTool”