In-game Functions: Difference between revisions

→‎Remove Item from Bank: Document solution for removing items with invalid quantities
(Use SyntaxHighlight)
(→‎Remove Item from Bank: Document solution for removing items with invalid quantities)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{V|1.1.1}}
{{V|1.1.2}}
In-game functions are responsible for most things in the game. It is possible to interact directly with them through the console. This can be used to add items, levels, GP and more. These functions can be executed though the console. To access the console open Developer Tools (usually by pressing F12) in your browser and navigate to the console. Then, simply paste the code in the input field and press enter. Most functions will require you to fill out variables in the code before executing them. Note that all code is case sensitive.
In-game functions are responsible for most things in the game. It is possible to interact directly with them through the console. This can be used to add items, levels, GP and more. These functions can be executed though the console. To access the console open Developer Tools (usually by pressing F12) in your browser and navigate to the console. Then, simply paste the code in the input field and press enter. Most functions will require you to fill out variables in the code before executing them. Note that all code is case sensitive.


Line 6: Line 6:
<div class="warningbox">You are playing around with the code of the game, as such if you make mistakes it is possible that could corrupt your game. It is highly recommended to '''BACKUP YOUR SAVE''' before running any in-game functions.</div>
<div class="warningbox">You are playing around with the code of the game, as such if you make mistakes it is possible that could corrupt your game. It is highly recommended to '''BACKUP YOUR SAVE''' before running any in-game functions.</div>


