Batch close: Difference between revisions
imported>Bale No edit summary |
Clarify what functions can be batched (with footnotes), based on looking at KoLmafia r20662 source code |
||
(10 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{#vardefine:name|batch_close}} | {{ | ||
{{#vardefine:return_type|boolean}} | #vardefine:name|batch_close}}{{ | ||
#vardefine:return_type|boolean}}{{ | |||
FunctionPage| | |||
name={{#var:name}}| | name={{#var:name}}| | ||
function1={{Function| | function1={{Function| | ||
Line 14: | Line 14: | ||
function_description= | function_description= | ||
After a batch_open | After a {{f|batch_open}}, certain functions that generate a server hit on each call are queued up, rather than executed immediately. When {{f|batch_close}} is called, it will then execute all of them at once (hopefully with fewer server hits).</p> | ||
<p>The functions that benefit from being batched include autosell | |||
<p>The functions that benefit from being batched include {{f|autosell}} as well as various put_X(), take_X() functions that move items to or from the display, shop, or stash. Most of the KoL interfaces for these are capable of transferring up to 11 items at once, but that can't otherwise be expressed in ASH. More details:</p> | |||
* Caution is required when using more than one batchable function in a single batch, since they won't be executed in the same order you wrote them. | * Caution is required when using more than one batchable function in a single batch, since they won't be executed in the same order you wrote them. | ||
** What happens in this case is that all instances of the first encountered function are executed, then all instances of the second encountered function, and so on. | ** What happens in this case is that all instances of the first encountered function are executed, then all instances of the second encountered function, and so on. | ||
** This should produce the expected results in cases such as a loop that pulls an item from storage, and then puts it in your closet. | ** This should produce the expected results in cases such as a loop that pulls an item from storage, and then puts it in your closet. | ||
*** Inside of a batch, all the pulls get processed at once, and then all the closet puts. | *** Inside of a batch, all the pulls get processed at once, and then all the closet puts. | ||
* put_X() and take_X() with the same source | * put_X() and take_X() with the same source ''can'' be used in the same batch as of [https://kolmafia.us/threads/13272-ash-batching-of-commands-will-now-save-up-and-batch-multiple-prefixes-of-the-s.14331/ r13272]. ([https://kolmafia.us/threads/improve-ash-batching.14329/ feature thread]) | ||
* Batches are accumulated on a per-script-invocation basis. | * Batches are accumulated on a per-script-invocation basis. | ||
** Having an open batch does not affect execution of any other script that's running at the same time. | ** Having an open batch does not affect execution of any other script that's running at the same time. | ||
** Any commands batched by a script that was aborted are discarded - they won't mysteriously be executed by the next script that calls batch_close | ** Any commands batched by a script that was aborted are discarded - they won't mysteriously be executed by the next script that calls {{f|batch_close}} | ||
<p>(Note: this function description taken in its entirety, with only slight formatting changes, from jasonharper's log notes on r7552.) | <p>Any failure of batched commands can be captured and tested via the return value of {{|batch_close}}, just as you'd normally check the return value of the individual functions being batched. However, there's no way to tell just how much progress had been made before the failure, so it's unlikely that a script could meaningfully continue after that point.</p> | ||
<p>(Note: this function description taken in its entirety, with only slight formatting changes, from jasonharper's log notes on r7552.)</p> | |||
<p>Note: Due to KoL's closet/storage interface revamp (aligns with KoLmafia r9252), closet- and storage-related operations can no longer be batched.</p> | |||
| | | | ||
code1={{CodeSample| | code1={{CodeSample| | ||
title=Code Sample| | title=Code Sample| | ||
description=This | description=This will remove all items from a characters closet. None of the items are removed until the batch is closed so that they can be removed in groups of 11 to minimize server hits.| | ||
code= | code= | ||
<syntaxhighlight> | <syntaxhighlight> | ||
batch_open(); | |||
// Check every item to see if there are any in the closet. | |||
foreach doodad in $items[] | |||
if(closet_amount(doodad)>0) | |||
take_closet(closet_amount(doodad), doodad); | |||
batch_close(); | |||
</syntaxhighlight>}}| | </syntaxhighlight>}}| | ||
see_also={{SeeAlso|batch_open}}| | see_also={{SeeAlso|batch_open}}| | ||
}} | }} | ||
==Functions that can be batched== | |||
While in batch mode, the following functions will postpone operations until the next {{f|batch_close}} call: | |||
* {{f|autosell}} | |||
* {{f|empty_closet}}<ref>While this function can be batched, doing so is not very useful in practice, since it only takes a single server request anyway.</ref> | |||
* {{f|put_closet}}<ref name="nonfunctional-closet-batch">While this function can be batched, each item transfer will still consume one request. This is due to changes in KoL's closet interface.[https://kolmafia.us/threads/new-hangks-and-closet-interface.6480]</ref> | |||
* {{f|put_display}} | |||
* {{f|put_shop}} | |||
* {{f|put_stash}} | |||
* {{f|reprice_shop}} | |||
* {{f|sell}} | |||
* {{f|take_closet}}<ref name="nonfunctional-closet-batch" /> | |||
* {{f|take_display}} | |||
* {{f|take_shop}} | |||
* {{f|take_stash}}<ref>While this function can be batched, each item transfer will still consume one request. This is due to limitations in KoL's clan stash interface. This limitation does not apply to {{f|put_stash}}.</ref> | |||
* {{f|take_storage}} | |||
[[Category:Miscellaneous Functions]] |
Latest revision as of 07:47, 14 March 2021
Function Syntax
boolean batch_close()
After a batch_open()
, certain functions that generate a server hit on each call are queued up, rather than executed immediately. When batch_close()
is called, it will then execute all of them at once (hopefully with fewer server hits).
The functions that benefit from being batched include autosell()
as well as various put_X(), take_X() functions that move items to or from the display, shop, or stash. Most of the KoL interfaces for these are capable of transferring up to 11 items at once, but that can't otherwise be expressed in ASH. More details:
- Caution is required when using more than one batchable function in a single batch, since they won't be executed in the same order you wrote them.
- What happens in this case is that all instances of the first encountered function are executed, then all instances of the second encountered function, and so on.
- This should produce the expected results in cases such as a loop that pulls an item from storage, and then puts it in your closet.
- Inside of a batch, all the pulls get processed at once, and then all the closet puts.
- put_X() and take_X() with the same source can be used in the same batch as of r13272. (feature thread)
- Batches are accumulated on a per-script-invocation basis.
- Having an open batch does not affect execution of any other script that's running at the same time.
- Any commands batched by a script that was aborted are discarded - they won't mysteriously be executed by the next script that calls
batch_close()
Any failure of batched commands can be captured and tested via the return value of {{|batch_close}}, just as you'd normally check the return value of the individual functions being batched. However, there's no way to tell just how much progress had been made before the failure, so it's unlikely that a script could meaningfully continue after that point.
(Note: this function description taken in its entirety, with only slight formatting changes, from jasonharper's log notes on r7552.)
Note: Due to KoL's closet/storage interface revamp (aligns with KoLmafia r9252), closet- and storage-related operations can no longer be batched.
Code Sample
This will remove all items from a characters closet. None of the items are removed until the batch is closed so that they can be removed in groups of 11 to minimize server hits.
batch_open();
// Check every item to see if there are any in the closet.
foreach doodad in $items[]
if(closet_amount(doodad)>0)
take_closet(closet_amount(doodad), doodad);
batch_close();
See Also
Functions that can be batched
While in batch mode, the following functions will postpone operations until the next batch_close()
call:
autosell()
empty_closet()
[1]put_closet()
[2]put_display()
put_shop()
put_stash()
reprice_shop()
sell()
take_closet()
[2]take_display()
take_shop()
take_stash()
[3]take_storage()
- ↑ While this function can be batched, doing so is not very useful in practice, since it only takes a single server request anyway.
- ↑ 2.0 2.1 While this function can be batched, each item transfer will still consume one request. This is due to changes in KoL's closet interface.[1]
- ↑ While this function can be batched, each item transfer will still consume one request. This is due to limitations in KoL's clan stash interface. This limitation does not apply to
put_stash()
.