Initial Context: Thing Alternate Context: None Fields Finalized? Yes Where Used: Components Procedure Use: "xactbuy" type, "transact" context, "pick" context
The TransactBuy script utilizes the following special symbols:
reject (String) Entry: The empty string to indicate success.
Exit: If non-empty, indicates the transaction was rejected, with the contents being shown to the user as the explanation for the failure.
special (Number) Entry: Value specified with the definition of the portal to allow different behaviors based on usage.
The TransactBuy script is invoked at the completion of a "buy" transaction. The purpose of the script is to appropriately complete the purchase. It achieves this by retrieving the details of the transaction from the special "transaction" pick. Once the information is retrieved, whatever actions comprise the purchase can be performed, such as subtracting the cost of the purchase from the cash possessed by the character.
When invoked, the initial context is the thing being purchased. However, this script will primarily be interested in the contents of the "transaction" pick, which can be accessed via the "transaction" context. The transaction pick will contain all of the particulars specified by the user for the purchase.
The contents of the transaction pick will depend entirely on the "buy" template utilized. Whatever portals are presented within the buy template will dictate the values of fields within the transaction pick.
The engine will retrieve the final quantity purchased from the "xactQty" field of the transaction pick. The value of this field will dictate the actual quantity assigned to the new pick that is purchased.
Please see the separate documentation for further details on using transactions.
The TransactBuy script below shows the behavior of the Sample data files for handling gear transactions. If the gear is free, the transaction is completed without any changes to the character's cash. Otherwise, the appropriate cash is deducted from the proper usage pool, with a rejection error being reported if there is insufficient cash.
~if we're buying for free, no cash should be touched, so get out if (hero.transact.field[xactIsFree].value <> 0) then done endif ~get the cash amount specified by the user var cash as number cash = hero.transact.field[xactCash].value ~if no cash amount was given, get the standard total cost for the purchase if (cash = 0) then cash = hero.transact.field[xactQty].value * hero.transact.field[xactEach].value endif ~if we don't have enough cash to make the purchase, reject the transaction if (cash > herofield[acCashNet].value) then @reject = "You lack sufficient cash to purchase the item." done endif ~subtract the amount from the current pool of cash perform hero.usagepool[TotalCash].adjust[-cash]