==Using In-game Functions On Steam==
==Using In-game Functions On Steam, Android, or iOS==
Players can use the [https://mod.io/g/melvoridle/m/devconsole dev.Console mod] to execute these commands within the Steam version of Melvor Idle.
Players can use the [https://mod.io/g/melvoridle/m/devconsole dev.Console mod] to execute these commands within the Steam, Android, and iOS versions of Melvor Idle.


== Add Item to Bank ==
== Add Item to Bank ==
Line 24: Line 24:
| logLost || boolean || Yes || false || If <code>true</code>, items that did not fit into the bank will be logged as lost
| logLost || boolean || Yes || false || If <code>true</code>, items that did not fit into the bank will be logged as lost
|-
|-
| found || boolean || Yes || false || Determines if it will show in item completion log
| found || boolean || Yes || false || Determines if items added by this function will be included within the "Times Found" statistic for that item within the completion log. Therefore, unless this parameter is set to <code>true</code>, any items added in this way will not contribute towards the player's item completion percentage.
<br/><br/>{{Disclaimer|'''Note:''' When adding {{ItemIcon|Bank Slot Token|Bank Slot Tokens}}, it is suggested that this parameter is set to <code>true</code>, otherwise this may cause issues with the way the game calculates the amount of bank space a player has.}}
|-
|-
| ignoreSpace || boolean || Yes || false || If <code>true</code>, the item will be added to the bank even if the bank is already full
| ignoreSpace || boolean || Yes || false || If <code>true</code>, the item will be added to the bank even if the bank is already full
Line 36: Line 37:
The removeItemQuantityByID function can be used to remove any item from the bank
The removeItemQuantityByID function can be used to remove any item from the bank
  <syntaxhighlight lang="js">game.bank.removeItemQuantityByID(itemID, quantity, removeItemCharges)</syntaxhighlight>
  <syntaxhighlight lang="js">game.bank.removeItemQuantityByID(itemID, quantity, removeItemCharges)</syntaxhighlight>
Note that if an item's quantity is in an invalid state, such as <syntaxhighlight lang="js" inline>NaN</syntaxhighlight> or <syntaxhighlight lang="js" inline>Infinity</syntaxhighlight>, then this function will not be able to remove that item from the bank. For any such items, use the below snippet instead:
{{SpoilerBox
|color=default
|title=Code
|text=First, enter the below into the console:
<syntaxhighlight lang="js">function removeItemByID(itemID) {
const item = game.items.getObjectByID(itemID);
if (item === undefined)
throw new Error(
`Error removing item from bank by id. Item with id: ${ itemID } is not registered.`
);
const bankItem = game.bank.items.get(item);
if (bankItem === undefined)
throw new Error(
`Tried to remove quantity from bank, but item is not in bank.`
);
bankItem.quantity = 1;
game.bank.removeItemQuantity(item, 1, true);
}</syntaxhighlight>
After this, invoke the newly-created function with the appropriate item ID to remove items from the bank. For example: <syntaxhighlight lang="js" inline>removeItemByID('melvorD:Oak_Logs');</syntaxhighlight>
}}


=== Attributes ===
=== Attributes ===
Line 50: Line 73:


=== Examples ===
=== Examples ===
  <syntaxhighlight lang="js">game.bank.removeItemQuantityByID("melvorD:Oak_Logs", 10);</syntaxhighlight>
  <syntaxhighlight lang="js">game.bank.removeItemQuantityByID('melvorD:Oak_Logs', 10);</syntaxhighlight>
The above code will result in 10 {{ItemIcon|Oak Logs}} being removed from the bank.
The above code will result in 10 {{ItemIcon|Oak Logs}} being removed from the bank.


== Add GP ==
== Adjust Currencies (GP, Slayer Coins, and Raid Coins) ==
The gp.add function can be used to add [[Currency#Gold Pieces|GP]] to a player.
All [[Currency]] within the game, being {{GP}} [[GP]], {{SC}} [[Slayer Coins]] (SC), and {{RC}} [[Raid Coins]] (RC) can be adjusted using the same set of functions:
  <syntaxhighlight lang="js">game.gp.add(amount)</syntaxhighlight>
* To adjust GP, use <syntaxhighlight lang="js" inline>game.gp</syntaxhighlight>
=== Attributes ===
* To adjust SC, use <syntaxhighlight lang="js" inline>game.slayerCoins</syntaxhighlight>
* To adjust RC, use <syntaxhighlight lang="js" inline>game.raidCoins</syntaxhighlight>
 
=== Add Currency ===
The game.''currency''.add function can be used to add to the player's current balance of that currency.
  <syntaxhighlight lang="js">game.<currency>.add(amount)</syntaxhighlight>
 
==== Attributes ====
{| class="wikitable"
{| class="wikitable"
|-
|-
! Attribute !! Type !! Optional? !! Default Value !! Description
! Attribute !! Type !! Optional? !! Default Value !! Description
|-
|-
| amount|| int || No || || The quantity of GP to add
| amount || int || No || || The amount to increase the specified currency's balance by
|}
|}
=== Examples ===
 
==== Examples ====
  <nowiki>game.gp.add(1);</nowiki>
  <nowiki>game.gp.add(1);</nowiki>
The above code will add 1 [[Currency#Gold Pieces|GP]] to the player.
The above code will add 1 [[Currency#Gold Pieces|GP]] to the player.


== Remove GP ==
=== Remove Currency ===
The gp.remove function can be used to remove [[Currency#Gold Pieces|GP]] from a player. If the amount specified is greater than the amount the player currently has, then GP will go into the negatives.
The game.''currency''.remove function can be used to subtract from the player's current balance of that currency. If the amount specified is greater than the amount the player currently has, then the currency's balance will become negative.
  <syntaxhighlight lang="js">game.gp.remove(amount)</syntaxhighlight>
  <syntaxhighlight lang="js">game.<currency>.remove(amount)</syntaxhighlight>
=== Attributes ===
 
==== Attributes ====
{| class="wikitable"
{| class="wikitable"
|-
|-
! Attribute !! Type !! Optional? !! Default Value !! Description
! Attribute !! Type !! Optional? !! Default Value !! Description
|-
|-
| amount|| int || No || || The quantity of GP to remove
| amount || int || No || || The quantity to decrease the specified currency's balance by
|}
|}
=== Examples ===
<syntaxhighlight lang="js">game.gp.remove(1);</syntaxhighlight>
The above code will remove 1 [[Currency#Gold Pieces|GP]] from the player.


== Add Slayer Coins ==
==== Examples ====
The slayerCoins.add function can be used to add [[Currency#Slayer Coins|Slayer Coins]] to a player.
  <syntaxhighlight lang="js">game.raidCoins.remove(1);</syntaxhighlight>
<syntaxhighlight lang="js">game.slayerCoins.add(amount)</syntaxhighlight>
The above code will remove 1 [[Raid Coins|Raid Coin]] from the player.
=== Attributes ===
{| class="wikitable"
|-
! Attribute !! Type !! Optional? !! Default Value !! Description
|-
| amount || int || No || || The quantity of slayer coins to add.
|}
=== Examples ===
  <syntaxhighlight lang="js">game.slayerCoins.add(1);</syntaxhighlight>
The above code will add 1 [[Currency#Slayer Coins|Slayer Coin]] to the player.


== Remove Slayer Coins ==
=== Set Currency ===
The slayerCoins.remove function can be used to remove [[Currency#Slayer Coins|Slayer Coins]] from a player. If the amount specified is greater than the amount the player currently has, then slayer coins will go into the negatives.
The game.''currency''.set function can be used to set the player's balance of that currency to the specified amount. This function may be of particular use to players who have inadvertently found their GP or SC balance is set to an invalid value such as <code>NaN</code>.
<syntaxhighlight lang="js">game.slayerCoins.remove(amount)</syntaxhighlight>
  <syntaxhighlight lang="js">game.<currency>.set(amount)</syntaxhighlight>
=== Attributes ===
{| class="wikitable"
|-
! Attribute !! Type !! Optional? !! Default Value !! Description
|-
| amount || int || No || || The quantity of slayer coins to remove
|}
=== Examples ===
  <syntaxhighlight lang="js">game.slayerCoins.remove(1);</syntaxhighlight>
The above code will remove 1 [[Currency#Slayer Coins|Slayer Coin]] from the player.


== Add Raid Coins==
==== Attributes ====
The raidCoins.add function can be used to add [[Currency#Raid Coins|Raid Coins]] to a player.
<syntaxhighlight lang="js">game.raidCoins.add(amount)</syntaxhighlight>
=== Attributes ===
{| class="wikitable"
{| class="wikitable"
|-
|-
! Attribute !! Type !! Optional? !! Default Value !! Description
! Attribute !! Type !! Optional? !! Default Value !! Description
|-
|-
| amount || int || Yes || 0 || The quantity of raid coins to be added.
| amount || int || No || || The amount to set the specified currency's balance to
|}
|}
=== Examples ===
<syntaxhighlight lang="js">game.raidCoins.add(1);</syntaxhighlight>
The above will add 1 [[Currency#Raid Coins|Raid Coin]] to the player.


== Remove Raid Coins==
==== Examples ====
The raidCoins.remove function can be used to remove [[Currency#Raid Coins|Raid Coins]] from a player.
  <syntaxhighlight lang="js">game.slayerCoins.set(999);</syntaxhighlight>
<syntaxhighlight lang="js">game.raidCoins.remove(amount)</syntaxhighlight>
The above code will set the player's [[Raid Coins|Raid Coin]] balance to 999, regardless of what the previous balance of raid coins owned was.
=== Attributes ===
{| class="wikitable"
|-
! Attribute !! Type !! Optional? !! Default Value !! Description
|-
| amount || int || Yes || 0 || The quantity of raid coins to be removed.
|}
=== Examples ===
  <syntaxhighlight lang="js">game.raidCoins.remvoe(1);</syntaxhighlight>
The above will remove 1 [[Currency#Raid Coins|Raid Coin]] from the player.


== Add Prayer Points ==
== Add Prayer Points ==
Line 234: Line 227:
  <syntaxhighlight lang="js">game.summoning.discoverMark(game.summoning.actions.getObjectByID('melvorF:Dragon'));</syntaxhighlight>
  <syntaxhighlight lang="js">game.summoning.discoverMark(game.summoning.actions.getObjectByID('melvorF:Dragon'));</syntaxhighlight>
The above code discovers a single mark for the {{ItemIcon|Dragon}} familiar.
The above code discovers a single mark for the {{ItemIcon|Dragon}} familiar.
{{Menu}}