TransactSetup Script
Context: HL Kit … Kit Reference … Script Types
Technical Details
The TransactSetup script utilizes the following special symbols:
isbuy Entry: Indicates whether the transaction is buy (non-zero) or sell (zero).
Exit: Ignored.
ispick Entry: Indicates whether the context is a pick (non-zero) or a thing (zero).
Exit: Ignored.
special Entry: Value specified with the definition of the portal to allow different behaviors based on usage.
Exit: Ignored.
Description
The TransactSetup script is invoked at the beginning of a transaction, whether it be a buy or sell operation. When invoked, the initial context is either the thing being purchased or the pick being sold. The script can also access the separate "transaction" context to manipulate the transaction pick. In fact, the role of the TransactSetup script is to appropriately configure the transaction pick so that everything is properly presented and handled for the user.
The engine will automatically setup the transaction pick with a few pieces of information. It's up to you to setup the remaining details for how you want the transaction to be handled. The automatic behaviors of the engine differs for buying and selling operations, so both are outlined separately below.
Setup logic for a "buy" transaction:
- The "xactName" field is set to the name of the thing being purchased
- The "xactLimit" field is set to no limit
- The "xactQty" field is set to the lot size for the thing being purchased
- The TransactSetup script is invoked
Setup logic for a "sell" transaction:
- The "xactName" field is set to the name of the thing being purchased
- The "xactLimit" field is set to the total quantity possessed for the pick
- The "xactQty" field is set to the total quantity possessed
- The TransactSetup script is invoked
Within the TransactSetup script, the "xactEach" field must always be set to the proper unit cost for the item being purchased or sold. Other fields may be setup as you deem appropriate to the transaction requirements.
Please see the separate documentation for further details on using transactions.
NOTE! The TransactSetup script is only invoked when buying and selling items that belong to a component that is stackable. If the component does not support stacking, the
Example
The Change script below shows how the calculation of XP cost is performed for the World of Darkness game system. This example is edited down to show the core behaviors, as the real script handles additional factors.
~start by assuming our unit cost is the cost of one item var cost as number cost = field[grCost].value ~setup the unit cost for the item hero.transact.field[xactEach].value = cost ~zero out the cash amount to be paid (implying use of the standard cost) hero.transact.field[xactCash].value = 0 ~if the item is gear, setup whether the item holds other gear if (isgear <> 0) then hero.transact.field[xactHolder].value = gearcount endif