Question about setFillColor...Not working properly when setting random values.

Am I doing something wrong?

object:setFillColor(math.random(0, 256), math.random(0, 256), math.random(0, 256))

This will only set my object to white. I’ve used this method before and it worked perfectly fine. Not sure what the problem is now.

I read an article about setFillColor changing in Graphics 2.0. I tried setting the random values to 0.0 and 1.0 but that sets it to white as well. Anyone want to shed some light on this?

Yep:

object:setFillColor(math.random(0, 255)/255, math.random(0, 255)/255, math.random(0, 255)/255)

That worked. Thanks a lot! :wink:

BTW I was looking at your templates today. Are they converted to Graphics 2.0?

My apologies for going off subject.

All products description (on Sellfy) should mention whether I’ve converted them to Graphics 2.

For the most part, the answer is, “Yes.”

https://sellfy.com/p/eO2t/

I would recommend:

obj:setFillColor( math.random(), math.random(), math.random() )

When calling math.random() with out a parameter you get a number between 0 and 1 which saves you having to do the three divides.  Plus internally math.random wants to naturally return a value between 0 and 1 and to get an integer range, it has to do more calculations to get you that range.

Rob

Yep:

object:setFillColor(math.random(0, 255)/255, math.random(0, 255)/255, math.random(0, 255)/255)

That worked. Thanks a lot! :wink:

BTW I was looking at your templates today. Are they converted to Graphics 2.0?

My apologies for going off subject.

All products description (on Sellfy) should mention whether I’ve converted them to Graphics 2.

For the most part, the answer is, “Yes.”

https://sellfy.com/p/eO2t/

I would recommend:

obj:setFillColor( math.random(), math.random(), math.random() )

When calling math.random() with out a parameter you get a number between 0 and 1 which saves you having to do the three divides.  Plus internally math.random wants to naturally return a value between 0 and 1 and to get an integer range, it has to do more calculations to get you that range.

Rob