ANNOYING NPC CODE ISSUE (Please Help)

LukeZurg22

Terrarian
I do not have THAT much experience with coding but i know a small bit to tell that there is something wrong with the:

public override bool Autoload(ref string name, ref string texture)
{
name = "NPCTown1";
return mod.Properties.Autoload;
}

area but just removing it causes error. Ive done all I can that seemed reasonable to fix the issue but nothing worked. Is anybody able to help me with this issue?

The whole script is at: https://pastebin.com/FvP7bsrG

And the error i get is: https://pastebin.com/fN2igB8t
 
I do not have THAT much experience with coding but i know a small bit to tell that there is something wrong with the:

public override bool Autoload(ref string name, ref string texture)
{
name = "NPCTown1";
return mod.Properties.Autoload;
}

area but just removing it causes error. Ive done all I can that seemed reasonable to fix the issue but nothing worked. Is anybody able to help me with this issue?

The whole script is at: https://pastebin.com/FvP7bsrG

And the error i get is: https://pastebin.com/fN2igB8t

c:\Users\LukeZurg22_Gaming\Documents\My Games\Terraria\ModLoader\Mod Sources\NecessaryAddons\NPCs\NPCTown1.cs(20,17) : error CS1061: 'Terraria.NPC' does not contain a definition for 'name' and no extension method 'name' accepting a first argument of type 'Terraria.NPC' could be found (are you missing a using directive or an assembly reference?)

c:\Users\LukeZurg22_Gaming\Documents\My Games\Terraria\ModLoader\Mod Sources\NecessaryAddons\NPCs\NPCTown1.cs(87,22) : warning CS0618: 'Terraria.Lang.inter' is obsolete: 'Lang arrays have been replaced with the new Language.GetText system.'

c:\Users\LukeZurg22_Gaming\Documents\My Games\Terraria\ModLoader\Mod Sources\NecessaryAddons\NPCs\NPCTown1.cs(87,22) : error CS0266: Cannot implicitly convert type 'Terraria.Localization.LocalizedText' to 'string'. An explicit conversion exists (are you missing a cast?)
 
Give this a read, it explains how to fix the 'name' error.

As for the other error, I'm not sure how to fix that. You need to use Language.GetText instead of the array, but I don't know what you should pass as an argument.
 
Give this a read, it explains how to fix the 'name' error.

As for the other error, I'm not sure how to fix that. You need to use Language.GetText instead of the array, but I don't know what you should pass as an argument.

I dont know what that means! As for t,he second ERROR , it shows when i remove "ref string texture" from the peramiter list.

I cant find where in the link you gave that says how to fix the name error. (Also, this script is for an npc, not a block/item. I have already finished an item and that one works fine.)
 
I dont know what that means! As for t,he second ERROR , it shows when i remove "ref string texture" from the peramiter list.

I cant find where in the link you gave that says how to fix the name error. (Also, this script is for an npc, not a block/item. I have already finished an item and that one works fine.)
You can no longer use npc.name, you have to use Tooltip.SetDefault. The link I gave you outlines how to do that.

The second error isn't related to the "ref string texture" error, it's a standalone error that's always been there, but the compiler never got to it because the "ref string error" error stopped it in its tracks. I know where it is (button = Lang.inter[28];), and why it is happening, but I don't know what to replace it with.

EDIT: DisplayName.SetDefault, not Tooltip.SetDefault.
 
Last edited:
You can no longer use npc.name, you have to use Tooltip.SetDefault. The link I gave you outlines how to do that.

The second error isn't related to the "ref string texture" error, it's a standalone error that's always been there, but the compiler never got to it because the "ref string error" error stopped it in its tracks. I know where it is (button = Lang.inter[28];), and why it is happening, but I don't know what to replace it with.

So now:
npc.name = "Cactus Enthusiast";
npc.townNPC = true;
npc.friendly = true;
npc.width = 18;
npc.height = 40;
npc.aiStyle = 7;
npc.damage = 10;
npc.defense = 15;
npc.lifeMax = 250;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath1;
npc.knockBackResist = 0.5f;
Needs to be replaced with something like:
npc.name = "Cactus Enthusiast";
Tooltip.SetDefault.townNPC = true;
Tooltip.SetDefault.friendly = true;
Tooltip.SetDefault.width = 18;
Tooltip.SetDefault.height = 40;
Tooltip.SetDefault.aiStyle = 7;
Tooltip.SetDefault.damage = 10;
Tooltip.SetDefault.defense = 15;
Tooltip.SetDefault.lifeMax = 250;
Tooltip.SetDefault.HitSound = SoundID.NPCHit1;
Tooltip.SetDefault.DeathSound = SoundID.NPCDeath1;
Tooltip.SetDefault.knockBackResist = 0.5f;

?
 
So now:
npc.name = "Cactus Enthusiast";
npc.townNPC = true;
npc.friendly = true;
npc.width = 18;
npc.height = 40;
npc.aiStyle = 7;
npc.damage = 10;
npc.defense = 15;
npc.lifeMax = 250;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath1;
npc.knockBackResist = 0.5f;
Needs to be replaced with something like:
npc.name = "Cactus Enthusiast";
Tooltip.SetDefault.townNPC = true;
Tooltip.SetDefault.friendly = true;
Tooltip.SetDefault.width = 18;
Tooltip.SetDefault.height = 40;
Tooltip.SetDefault.aiStyle = 7;
Tooltip.SetDefault.damage = 10;
Tooltip.SetDefault.defense = 15;
Tooltip.SetDefault.lifeMax = 250;
Tooltip.SetDefault.HitSound = SoundID.NPCHit1;
Tooltip.SetDefault.DeathSound = SoundID.NPCDeath1;
Tooltip.SetDefault.knockBackResist = 0.5f;

