|
Dahlia Genira
Registered User
Join date: 29 May 2009
Posts: 8
|
05-29-2009 21:52
Hello!
I am trying to get a script to do a discount and have the discount be a percentage (%), I can get the script to - $L from the price but can not get it to do a % of the price. Can someone please explain to me how to have a script do this? Thank you all so much!
|
|
Klaire Larnia
Learner, be gentle....
Join date: 2 Jun 2008
Posts: 41
|
05-29-2009 22:35
From: Dahlia Genira Hello!
I am trying to get a script to do a discount and have the discount be a percentage (%), I can get the script to - $L from the price but can not get it to do a % of the price. Can someone please explain to me how to have a script do this? Thank you all so much! Can you not do a simple maths equation? And say something like: Price = Original * 0.75 that would give you a 25% discount. then all you need to do is round the figure up/down to make sure it is a whole number which can be done if you look here: http://lslwiki.net/lslwiki/wakka.php?wakka=llRoundThat is how I would approach it personally.
_____________________
Klaire xXx =^.^= xXx
|
|
Dahlia Genira
Registered User
Join date: 29 May 2009
Posts: 8
|
05-30-2009 01:09
Maybe I am attempting to do this wrong, but when done this way the pay box is empty. Here is the code I have for the discount:
string p = llList2String(notecardList,(index*4)+2); string disc = llList2String(notecardList,(index*4)+3); price2 = (integer)p * (integer)disc; llRound(price2); llSetPayPrice(PAY_HIDE, [price2, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
string p is the original price and string disc is the % off I want to do.
|
|
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
|
05-30-2009 02:17
From: Dahlia Genira Maybe I am attempting to do this wrong, but when done this way the pay box is empty. Here is the code I have for the discount:
string p = llList2String(notecardList,(index*4)+2); string disc = llList2String(notecardList,(index*4)+3); price2 = (integer)p * (integer)disc; llRound(price2); llSetPayPrice(PAY_HIDE, [price2, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
string p is the original price and string disc is the % off I want to do.
float calc = amount + 0.0; float a = calc * ( percent/100 ); then convert your float to integer price_f=(integer)a; llSetPayPrice(PAY_HIDE, [price_f, PAY_HIDE, PAY_HIDE, PAY_HIDE]); PS: i dont know where you pull out the pay moment, but this is how i work with the % discounts in my scripts
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-30-2009 11:17
price2 = llRound( (float)disc * (float)p );
when you use (integer) casts, you are removing anything after the decimal point...
if you store your discount as %off rather than %total then subtract disc from one before applying, and if it's stored as a whole integer, then divide by 100 first.
ex
disc = 15 price2 = llRound( (1 - (float)disc / 100.0) * (float)p );
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|