tAPI tAPI Community Resources - Development assistance for developers, by developers.

Neojin

Terrarian
As more tAPI mods are developed and refined, tAPI itself becomes more popular and more people decide to try and create their own mods. Many of these developers are new to tAPI, and a lot of them are new to coding in general. The tAPI thread has become a place where users of all levels go to ask for help and post any code issues. While these posts are well-intentioned, and are often learning opportunities for all of us, it clutters up the tAPI thread which may be better suited for posts about tAPI's development.

I would like this thread to be a place for developers of all experience to post their questions and error logs. And I would like to ask the assistance of any programmer, hobbyist coder, or anyone who's fiddled with making a tConfig or tAPI mod to offer any help they may have to those who post here.

Additionally here are a few resources I would like to highlight that may provide additional help:
 
Last edited:
Hey is it possible to make a weapon restricted if you dont have a certain accesory?
Yes. If your weapon fired a projectile similar to the Terra Blade, you can have the weapons code iterate through the players accessories looking for you're particular accessory, and only fire the projectile if it's found. You can modify any of the values of the weapon such as damage, attack speed, knockback. Or I think you could use the canUse attribute to keep the player from even using the weapon unless an accessory is equipped.
 
Well, I need help...
I keep getting that error:
TAPI.Mods+LoadException: Base Metals.tapi: System.NullReferenceException: Object reference not set to an instance of an object.
at TAPI.ModJsonHandler.HandleTile(ModBase modBase, JsonData j, String fname)
at TAPI.ModJsonHandler.Handle(ModBase modBase)
at TAPI.Mod.<Load>b__0(BinBuffer bb)
at TAPI.Mods.HandleTapiModFile(FPath path, Action`1 action)
at TAPI.Mods.HandleModFile(FPath path, Action`1 action)
at TAPI.Mod.Load()
at TAPI.Mods.Load()
at TAPI.Mods.Load()

It's all started when I created a tile, but I can't fix it, because I don't know why this error happens...

{
"internalName": "CoalTile",
"displayName": "Coal Ore",
"size": [1,1],
"frameWidth": 16,
"frameHeight": 16,
"solid": true,
"blocksLight": true,
"blocksSun": true,
"mergeDirt": true,
"drop": "basemetal:Coal",
"dust": 61,
"treasure": true,
"minPick": 35,
"breaksByPick": true,
"sound": 1,
"soundGroup": 21,
}

{
"displayName": "Coal",
"size": [16,16],
"maxStack": 99,
"value": [0,0,2,0],
"rare": 2,
"useStyle": 1,
"useAnimation": 15,
"useTime": 10,
"autoReuse": true,
"useTurn": true,
"tooltip": "'Good fuel'",
"createTile": "basemetal:CoalTile",
"consumable": true
}
 
Well, I need help...
I keep getting that error:
TAPI.Mods+LoadException: Base Metals.tapi: System.NullReferenceException: Object reference not set to an instance of an object.
at TAPI.ModJsonHandler.HandleTile(ModBase modBase, JsonData j, String fname)
at TAPI.ModJsonHandler.Handle(ModBase modBase)
at TAPI.Mod.<Load>b__0(BinBuffer bb)
at TAPI.Mods.HandleTapiModFile(FPath path, Action`1 action)
at TAPI.Mods.HandleModFile(FPath path, Action`1 action)
at TAPI.Mod.Load()
at TAPI.Mods.Load()
at TAPI.Mods.Load()

It's all started when I created a tile, but I can't fix it, because I don't know why this error happens...

{
"internalName": "CoalTile",
"displayName": "Coal Ore",
"size": [1,1],
"frameWidth": 16,
"frameHeight": 16,
"solid": true,
"blocksLight": true,
"blocksSun": true,
"mergeDirt": true,
"drop": "basemetal:Coal",
"dust": 61,
"treasure": true,
"minPick": 35,
"breaksByPick": true,
"sound": 1,
"soundGroup": 21,
}

