Difference between pages "Installation" and "Equip"

From Kolmafia
(Difference between pages)
Jump to navigation Jump to search
(Total rewrite for Java 11+ codebase)
 
(add new overloads for equipping familiars directly and code example)
 
Line 1: Line 1:
{{TOCright}}
+
{{
The latest source build can be downloaded from [http://builds.kolmafia.us/ builds.kolmafia.us] or the [https://github.com/kolmafia/kolmafia/releases GitHub releases page].
+
#vardefine:name|equip}}{{
 +
#vardefine:return_type|boolean}}{{
  
The GitHub releases page contains both the KoLmafia-xxxxx.jar java binaries and installers for an experimental version that includes a bundled version of Java.  If you use the installers, they manage the Java dependency listed below, but it can be more difficult to troubleshoot issues. 
+
FunctionPage|
 +
name={{#var:name}}|
  
== Dependencies==
+
function1={{Function|
 +
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|item|equip_me}}|
 +
}}|
  
===Java 11 or better (Java 17 recommended)===
+
function2={{Function|
KoLmafia depends on finding Java 11 or better.  The recommended version is linked at the top of every page of kolmafia.us. 
+
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|item|equip_me}}|
 +
parameter2={{Param|slot|where}}|
  
If you do not have a recent version of Java, the recommended version (as of this writing) is [https://adoptium.net/index.html Java 17]. 
+
}}|
  
====Testing your Java installation====
+
function3={{Function|
From a Command Prompt (or Terminal) window, enter <code>java -version</code>
+
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|slot|where}}|
 +
parameter2={{Param|item|equip_me}}|
 +
p1desc={{Pspan|equip_me}} is the item to equip|
 +
p2desc={{Pspan|where}} is the slot to place the item in|
 +
}}|
  
If that returns something like this, you should be good to go.
+
function4={{Function|
 +
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|item|equip_me}}|
 +
parameter2={{Param|familiar|fam}}|
  
<code>Michaels-MBP:~ mcroft$ java -version<br />openjdk version "16.0.1" 2021-04-20<br />OpenJDK Runtime Environment Zulu16.30+15-CA (build 16.0.1+9)<br />OpenJDK 64-Bit Server VM Zulu16.30+15-CA (build 16.0.1+9, mixed mode, sharing)</code>
+
}}|
==== Troubleshooting Java====
 
Please be aware that some older versions of Java do not get completely replaced when installing a newer version.  Usually this happens with Java 8 JRE and Java 11+ JDKs.  If that makes no sense, just delete Java 8.
 
  
If you get a message like this:<code>Error: A JNI error has occurred, please check your installation and try again.</code> Please [https://kolmafia.us/threads/java-11-now-required-for-kolmafia-java-17-recommended.26579/ read this announcement].
+
function5={{Function|
 +
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|familiar|fam}}|
 +
parameter2={{Param|item|equip_me}}|
 +
p1desc={{Pspan|equip_me}} is the item to equip|
 +
p2desc={{Pspan|where}} is the familiar to equip the item on|
 +
}}|
  
===HiDPI Support===
+
function_description=Attempts to equip the item {{pspan|equip_me}} in the slot {{pspan|where}} if specified, and returns true if the operation was successful, and false if it was not. If parameter {{pspan|where}} is not specified, it defaults to the "standard" place for such an item (main-hand for 1-handed weapons, first open slot for accessories or acc1 if no slots are open).
 +
*If {{pspan|where}} is specified and {{pspan|equip_me}} is set to $item[none], this function will unequip whatever is in slot {{pspan|where}} and return true.
 +
*If {{pspan|where}} is not specified and {{pspan|equip_me}} is set to $item[none], the function aborts and you get a funky error because that makes no sense.
 +
*If you cannot equip {{pspan|equip_me}}, or {{pspan|where}} is supplied and the item cannot be used in that slot, you will be given an error message and this function will return false.
 +