?
No, that's exactly the opposite of what you need to do.

Leave everything in the SetDefaults method as it is, but remove the npc.name statement. Override SetStaticDefaults in addition to SetDefaults, and set the name there.

So basically:
Code:
public override void SetDefaults()
{
    //stuff
}

public override void SetStaticDefaults()
{
    DisplayName.SetDefault("Name");
}
 
Wait, i think im understanding a bit more, so i would have to execute the code for the npc as:

public override void SetDefaults()
{
npc.townNPC = true;
npc.friendly = true;
npc.width = 18;
npc.height = 40;
npc.aiStyle = 7;
npc.damage = 10;
npc.defense = 15;
npc.lifeMax = 250;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath1;
npc.knockBackResist = 0.5f;
Main.npcFrameCount[npc.type] = 25;
animationType = NPCID.Guide;
}

public override void SetStaticDefaults()
{
DisplayName.SetDefault("Cactus Enthusiast");
}

? Im pretty sure thats how that goes from what help you assisted with sofar.
 
Wait, i think im understanding a bit more, so i would have to execute the code for the npc as:

public override void SetDefaults()
{
npc.townNPC = true;
npc.friendly = true;
npc.width = 18;
npc.height = 40;
npc.aiStyle = 7;
npc.damage = 10;
npc.defense = 15;
npc.lifeMax = 250;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath1;
npc.knockBackResist = 0.5f;
Main.npcFrameCount[npc.type] = 25;
animationType = NPCID.Guide;
}

public override void SetStaticDefaults()
{
DisplayName.SetDefault("Cactus Enthusiast");
}

? Im pretty sure thats how that goes from what help you assisted with sofar.
Yeah, that should work.

Still don't know how to fix your other issue though, unfortunately. You'd need a better person than me.
 
Yeah, that should work.

Still don't know how to fix your other issue though, unfortunately. You'd need a better person than me.

Where can i come in contact with someone who knows how to fix the issue?

EDIT: I also kept the reg string texture part you told me to remove but i did move and change up the name.Npc thing, but the error is still https://pastebin.com/Z4TCKr67 so that if i do get in contact with someone who has more experience, he or she has an easy error bases to start helping and a base for me to learn how to solve errors more easly.
 
Where can i come in contact with someone who knows how to fix the issue?

EDIT: I also kept the reg string texture part you told me to remove but i did move and change up the name.Npc thing, but the error is still https://pastebin.com/Z4TCKr67 so that if i do get in contact with someone who has more experience, he or she has an easy error bases to start helping and a base for me to learn how to solve errors more easly.
Try here. Somebody there is bound to know the answer.

I don't know why you changed the parameters to (ref string, ref string), but that is never going to work. Change it back to (ref string name).
 
Try here. Somebody there is bound to know the answer.

I don't know why you changed the parameters to (ref string, ref string), but that is never going to work. Change it back to (ref string name).

I msged the person for help and, sorry, i meant ref string name, ref string texture, i kept texture in there cause it causes more errors so instead, i routed to the direct source of the issue and with the other persons help, it can be narrowed down more accurately.
 
I msged the person for help and, sorry, i meant ref string name, ref string texture, i kept texture in there cause it causes more errors so instead, i routed to the direct source of the issue and with the other persons help, it can be narrowed down more accurately.
I don't think you quite understand how the compiler works. Removing the ref string texture from the parameter list doesn't cause more issues, it just reveals them.

Imagine I have a script, some lines generate errors, some don't.
Code:
Line 1
Line 2 - generates an error
Line 3
Line 4 - generates an error
Line 5 - generates an error
Line 6

The compiled processes your script from top to bottom. As soon as it finds an error, in this case on line 2, it stops compiling, and tells you where it encountered the error. But obviously, when it stops on line 2, the errors on line 4 and 5 are still there, the compiler simply never got there. So 'intentionally' causing errors to prevent (even though what you are doing is actually hiding) multiple errors doesn't work, as a script with just one error will work just as well as a script with two hundred. Namely, not at all.

Seriously, change it back to (ref string name). The two errors have nothing to do with each other. Just tell the other person that you need to acquire a string for a chat button, because that's what you need to do.
 
I don't think you quite understand how the compiler works. Removing the ref string texture from the parameter list doesn't cause more issues, it just reveals them.

Imagine I have a script, some lines generate errors, some don't.
Code:
Line 1
Line 2 - generates an error
Line 3
Line 4 - generates an error
Line 5 - generates an error
Line 6

The compiled processes your script from top to bottom. As soon as it finds an error, in this case on line 2, it stops compiling, and tells you where it encountered the error. But obviously, when it stops on line 2, the errors on line 4 and 5 are still there, the compiler simply never got there. So 'intentionally' causing errors to prevent (even though what you are doing is actually hiding) multiple errors doesn't work, as a script with just one error will work just as well as a script with two hundred. Namely, not at all.

Seriously, change it back to (ref string name). The two errors have nothing to do with each other. Just tell the other person that you need to acquire a string for a chat button, because that's what you need to do.

Crud, ill remove ref string texture, sorry. XD

I thought that the compiler works with the most problematic error first, then as more errors are fixed other errors lower would show.
 
That's the same error you had before, the one I don't know how to fix. Can't help you there, unfortunately.

Edit: I pin-pointed the direct area code that has the issue:

public override void SetChatButtons(ref string button, ref string button2)
{
button = Lang.inter>>>>[28]<<<<;
}

(I put arrows pointing to the most direct spot of the issue.)

Old: Crud, and the person hasnt even responded yet.
 
Last edited:
Back
Top Bottom