These forums are CLOSED. Please visit the new forums HERE
taking money |
|
|
Danielz Shackle
Registered User
Join date: 30 Apr 2006
Posts: 100
|
05-20-2006 06:24
if im selling something, and i want them to be able to take their money, but need it to be exact amounts, say 20L, what would the math part of script be to make this work. I see in wiki page http://secondlife.com/badgeo/wakka.php?wakka=ExampleMoney how to take exactly 20, but how do i do multiples of 20 only, with no inbetween amounts? i should know this, but i didnt sleep last night to try to finish, id apreccate any help.
|
|
Danielz Shackle
Registered User
Join date: 30 Apr 2006
Posts: 100
|
one way
05-20-2006 06:49
the only way i can think of would be to
take the amount they pay me (exp 185) divide by 20, then floor it (would give me 9) then take what they paid minus (floored int*20) (185-180) and refund difference this seems like alot of steps extra though, is there an easier way |
|
Top Tank
Wasted Jack
Join date: 5 Dec 2005
Posts: 12
|
05-20-2006 06:58
CODE integer PRICE_PER_UNIT = 20; |
|
Draco18s Majestic
Registered User
Join date: 19 Sep 2005
Posts: 2,744
|
05-20-2006 07:00
the only way i can think of would be to take the amount they pay me (exp 185) divide by 20, then floor it (would give me 9) then take what they paid minus (floored int*20) (185-180) and refund difference this seems like alot of steps extra though, is there an easier way Yep, if you look at Top's code, you forgot about the % (modulous) opperator, it takes care of steps 2 and 3. |
|
Danielz Shackle
Registered User
Join date: 30 Apr 2006
Posts: 100
|
05-20-2006 07:38
that made the first steps allot easier. but it brings up one more question for me, i guess ive always done it the longer way, never the way u scripted it. What sows how many units they did buy?
is it an integer im not seeing, or how do i know they bought 4@20? |
|
Top Tank
Wasted Jack
Join date: 5 Dec 2005
Posts: 12
|
05-20-2006 12:04
(iAmount / PRICE_PER_UNIT) would give you the amount of units purchased.
|
|
Danielz Shackle
Registered User
Join date: 30 Apr 2006
Posts: 100
|
damn, have another question now
05-21-2006 19:26
okay, those both work perfect, but it leads me into another question. if i put that in a state, the pay function seems to only work in that state. which is good for the project im working on, but for future use, is their a way to make it work on all states, short of haveing to put it into each state. can i use it as a global function somehow?
|
|
Draco18s Majestic
Registered User
Join date: 19 Sep 2005
Posts: 2,744
|
05-21-2006 20:12
if you create an actual function, yes, you can put llGiveMoney in there.
|
|
Top Tank
Wasted Jack
Join date: 5 Dec 2005
Posts: 12
|
05-22-2006 05:49
True. You can have global functions (in fact, user-defined functions are always global) but you can't have global events. This means that you will still need to code a money() event block on each and every state you have in your script, but all of them can simply be a one-line call to one global function that will take care of actual processing of the payment.
CODE handlePayment(key kAgent, integer iAmount) I intentionally did not include a money() event handler in the default state. I believe it is good practice to use the default state only for initialization tasks and then change to another state after initialization is successful. In most cases, it is highly unlikely that a script would be able to accept and process money while it is still initializing. Not including a money() event handler in the default state would therefore ensure that money would not be prematurely accepted. |