*The overload for equipping a familiar with {{pspan|equip_me}} can be used to equip familiars with familiar equipment without requiring the familiar to be your currently active familiar. This will return false if you don't have (or can't use) the familiar or if the familiar can't equip the item you are attempting to equip.
 +
&nbsp;|
  
The default builds target Java  and use Java Swing to provide its user interface. This means that Java Swing support for HiDPI on Linux is not present. Java 9's Swing includes support for HiDPI. Thus to have HiDPI support one needs to compile it targeting Java 9. To do so, checkout the source from the sourceforge repository using subversion. Ensure that you have some version of JDK 9 installed and configured on your computer as the default java compiler, and also an up-to-date version of Apache Ant. Change the line in 'build.properties' from 'target="1.6"' to 'target="1.9"'. This compiles the source into a version that has support for HiDPI; the built jar will be located at the 'dist' folder. Finally, execute the '.jar' file with an option set as follows: 'java -Dsun.java2d.uiScale=<multiplier> -jar <jarfile>'; e.g. in my case, '<multiplier>' should be '2'.
+
code1={{CodeSample|
 +
title=Code Sample|
 +
description=Equips the Swashbuckling Getup carefully to ensure that the parrot is in the second accessory slot.|
 +
code=
 +
<syntaxhighlight>
 +
equip($item[eyepatch]);
 +
equip($item[swashbuckling pants]);
 +
equip($slot[acc2], $item[stuffed shoulder parrot]);
 +
</syntaxhighlight>
 +
}}|
  
[[Category:Tech Support]]
+
code2={{CodeSample|
[[Category:New User Help]]
+
title=Code Sample|
 +
description=Equips the blue plate on the Shorter-Order Cook without switching to it first.|
 +
code=
 +
<syntaxhighlight>
 +
equip($familiar[shorter-order cook], $item[blue plate]);
 +
</syntaxhighlight>
 +
}}|
 +
 
 +
see_also={{SeeAlso|can_equip|equipped_amount|equipped_item|have_equipped}}|
 +
cli_equiv=The CLI commands "equip" (and others, for specific slots) function similarly.|
 +
}}
 +
 
 +
[[Category:Equipment]]

Latest revision as of 16:49, 12 April 2024

Function Syntax

boolean equip(item equip_me )

boolean equip(item equip_me ,slot where )

boolean equip(slot where ,item equip_me )

  • equip_me is the item to equip
  • where is the slot to place the item in

boolean equip(item equip_me ,familiar fam )

boolean equip(familiar fam ,item equip_me )

  • equip_me is the item to equip
  • where is the familiar to equip the item on

Attempts to equip the item equip_me in the slot where if specified, and returns true if the operation was successful, and false if it was not. If parameter where is not specified, it defaults to the "standard" place for such an item (main-hand for 1-handed weapons, first open slot for accessories or acc1 if no slots are open).

  • If where is specified and equip_me is set to $item[none], this function will unequip whatever is in slot where and return true.
  • If where is not specified and equip_me is set to $item[none], the function aborts and you get a funky error because that makes no sense.
  • If you cannot equip equip_me, or where is supplied and the item cannot be used in that slot, you will be given an error message and this function will return false.
  • The overload for equipping a familiar with equip_me can be used to equip familiars with familiar equipment without requiring the familiar to be your currently active familiar. This will return false if you don't have (or can't use) the familiar or if the familiar can't equip the item you are attempting to equip.

 

Code Sample

Equips the Swashbuckling Getup carefully to ensure that the parrot is in the second accessory slot.

equip($item[eyepatch]);
equip($item[swashbuckling pants]);
equip($slot[acc2], $item[stuffed shoulder parrot]);

Code Sample

Equips the blue plate on the Shorter-Order Cook without switching to it first.

equip($familiar[shorter-order cook], $item[blue plate]);

CLI Equivalent

The CLI commands "equip" (and others, for specific slots) function similarly.

See Also

can_equip() | equipped_amount() | equipped_item() | have_equipped()