Announcement

Collapse
No announcement yet.

Type mismatch woes... [04]

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

    Type mismatch woes... [04]

    Ok guys. I am creating a mutator that checks what weapon a player is holding when they spawn and if they are holding the weapon I want to replace, it swaps it out for the new weapon I've created. Only problem is, it won't compile. It gives me a Type mismatch in '='

    Here's the code:
    Code:
    class WeaponReplaceMutator extends Mutator;
    
    var class<Weapon> OldWeaponClass, NewWeaponClass;
        
    function bool CheckReplacement(actor Other, out byte bSuperRelevant)
    {
    
    	if ( Pawn(Other) != None )
    	{
    		if ( Pawn(Other).Weapon == OldWeaponClass )
    		{
    			Pawn(Other).Weapon = NewWeaponClass;
    		}
    		else
    			return true;
    	}
    
    	return true;
    }
    
    
    
    defaultproperties
    {
         OldWeaponClass=class'oldpackage.oldweaponclass'
         NewWeaponClass=class'newpackage.newweaponclass'
    }
    If you are wondering why I am trying to do this with Checkreplacement(), the particular situation (immediately on/after player spawn) this is to be used in doesn't warrant any other method AFAIK.

    Any help would be greatly appreciated!

    #2
    The problem is pretty simple:
    The Pawn.Weapon property is an object, what you try to assign is a class.

    Solution:

    Pawn(Other).Weapon = Spawn( NewWeaponClass, Pawn );

    In addition the Pawn(Other).Weapon == OldWeaponClass will not work either. Try the following:

    Pawn(Other).Weapon.IsA( OldWeaponClass );

    Define the OldWeaponClass not as class, instead as name property. This will give you what you want

    Comment


      #3
      Cool thanks for the info.

      I tried that, but the compiler gave me an Error, Call to spawn: type mismatch in parameter '1'.

      Heres what I have:
      Code:
      class WeaponReplace Mutator extends Mutator;
      
      var name OldWeaponClass, NewWeaponClass;
          
      function bool CheckReplacement(actor Other, out byte bSuperRelevant)
      {
      
      	if ( Pawn(Other) != None )
      	{
      		if ( Pawn(Other).Weapon.IsA( OldWeaponClass ))
      		{
      			Pawn(Other).Weapon = Spawn( NewWeaponClass, Pawn); 
      		}
      		else
      			return true;
      	}
      
      	return true;
      }
      
      
      defaultproperties
      {
           OldWeaponClass=class'oldweaponpackage.oldweaponclass'
           NewWeaponClass=class'newweaponpackage.newweaponclass'
      
      }
      Sorry about being a n00b, only beeing messing with UScript for a bout a month (give or take).

      Comment


        #4
        it seems to me that newweaponclass is a name, but the spawn function requires an argument of type "class".

        you'll need to change it similarly to what you had before:

        var class<Weapon> NewWeaponClass;

        then you can call Spawn( NewWeaponClass, ... ) no problem...

        Comment


          #5
          Sigh... no dice

          This time, I get a Error, call to spawn: Bad expression or missing '('

          heres the code:

          Code:
          class WeaponReplaceMutator extends Mutator;
          
          var class<weapon> NewWeaponClass;
          var name OldWeaponClass;
              
          function bool CheckReplacement(actor Other, out byte bSuperRelevant)
          {
          
          	if ( Pawn(Other) != None )
          	{
          		if ( Pawn(Other).Weapon.IsA( OldWeaponClass ))
          		{
          			Pawn(Other).Weapon = Spawn( NewWeaponClass, Pawn); 
          		}
          		else
          			return true;
          	}
          
          	return true;
          }
          
          
          defaultproperties
          {
               OldWeaponClass="oldweaponpackage.oldweaponclass"
               NewWeaponClass=class'newweaponpackage.newweaponclass'
          
          }
          Sorry about this guys...

          Comment


            #6
            make sure before you ask questions that you read the function prototypes. spawn is defined as:

            Spawn (class SpawnClass, optional actor SpawnOwner, optional name SpawnTag, optional vector SpawnLocation, optional rotator SpawnRotation)

            notice that the second argument must be an actor. your code specifies "Pawn" as the actor. unfortunately for your code, Pawn doesn't exist as an actor. it's a class name, not an object of class actor. try replacing "Pawn" with "Other" or "Pawn(Other)" or whatever it is you're looking for...

            Comment

            Working...
            X