Click here to Skip to main content
15,886,842 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am currently stuck with a CS0103 in my code and I have no idea how to fix it.
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;

namespace MI.Items.Placeable
{
	public class MinecraftInjection : ModItem
	{
		public override void SetStaticDefaults()
		{
			ItemID.Sets.SortingPriorityMaterials[item.type] = 59;
		}

		public override void SetDefaults()
		{
			item.width = 20;
			item.height = 20;
			item.maxStack = 99;
			item.value = 7800;
			item.useStyle = 1;
			item.useTurn = true;
			item.useAnimation = 15;
			item.useTime = 10;
			item.autoReuse = true;
			item.consumable = true;
			item.createTile = mod.TileType(Tiles("NetheriteBar"));
			item.placeStyle = 0;
		}

		public override void AddRecipes()
		{
			ModRecipe recipe = new ModRecipe(mod);
			recipe.AddIngredient(mod.ItemType("ExampleOre"), 4);
			recipe.AddIngredient(ItemID.GoldBar, 2);
			recipe.AddIngredient(ItemID.HellstoneBar);
			recipe.SetResult(this);
			recipe.AddRecipe();
		}
	}
}


any help is appreciateted, thanks!

What I have tried:

I tried adding
var things = new List<Tiles>

{
		public override void SetStaticDefaults()
		{
			ItemID.Sets.SortingPriorityMaterials[item.type] = 59;
		}

		public override void SetDefaults()
        var things = new List<Tiles>
		{
			item.width = 20;
			item.height = 20;
			item.maxStack = 99;
			item.value = 7800;
			item.useStyle = 1;
			item.useTurn = true;
			item.useAnimation = 15;
			item.useTime = 10;
			item.autoReuse = true;
			item.consumable = true;
			item.createTile = mod.TileType(Tiles("NetheriteBar"));
			item.placeStyle = 0;
		}

this, however, changed 2 errors into 44
changing
<Tiles>
into
(Tiles)
did not help
Posted
Updated 6-May-20 22:28pm
Comments
RickZeeland 7-May-20 3:10am    
Apparently you are using a name that is not recognized, see: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0103
Richard MacCutchan 7-May-20 5:45am    
Why do you think some random line of code will correct your error? You refer to two objects (recipe and item) but you have not declared them anywhere that we can see.

1 solution

Please, read this first: Compiler Error CS0103 | Microsoft Docs[^]

The compiler message is quite obvious. Tiles class does not exist (in current context) or is inaccessible due to protection level!

My best guess: you have to add a namespace in which Tiles class is declared by adding using directive at the top of module.

Even if Tiles name is not recognized, there's another issue:
C#
var things = new List<Tiles>
{
    item.width = 20;
    //skipped lines
    item.placeStyle = 0;
}

You can NOT initilize list of Tiles this way!
It should be:
C#
var things = new List<Tiles>
{
    new Tiles(...),
    new Tiles(...),
    new Tiles(...)
}
 
Share this answer
 
v2
Comments
TheRealSteveJudge 7-May-20 4:43am    
Good advice! 5*
Maciej Los 7-May-20 6:48am    
Thank you.
[no name] 7-May-20 5:06am    
I already read the Document, I tried it, definitely did something wrong, reverted it just to make sure I didn't screw something else up, it gave me a different error instead (CS0119 if I remember correctly) that I fixed and I'm currently stuck with a CS0118
Member 15897526 19-Jan-23 8:00am    
I am having same problem






using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Globalization;
public class Form1 : System.Windows.Forms.Form
{
public System.Windows.Forms.ListBox List1;
public System.Windows.Forms.TextBox Text2;
public System.Windows.Forms.TextBox Text1;
public System.Windows.Forms.GroupBox Frame1;
public System.Windows.Forms.RadioButton optDWord;
public System.Windows.Forms.RadioButton optWord;
public System.Windows.Forms.RadioButton optByte;
public System.Windows.Forms.Button btnExit;
public System.Windows.Forms.Button btnWrite;
public System.Windows.Forms.Button btnRead;
public System.Windows.Forms.Label Label3;
public System.Windows.Forms.Label Label1;
public System.Windows.Forms.Label Label4;
public System.Windows.Forms.Label Label2;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after
InitializeComponent call
//
}
///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
static void Main()
{
Application.Run(new Form1());
}
private void btnExit_Click(object sender, System.EventArgs
e)
{
this.Close();
}
private void btnRead_Click(object sender, System.EventArgs
e)
{
int nInNum;
short nPortID;
nPortID = short.Parse(Text1.Text,
NumberStyles.AllowHexSpecifier);
if(optByte.Checked)
nInNum = NTPort.Inport(nPortID);
else if(optWord.Checked)
nInNum = NTPort.InportW(nPortID);
else
nInNum = NTPort.InportD(nPortID);
// Get Error Information
StringBuilder errorBuffer = new StringBuilder(30);
NTPort.GetLastState(errorBuffer);
List1.Items.Add("In 0x" + Text1.Text + ", 0x" +
nInNum.ToString("X"));
List1.Items.Add(errorBuffer.ToString());
List1.SelectedIndex = List1.Items.Count - 1;
}
private void btnWrite_Click(object sender, System.EventArgs
e)
{ int nOutNum;
short nPortID;
nPortID = short.Parse(Text1.Text,
NumberStyles.AllowHexSpecifier);
nOutNum = short.Parse(Text2.Text,
NumberStyles.AllowHexSpecifier);
if(optByte.Checked)
// Byte
NTPort.Outport(nPortID, (short)nOutNum);
else if(optWord.Checked)
// Word
NTPort.OutportW(nPortID, (short)nOutNum);
else
// DWord
NTPort.OutportD(nPortID, nOutNum);
// Get Error Information
StringBuilder errorBuffer = new StringBuilder(30);
NTPort.GetLastState(errorBuffer);
List1.Items.Add("Out 0x" + Text1.Text + ", 0x" +
Text2.Text);
List1.Items.Add(errorBuffer);
List1.SelectedIndex = List1.Items.Count - 1;
}
private void Form1_Load(object sender, System.EventArgs e)
{
// After register NTPort Library,
// place your registration information here.
NTPort.LicenseInfo("Your Name", 0);
}
private void Text1_TextChanged(object sender, EventArgs e)
{
} } }

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