{
"displayName": "Coal",
"size": [16,16],
"maxStack": 99,
"value": [0,0,2,0],
"rare": 2,
"useStyle": 1,
"useAnimation": 15,
"useTime": 10,
"autoReuse": true,
"useTurn": true,
"tooltip": "'Good fuel'",
"createTile": "basemetal:CoalTile",
"consumable": true
}
The error does seem to be happening when tAPI tries to load your tiles json file -
at TAPI.ModJsonHandler.HandleTile(ModBase modBase, JsonData j, String fname)

What are the exact file names used for the tile and item? And are they in the correct folders? (Tiles folder for the tile, Items folder for the item) Also what is your mods internalName? (basemetal?) And what are the names of the texture files for the tile and item?

In your tiles json file, "internalName" is not a standard tile property. It probably doesn't hurt to have it in there, as tAPI supports custom json properties I think, but I would recommend removing that line unless you've inserted it for a particular reason. There's also an unnecessary comma at the end of the last line that I would remove.
 
The error does seem to be happening when tAPI tries to load your tiles json file -
at TAPI.ModJsonHandler.HandleTile(ModBase modBase, JsonData j, String fname)

What are the exact file names used for the tile and item? And are they in the correct folders? (Tiles folder for the tile, Items folder for the item) Also what is your mods internalName? (basemetal?) And what are the names of the texture files for the tile and item?

In your tiles json file, "internalName" is not a standard tile property. It probably doesn't hurt to have it in there, as tAPI supports custom json properties I think, but I would recommend removing that line unless you've inserted it for a particular reason. There's also an unnecessary comma at the end of the last line that I would remove.

Yeah, I checked EVERYTHING, but mod started working after putting Coal in recipe of another thingy.But thanks for help anyway:clothierhappy:
 
I need a little help on an error i get when i build the mod:
========================================

LitJson.JsonException: ModInfo Error: The given key was not present in the dictionary. ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at tAPI_Builder.MainWindow.<>c__DisplayClass8.<BtnBuild_Click>b__0()
--- End of inner exception stack trace ---
at tAPI_Builder.MainWindow.<>c__DisplayClass8.<BtnBuild_Click>b__0()


I'm pretty new to coding and modding, so this may be quite easy to fix, any idea's?
 
I need a little help on an error i get when i build the mod:
========================================

LitJson.JsonException: ModInfo Error: The given key was not present in the dictionary. ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at tAPI_Builder.MainWindow.<>c__DisplayClass8.<BtnBuild_Click>b__0()
--- End of inner exception stack trace ---
at tAPI_Builder.MainWindow.<>c__DisplayClass8.<BtnBuild_Click>b__0()


I'm pretty new to coding and modding, so this may be quite easy to fix, any idea's?
tAPI Builder is having trouble finding, accessing, or reading your mods ModInfo.json file. Did you include a ModInfo.json file for your mod? If you did include this file, please copy it here so we can take a look at it.
 
tAPI Builder is having trouble finding, accessing, or reading your mods ModInfo.json file. Did you include a ModInfo.json file for your mod? If you did include this file, please copy it here so we can take a look at it.
No need now, i've fixed that issue, just forgot to edit the post, it's all fine now
 
Hello!

Is it possible to a have a custom NPC like the guide to have recipes and explain stuff from my mod?

I know how to do basic JSON scripts, however cs is a bit over my head at the moment.

Thanks!
 
what is wrong with this code when i hit the monster i get an error
heres the code (cs made it happen)

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace WM.NPCs
{
public class RandomNess_Sheet : ModNPC
{
public override bool CanSpawn( int x, int y, int type, Player spawnedOn)
{
if (y <= Main.worldSurface &&
((!Main.bloodMoon && !spawnedOn.zoneEvil && Main.rand.Next(3) == 0)))
{
return false;
}
return false;
}
}
}

