tModLoader Not all code paths return a value

aSnek147

Terrarian
Attached is the only custom content that currently exists in my new mod. When I use the "build + reload" option in tModloader, I get an error, telling me that not all code paths are returning a value, and directing me to line 48. What have I done wrong here, and how do I fix it?
 

Attachments

  • StoneStaff.cs
    1.6 KB · Views: 47
I don't know Terraria modding but have programmed professionally in C# for many years. My advice here addresses C# itself, with an informed guess as to the Terraria side of the affair.

If you declare a return type for a function, you must return a value of that type. CanUseItem() doesn't return a bool, or for that matter any value at all. Unless the function is misnamed, it needs to return true if the player can use the item and false if the player can't use it.
 
Sorry, I'm not even sure how to use C#, so I wouldn't be sure how to return the function as true. What would I need to write to do this?
 
Right, so I fixed my original issue and the mod can run correctly. However when I use the alt-function, it's exactly the same as the base function. The alt-function is supposed to fire the "Starfury" projectile, deal 12 damage, and cost 6 mana, however for some reason it's exactly the same as the base function, which fires the "FallingStar" projectile, deals 10 damage, and costs 3 mana. How can I fix this? Attached is the new code
 

Attachments

  • StoneStaff.cs
    1.6 KB · Views: 55
You have return true; immediately in your CanUseItem method, so none of the other code is executed. Move it to the end.

Also, you need brackets for your if statement there { } otherwise all you are setting is Item.mana for altFunctionUse.
 
You'll definitely need to learn programming in general and C# specifically, or else you're going to run into one roadblock after another.

Try this free ebook (you have to sign up for occasional emails but can cancel any time) — Syncfusion Free Ebooks | C# Succinctly

It includes stuff you won't need (databases and such) but covers the bases pretty well. It's written for C# version 6. The current version is 10, so it won't cover the latest features. You won't need those anyway.

For newer info there are heaps of other free resources on the web. Just google / duckduckgo / bing / whatever and Bob's your uncle. Good luck!
 
I'm just going to pop in here to give another C# tutorial site, this site also has a bunch of other tutorials if you ever need those
 
*thumbs up* Programming is a great skill to pick up. Learning C# will help you if you want to try web programming using PHP and JavaScript — the languages are different but their syntax and many operations are based on the C language.
 
Back
Top Bottom