Changes

Jump to navigation Jump to search
Line 54: Line 54:     
==Mod APIs==
 
==Mod APIs==
===Console commands===
  −
You can add commands to the SMAPI console (the terminal window that opens alongside the game), and invoke them by typing directly into the console. Note that most players aren't comfortable with a command-line interface, so you should prefer in-game interfaces for player-facing features.
  −
  −
Each console command must have:
  −
* a name which the player types to invoke the command.
  −
* a description shown when the player uses the <tt>help</tt> command. This should explain what the command does, how to use it, and what arguments it accepts. The example below shows the recommended convention.
  −
* the code to run when the command is called.
  −
  −
The code below creates a <tt>player_setmoney</tt> command (but don't forget to validate input, this is just an example).
  −
<source lang="C#">
  −
public override void Entry(IModHelper helper)
  −
{
  −
  helper.ConsoleCommands.Add("player_setmoney", "Sets the player's money.\n\nUsage: player_setmoney <value>\n- value: the integer amount.", this.SetMoney);
  −
}
  −
  −
/// <summary>Set the player's money when the 'player_setmoney' command is invoked.</summary>
  −
/// <param name="command">The name of the command invoked.</param>
  −
/// <param name="args">The arguments received by the command. Each word after the command name is a separate argument.</param>
  −
private void SetMoney(string command, string[] args)
  −
{
  −
  Game1.player.money = int.Parse(args[0]);
  −
  this.Monitor.Log($"OK, set your money to {args[0]}.");
  −
}
  −
</source>
  −
  −
Here's how the player would use it:
  −
<pre>
  −
help player_setmoney
  −
> player_setmoney: Sets the player's money.
  −
>
  −
> Usage: player_setmoney <value>
  −
> - value: the integer amount.
  −
  −
player_setmoney 5000
  −
> OK, set your money to 5000.
  −
</pre>
  −
   
===Content packs===
 
===Content packs===
 
A content pack is a sub-mod containing files your mod can read. These are installed just like a regular SMAPI mod, but don't do anything on their own. These must specify your mod in their <tt>manifest.json</tt>. See [[Modding:Content packs]] for more info about content packs.
 
A content pack is a sub-mod containing files your mod can read. These are installed just like a regular SMAPI mod, but don't do anything on their own. These must specify your mod in their <tt>manifest.json</tt>. See [[Modding:Content packs]] for more info about content packs.
translators
8,404

edits

Navigation menu