Announcement

Collapse
No announcement yet.

Control reached the end of non-void function Errors

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Control reached the end of non-void function Errors

    I'm not sure what the problem is but I keep getting script warnings in the Log when I spawn at the start of the game. Despite me putting an Else return 0 in at the end of the function as a back up, it keeps saying this:

    Code:
    [0013.71] ScriptWarning: Control reached the end of non-void function (make certain that all paths through the function 'return <value>'
    	UDNSpaceMarineGame uedpieuntitled_2.TheWorld:PersistentLevel.UDNSpaceMarineGame_0
    	Function SpaceMarine.UDNSpaceMarineGame:RatePlayerStart:024C

    This is the complete function:

    Code:
    function float RatePlayerStart(PlayerStart P, byte Team, Controller Player)
    {
    
    
    local UDNPlayerController OtherPlayerController;
    local UDNPlayerController UDNPlayerController;
    local float Rating, distance;
    local vector OtherPlayerPosition;
    
    UDNPlayerController=UDNPlayerController(Player);
    
    if (UDNPlayerController!=none)
       {
          if(NumPlayers==1)
            {
    
             
    
               if (P.bPrimaryStart)
    		    {
    
                DebugMessagePlayer("This PlayerStart = true"@P);
    			Rating += 1.f;
    
    	        return Rating;
    
    		    }
    
               if (P.bOccupied)
               {
                //This will find every player start occupied by another actor
                //DebugMessagePlayer("This player start Is occupied");
    		    return 0.f;
                }
    
    
               if ( !P.bEnabled )
    	       {
               //This will find every player start with enabled turned off.
               //DebugMessagePlayer("This player start isn't enabled");
    		   return 0.f;
    	       }
            }
    
        else if(NumPlayers==2)
        {
    
         //DebugMessagePlayer("I should spawn near another player");
          foreach DynamicActors(class'UDNPlayerController', OtherPlayerController)
    	    {
    
             if (OtherPlayerController.Pawn != None)
    
              {
    
               OtherPlayerPosition = OtherPlayerController.Pawn.location;
    
                distance = VSize(OtherPlayerPosition - P.Location);
                Rating = 1.f / distance;
    
               //DebugMessagePlayer("2 player RATING" @ Rating @ p);
    
               return Rating;
    
              }
            }
    
          if (OtherPlayerController.Pawn == None)
    
          {
    
           //DebugMessagePlayer("There is no other player to spawn next to");
    
            if (P.bPrimaryStart)
    		   {
    			 Rating += 1.f;
    		   }
             return Rating;
    
           }
    
         }
    
       }
    
       else
       {
       return 0;
    
       }
      
    }
    any help would be great thanks.

    #2
    Fix your indenting levels and you'll easily see where you missed braces or whether that final Else statement actually belongs to the outer-most If statement.

    Comment


      #3
      Just take the last else statement out. Instead of this:
      Code:
         if(UDNPlayerController!=none)
          {
              // Buncha stuff
          }
          else
         {
             return 0;
         }
      Just have this:
      Code:
         if(UDNPlayerController!=none)
          {
              // Buncha stuff
          }
      
          return 0;

      Comment


        #4
        But still, fix your indenting if you want people to look at your code.

        Comment


          #5
          Thanks that works!

          Comment

          Working...
          X