TransactSell Script: Difference between revisions

From HLKitWiki
Jump to navigationJump to search
New page: {{context|Kit Reference|Script Types}} ==Technical Details== :{| class="scripttable" |class="leftnormal"|Initial Context: |Pick |- |Alternate Context: |None |- |Fields F...
 
 
(4 intermediate revisions by one other user not shown)
Line 12: Line 12:
|Fields Finalized?
|Fields Finalized?
|Yes
|Yes
|-
|Where Used:
|[[Component Element (Data)|Components]]
|-
|Procedure Use:
|"xactsell" type, "transact" context, "pick" context
|-
|-
|}
|}
Line 18: Line 24:


:{| class="infotable"
:{| class="infotable"
|class="leftnormal"|reject
|class="leftnormal"|isprimary
|Entry: The empty string to indicate success.<br>
|(Number) Entry: Indicates whether this is the [[Primary Transaction|primary transaction]] taking place (non-zero) or not (zero).<br>
Exit: Ignored.
|-
|reject
|(String) Entry: The empty string to indicate success.<br>
Exit: If non-empty, indicates the transaction was rejected, with the contents being shown to the user as the explanation for the failure.
Exit: If non-empty, indicates the transaction was rejected, with the contents being shown to the user as the explanation for the failure.
|-
|-
|special
|special
|Entry: Value specified with the definition of the portal to allow different behaviors based on usage.<br>
|(Number) Entry: Value specified with the definition of the portal to allow different behaviors based on usage.<br>
Exit: Ignored.
Exit: Ignored.
|-
|-
Line 30: Line 40:
==Description==
==Description==


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.
The TransactSell script is invoked at the completion of a "sell" transaction. The purpose of the script is to appropriately complete the sale. It achieves this by retrieving the details of the transaction from the special "transaction" pick. Once the information is retrieved, whatever actions comprise the sale can be performed, such as adding the proceeds of the sale to 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.
When invoked, the initial context is the pick that is being sold. 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 sale.


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 contents of the transaction pick will depend entirely on the "sell" template utilized. Whatever portals are presented within the sell 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.
The engine will retrieve the final quantity sold from the "xactQty" field of the transaction pick. The value of this field will dictate the actual quantity deducted from the pick that is sold. If the entire quantity of the pick is sold, the pick is deleted.


Please see the separate documentation for further details on [[Transactions|using transactions]].
Please see the separate documentation for further details on [[Transactions|using transactions]].
Line 42: Line 52:
==Example==
==Example==


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.
The TransactSell script below shows the behavior of the Sample data files for handling gear transactions. The cash value specified by the user is retrieved and added back to the usage pool the manages the character's cash.


<pre>
<pre>

Latest revision as of 23:33, 1 March 2011

Context: HL Kit &#133; Kit Reference &#133; Script Types 

Technical Details

Initial Context: Pick
Alternate Context: None
Fields Finalized? Yes
Where Used: Components
Procedure Use: "xactsell" type, "transact" context, "pick" context

The TransactSell script utilizes the following special symbols:

isprimary (Number) Entry: Indicates whether this is the primary transaction taking place (non-zero) or not (zero).

Exit: Ignored.

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.

Exit: Ignored.

Description

The TransactSell script is invoked at the completion of a "sell" transaction. The purpose of the script is to appropriately complete the sale. It achieves this by retrieving the details of the transaction from the special "transaction" pick. Once the information is retrieved, whatever actions comprise the sale can be performed, such as adding the proceeds of the sale to the cash possessed by the character.

When invoked, the initial context is the pick that is being sold. 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 sale.

The contents of the transaction pick will depend entirely on the "sell" template utilized. Whatever portals are presented within the sell template will dictate the values of fields within the transaction pick.

The engine will retrieve the final quantity sold from the "xactQty" field of the transaction pick. The value of this field will dictate the actual quantity deducted from the pick that is sold. If the entire quantity of the pick is sold, the pick is deleted.

Please see the separate documentation for further details on using transactions.

Example

The TransactSell script below shows the behavior of the Sample data files for handling gear transactions. The cash value specified by the user is retrieved and added back to the usage pool the manages the character's cash.

~get the cash amount specified by the user
var cash as number
cash = hero.transact.field[xactCash].value

~add the amount to the current pool of cash
perform hero.usagepool[TotalCash].adjust[cash]