- Home /
 
               Question by 
               NutellaDaddy · Apr 01, 2014 at 02:41 AM · 
                c#errorreturn value  
              
 
              `AllItems.AllWeapons()': not all code paths return a value
Everytime I try to define a class that takes the type of a certain type of item that I defined in another script I get this error. Can someone tell me what the problem is? I get it for every single function in the script.
 using UnityEngine;
 using System.Collections;
 
 public class AllItems : MonoBehaviour
 {
     private const string meleeWepPath = "Icons/Weapons/Melee";
 
     public static Weapon AllWeapons()
     {
         Weapon machete = new Weapon (10.0f, 0.0f, 3, false, 0, false);
         machete.name = "Machete";
         machete.description = "A fast bladed weapon";
         machete.icon =  Resources.Load (meleeWepPath) as Texture2D;;
         machete.rarity = RarityType.Common;
         machete.curDurability = 150.0f;
         machete.maxDurability = 150.0f;
         machete.weightAmount = 1;
 
     }
     public static Consumable AllConsumables()
     {
         
     }
     public static Armor AllArmor()
     {
         
     }
     public static Placeable AllPlaceables()
     {
         
     }
         public enum ItemType
         {
             Armor,
             Weapon,
             Consumable,
             Placeable
         }
 }
 
               Comment
              
 
               
              Write it up in the answers man. Thanks for the help. I'll mark it as correct
 
               Best Answer 
              
 
              Answer by Lo0NuhtiK · Apr 01, 2014 at 02:47 AM
public SomeThing MethodName() ... has to "return" a value
Example : (do NOT copy/paste this, it will NOT work)
 public SomeThing MethodName()
 {
    //bunch of variables here, bunch of other function calls, etc
    //still never returns anything
 }
 
 
 public SomeThing MethodName()
 {
    //bunch of stuff here.... and then
    if(someCrapIsTrue)
       return SomeThing ; //<---a return of something or other
 
    return null ; //<--- a return of null if applicable should someCrapNotBeTrue
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                