Click here to Skip to main content
16,022,234 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making a mod using TModLoader, and I had a few easy fix errors but I now have "An error occurred while building TESTMOD. Compiling TESTMOD.dll failed with 32 errors and 0 warnings. Error: C:\Users\Ryuk\Documents\My Games\Terraria\tModLoader\ModSources\TESTMOD\Content\Items\Halfwitted'sSword.cs(5,43): error CS1010: Newline in constant.".

C#
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TESTMOD.Content.Items.Halfwitted'sSword.cs
{ 
	// This is a basic item template.
	// Please see tModLoader's ExampleMod for every other example:
	// https://github.com/tModLoader/tModLoader/tree/stable/ExampleMod
	public class Halfwitted'sSword : ModItem	
	{
		// The Display Name and Tooltip of this item can be edited in the 'Localization/en-US_Mods.TESTMOD.hjson' file.
		public override void SetDefaults()
		{
			Item.damage = 9;
			Item.DamageType = DamageClass.Melee;
			Item.width = 40;
			Item.height = 40;
			Item.useTime = 20;
			Item.useAnimation = 20;
			Item.useStyle = ItemUseStyleID.Swing;
			Item.knockBack = 9;
			Item.value = Item.buyPrice(platinum: 100);
			Item.rare = ItemRarityID.Fiery Red;
			Item.UseSound = SoundID.Item1;
			Item.autoReuse = true;
		}

		public override void AddRecipes()
		{
			Recipe recipe = CreateRecipe();
			recipe.AddIngredient(ItemID.Lunarore, 9999);
			recipe.AddTile(TileID.Altar);
			recipe.Register();
		}
	}
}


What I have tried:

I'm not familiar with code like this and I've tried to create errors to test where the original error was, but the error would not change.
Posted
Updated 30-Jul-24 22:24pm
v2

Your namespace appears to be a file name. Don't confuse files, folders, namespaces and classes. Files and folders are just housekeeping, whereas namespaces and classes are project organisation. (I'm not going to get into a discussion about whether namespaces and folders should match). Maybe read this or this or this.

It should probably be this :
C#
namespace TESTMOD.Content.Items

Using special characters in a class name is best avoided just to avoid potential problems. So this :
C#
public class HalfwittedsSword : ModItem

Giving this new code :
C#
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TESTMOD.Content.Items
{ 
	// This is a basic item template.
	// Please see tModLoader's ExampleMod for every other example:
	// https://github.com/tModLoader/tModLoader/tree/stable/ExampleMod
	public class HalfwittedsSword : ModItem	
	{
		// The Display Name and Tooltip of this item can be edited in the 'Localization/en-US_Mods.TESTMOD.hjson' file.
		public override void SetDefaults()
		{
			Item.damage = 9;
			Item.DamageType = DamageClass.Melee;
			Item.width = 40;
			Item.height = 40;
			Item.useTime = 20;
			Item.useAnimation = 20;
			Item.useStyle = ItemUseStyleID.Swing;
			Item.knockBack = 9;
			Item.value = Item.buyPrice(platinum: 100);
			Item.rare = ItemRarityID.Fiery Red;
			Item.UseSound = SoundID.Item1;
			Item.autoReuse = true;
		}

		public override void AddRecipes()
		{
			Recipe recipe = CreateRecipe();
			recipe.AddIngredient(ItemID.Lunarore, 9999);
			recipe.AddTile(TileID.Altar);
			recipe.Register();
		}
	}
}
 
Share this answer
 
To add to what Richard has said, class names (and namespace names) have to follow the same rules as variable names: They must start with a letter or underscore, and then contain only letters, numbers, and underscores (thought there is a special case for keywords which may be prefixed with and '@' to allow for integration with other languages).

The formal definition is here: Lexical structure - C# language specification (Identifiers) | Microsoft Learn[^]

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!

And spending a little time learning to understand syntax error messages will save you a huge amount of time in future: you waited at least 1/4 hour for Chris to reply, then your email system probably added another 10 minutes or so, plus the time it took you to type up the question once you had found this site and created an account. Chances are that you could have saved a significant chunk of that time if you knew how to read them!

I'm not saying we don't want to help you fix them - sometimes I can't see my own errors because I read what I meant to write - but fixing syntax errors is part of the job, and if you can't do it for yourself people are going to look at you as a bit weird should you get a job in the industry!
 
Share this answer
 
v2
C#
public class Halfwitted'sSword : ModItem

I don't think you are allowed a single quote character in a class name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900