and heres the error

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Terraria.Main.PlaySound(System.Int32 type, System.Int32 x = -1, System.Int32 y = -1, System.Int32 Style = 1)
at Terraria.NPC.StrikeNPC(System.Int32 Damage, System.Single knockBack, System.Int32 hitDirection, System.Boolean crit = False, System.Boolean noEffect = False, System.Single critMult = 2)
at Terraria.NPC.UpdateNPC(System.Int32 i)
 
Hello!

Is it possible to a have a custom NPC like the guide to have recipes and explain stuff from my mod?

I know how to do basic JSON scripts, however cs is a bit over my head at the moment.

Thanks!

Almost anything is possible when using code, but using JSON alone severely limits what you can do. Any town NPC would require some C# coding to make them functional. That's where the chat text is set along with their shops, spawn conditions, etc. But adding a new one is one of the easier things to do coding wise. Here's what I recommend:
  • Download the Template Mod available from the first post
  • Use some Zip file program to open the .tapi file. 7zip, winZip, winRar, etc.
  • Place the contents of the file in your 'Documents\My Games\Terraria\tapi\Mods\Sources' folder
  • Use tAPI Builder to build the Template Mod, and verify it works in game
  • Now start looking at Template Mod source files, specifically the files in the NPCs folder. There is an example town NPC in there
  • Try to figure out what each part of the code does, and start changing some of the values to see what happens
  • Once you're more comfortable with the code, build your custom NPC from the Template Mod example code.

what is wrong with this code when i hit the monster i get an error
heres the code (cs made it happen)

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace WM.NPCs
{
public class RandomNess_Sheet : ModNPC
{
public override bool CanSpawn( int x, int y, int type, Player spawnedOn)
{
if (y <= Main.worldSurface &&
((!Main.bloodMoon && !spawnedOn.zoneEvil && Main.rand.Next(3) == 0)))
{
return false;
}
return false;
}
}
}

and heres the error

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Terraria.Main.PlaySound(System.Int32 type, System.Int32 x = -1, System.Int32 y = -1, System.Int32 Style = 1)
at Terraria.NPC.StrikeNPC(System.Int32 Damage, System.Single knockBack, System.Int32 hitDirection, System.Boolean crit = False, System.Boolean noEffect = False, System.Single critMult = 2)
at Terraria.NPC.UpdateNPC(System.Int32 i)
You're trying to play a sound that doesn't exist in the game. I don't see anywhere in the code you posted where a sound would be used though. Can you post the NPCs JSON file please. Is the problem just when this particular NPC is hit? Or when any NPC is hit with the weapon you're using?

Also, should your first return statement be 'return true'? Both of your return statements return false which means that NPC would never spawn.
 
Almost anything is possible when using code, but using JSON alone severely limits what you can do. Any town NPC would require some C# coding to make them functional. That's where the chat text is set along with their shops, spawn conditions, etc. But adding a new one is one of the easier things to do coding wise. Here's what I recommend:
  • Download the Template Mod available from the first post
  • Use some Zip file program to open the .tapi file. 7zip, winZip, winRar, etc.
  • Place the contents of the file in your 'Documents\My Games\Terraria\tapi\Mods\Sources' folder
  • Use tAPI Builder to build the Template Mod, and verify it works in game
  • Now start looking at Template Mod source files, specifically the files in the NPCs folder. There is an example town NPC in there
  • Try to figure out what each part of the code does, and start changing some of the values to see what happens
  • Once you're more comfortable with the code, build your custom NPC from the Template Mod example code.


You're trying to play a sound that doesn't exist in the game. I don't see anywhere in the code you posted where a sound would be used though. Can you post the NPCs JSON file please. Is the problem just when this particular NPC is hit? Or when any NPC is hit with the weapon you're using?

Also, should your first return statement be 'return true'? Both of your return statements return false which means that NPC would never spawn.
fixed it
 
Hi,

How do you create a custom item that drops from a mob? Also how do you create a raw tAPI file?

Thanks
 
Back
Top Bottom