Announcement

Collapse
No announcement yet.

Bad or missing expression in 'if' Please help

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

  • replied
    awww jeez thanks a lot, i owe you one. I can definitly use this.
    that would have been a headache i dont need right now, thanks again

    Leave a comment:


  • replied
    No, its not bad at all, your just going to have to use some different code. Read these pages on the UnrealWiki.

    [EDIT] Actually since you are already using an inventory item, its really, really easy to add an interaction or HUDOverlay (the preferred type). I've listed some sample code below (both for the inventory item that I give to the player when they spawn through my mutator, and the interaction).
    Inventory class:
    Code:
    //+=====================================
    // ThermalGoggles that allow the player to see pawns through walls for YARM Call of Duty 4 Mutator
    //+=====================================
    class ThermalGogglesInv_yarm extends Powerups;
    
    var bool bGogglesOn;
    var ThermalGogglesHUDOverlay  ThermalVision;
    
    // Network replication.
    replication{
    	// Things the server should send to the client.
    	reliable if( bNetOwner && bNetDirty && (Role==ROLE_Authority) )
    		bGogglesOn;
    }
    
    simulated function PostNetBeginPlay(){
        local PlayerController PC;
    
        // add the thermal view interaction
        PC = Level.GetLocalPlayerController();
        if(PC == PlayerController(Instigator.Controller)){
            ThermalVision=spawn(class'ThermalGogglesHudOverlay');
            if(ThermalVision!=none){
               PC.myHud.AddHudOverlay(ThermalVision);
               ThermalVision.PlayerOwner = PC;
               ThermalVision.Goggles = self;
            }
        }
        super.PostNetBeginplay();
    }
    
    function Activate(){
       Pawn(Owner).ClientMessage("Thermal Googles toggle");
       bGogglesOn = !bGogglesOn;
    }
    
    simulated function Destroyed(){
       local PlayerController PC;
    
        // remove the thermal view interaction
        PC = Level.GetLocalPlayerController();
        if(PC == PlayerController(Instigator.Controller)){
            if(ThermalVision != none) ThermalVision.GogglesDestroyed();
        }
    	super.destroyed();
    }
    
    defaultproperties{
         numcopies=1
         bActivatable=true
         bAutoActivate=false
         bCanHaveMultipleCopies=false
         bOnlyDirtyReplication=true
         bOnlyRelevantToOwner=true
         AttachmentClass=none
         bTravel=True
         DrawType=DT_None
         RemoteRole=ROLE_SimulatedProxy
         NetPriority=1.4
         bOnlyOwnerSee=true
         bHidden=true
         bClientAnim=true
         Physics=PHYS_None
         bReplicateMovement=false
         bAcceptsProjectors=false
         bDrawingFirstPerson=false
    }
    and here is the HUDOverlayClass:
    Code:
    //=============================================================================
    // Thermal Goggles HUDoverlay. By M Eck
    // This will be of benefit when players have a highpowered weapon and want to shoot through walls
    //=============================================================================
    
    class ThermalGogglesHUDOverlay extends HUDOverlay;
    
    var bool bOn, bWasOn;
    var Material THERMplayer, ThermHidePlayer;
    var Material View, ColorMat;
    var color color_nvg, color_view;
    var float chargeLeft;
    var float BatteryLife;
    var float DrainSpeed, ChargeSpeed;
    var float lastCheckTime;
    var float DrainMultiplier;// certain vison modes drain faster than others
    var float FadeTime; // for fading the screen from black
    var sound toggleSound;
    const NVGDRAIN = 1.0;
    
    var ThermalGogglesInv_yarm Goggles;
    var() PlayerController PlayerOwner;
    
    // close up shop so to speak
    function GogglesDestroyed(){
        Destroy();
    }
    
    function Render( Canvas C ){
        local float currtime, percentPower;
        local UnrealPawn RP;
        local pawn P;
        local float fadevalue;
    
        if(Goggles != none) bOn = Goggles.bGogglesOn;
        else GogglesDestroyed();
    
        currtime = level.timeseconds;
        percentPower = (chargeLeft/BatteryLife) * 100;
        P=PlayerOwner.Pawn;
    
        if ( currTime - FadeTime <= 0.8 ){
            FadeValue = 255 * ( 1.0 - (currtime - FadeTime)/0.8);
        	C.DrawColor.A = FadeValue;
        	C.Style = 5;
        	C.SetPos(0,0);
        	C.DrawTile( Texture'Engine.BlackTexture', C.SizeX, C.SizeY, 0.0, 0.0, 16, 16);
        }
    
        // Handle switching of goggles on and off
        if(bOn && !bWasOn){
           bWasOn=true;
           if(P !=none) P.PlayOwnedSound(toggleSound, SLOT_Interact,0.5,,,,false);
           FadeTime = level.timeseconds;
        }else if(!bOn && bWasOn ){
           bWasOn=false;
           if(P != none) P.PlayOwnedSound(toggleSound, SLOT_Interact,0.5,,,,false);
           FadeTime = level.timeseconds;
        }
    
        // draw all the fancy stuff
        if(bOn){
        	C.Style = 255;
    	    C.SetDrawColor(color_nvg.r, color_nvg.g, color_nvg.b,255); // really blur out the entire forground view!
    	    C.SetPos(0,0);
    	    C.DrawTile( ColorMat, C.SizeX, C.SizeY, 0.0, 0.0, ColorMat.MaterialUsize(), ColorMat.MaterialVsize() );
    
            ForEach P.DynamicActors(class'UnrealPawn', RP, ){
               if(RP != P && VSize(RP.location-P.location)<3500){
                   if(P.FastTrace(RP.location, P.location)) RP.SetOverlayMaterial(THERMplayer,1, true);
                   else RP.SetOverlayMaterial(ThermHidePlayer,1, true);
                   RP.bUnlit=true;
                   C.DrawActor(RP,false,true);//draw on top of everything else
                   RP.SetOverlayMaterial(none,1, true);
                   RP.bUnlit=false;
               }
    	    }
    
            // draw the "ring" around the view
            C.Style = 255;
    	    C.SetDrawColor (0, 0, 0,255);
    	    C.SetPos(0,0);
    	    C.DrawTile( View, C.SizeX, C.SizeY, 0.0, 0.0, View.MaterialUsize(), View.MaterialVsize() );
        }
    
        lastCheckTime =  currtime;
    
    }
    
    defaultproperties{
         BatteryLife=320
         ChargeSpeed=1.3// it takes the nvgs longer to charge up than use up
         View=Material'NVGviewFinal'
         ColorMat=Material'XGameShaders.ZoomFX.ModuNoise'
         THERMplayer=TexPanner'XGameShaders.ZoomFX.ScreenNoisePan'//Material'ThermGraySkin'
         ThermHidePlayer=Material'MotionGraySkin'
         color_nvg=(r=30,g=30,b=30,a=245)
         toggleSound=sound'MenuSounds.MS_CLick'
    }

    Leave a comment:


  • replied
    So the whole thing is totally wrong? is their anyway to use this code in
    UT2k4. What could i change? aww man this bad isnt it. im really desperate now.

    all i was trying to do was apply a gray overlay on the screen when the player gets a pick up object which also uses similair code.

    Leave a comment:


  • replied
    HudMutator? Did you get that from UT99? HUDoverlays and Interactions are used in UT2Kx for adding stuff to the HUD. That code would appear to be referencing the UT99 code base.

    Leave a comment:


  • replied
    thanks, here's the full full code you asked for, hope it gives you a clue.

    error: WolfGrayMutator.uc<40> : error, Bad or missing expression in 'if'

    Code:
    // HUD Mutator to handle drawing Wolf Vision overlay
    class WolfGrayMutator extends Mutator;
    var Pawn PlayerOwner;
    var float LastChecked;
    var WolfGray aWolfGray;
    
    // If the mutator hasn't been registered, register it
    simulated function Tick(float DeltaTime)
    {
      if (Level.NetMode == NM_DedicatedServer || bHUDMutator)
        Disable('Tick');
      else
        RegisterHUDMutator();
    }
    
    // RegisterHUDMutator that keeps track of the HUD's owner
    simulated function RegisterHUDMutator()
    {
      local Pawn P;
    
      ForEach AllActors(class'Pawn', P)
        if ( P.IsA('Pawn') && (P.myHUD != None) )
        {
          NextHUDMutator = P.myHud.HUDMutator;
          P.myHUD.HUDMutator = Self;
          bHUDMutator = True;
          PlayerOwner = P;
        }
    }
    
    // If the player has Wolf Vision, draw overlay
    simulated function PostRender(canvas C)
    {
      local int i;
      local Inventory inv;
    
      if ( PlayerOwner == None )
      {
        Destroy();
        if ( NextHUDMutator != None )
        {
           NextHUDMutator.PostRender( C );
           return;
        }
      }
      if ( PlayerOwner == ChallengeHUD(PlayerOwner.MyHUD).PawnOwner )
      {
        // Delay checking of inventory
        if ( Level.TimeSeconds - LastChecked > 0.3 )
        {
          LastChecked = Level.TimeSeconds;
          inv = PlayerOwner.Inventory;
          while (inv != None )
          {
            if ( inv.IsA('WolfVision') )
            {
              aWolfGray = WolfGray(inv);
              break;
            }
            inv = inv.inventory;
            i++;
            if ( i > 200 )
              inv = none;
          }
        }
        // Draw overlay if Wolf Vision activated
        if ( aWolfGray != None && aWolfGray.bEnabled )
        {
          C.SetPos(0, 0);
          C.Style = ERenderStyle.STY_Translucent;
          C.DrawIcon(Texture'WolfGrayOverlay', FMax(C.ClipX, C.ClipY)/256.0); // Assumes 256x256 texture
        }
      }
    
      if ( NextHUDMutator != None )
      {
        NextHUDMutator.PostRender( C );
      }
    }
    
    defaultproperties
    {
         aWolfGray=None
         bAlwaysRelevant=True
         bNetTemporary=True
         RemoteRole=Role_SimulatedProxy
    }

    Leave a comment:


  • replied
    That appears to be correct. Could you perhaps post the entire code and the error message? The problem might be somewhere else.

    And thx for using code tags.

    Leave a comment:


  • replied
    the error is in the PlayerOwner arguement

    Leave a comment:


  • replied
    Thanks for the interest, heres the code again

    Code:
    // HUD Mutator to handle drawing Wolf Vision overlay
    class WolfGrayMutator extends Mutator;
    var Pawn PlayerOwner;
    var float LastChecked;
    var WolfGray aWolfGray;
    ........

    Code:
    // If the player has Wolf Vision, draw overlay
    simulated function PostRender(canvas C)
    {
      local int i;
      local Inventory inv;
    
      if ( PlayerOwner == None )
      {
        Destroy();
        if ( NextHUDMutator != None )
           NextHUDMutator.PostRender( C );
           return;
      }
    ......

    Leave a comment:


  • replied
    Are PlayerOwner and NextHUDMutator existant variables? (are they both defined?)

    Also, use code tags.

    Leave a comment:


  • replied
    im having a problem with this error code too. I dont understand whats bad about the expression. the a statement or the arguement. here's the code anyway....

    local int i;
    local Inventory inv;

    if ( PlayerOwner == None )
    {
    Destroy();
    if ( NextHUDMutator != None )
    NextHUDMutator.PostRender( C );
    return;
    }

    Leave a comment:


  • replied
    Yeah, you can't say (if class != none) - you have to use an instance of the class (an object) .

    Let us know if that is still unclear.

    Leave a comment:


  • replied
    Code:
    local StogiesItem StogiesInstance;
    StogiesInstance = Spawn(Class'StogiesItem');
    
    If (StogiesInstance != None)
      StogiesInstance.P = P;
    }
    You used the class name, not the variable. And use code tags instead of quote tags please.

    Leave a comment:


  • started a topic Bad or missing expression in 'if' Please help

    Bad or missing expression in 'if' Please help

    I am having a problem with my script. I get the Error "Bad or missing expression in 'if' I am currently working in UT2004.

    This is what I have for my Pickup class so far.


    class StogiesPickup extends Pickup;

    auto state Pickup
    {
    function Touch( actor Other )
    {
    if ( ValidTouch(Other) )
    {

    P = Pawn(Other);
    }
    EffectPlayer(P);
    SetRespawn();
    }
    }

    function EffectPlayer(Pawn P)
    {

    local StogiesItem StogiesInstance;
    StogiesInstance = Spawn(Class'StogiesItem');

    If (StogiesItem != none)
    StogiesItem.P = P;

    }


    defaultproperties
    {
    PickupMessage="Puff Puff!"
    DrawType=DT_StaticMesh
    StaticMesh=StaticMesh'Stogies.StogiesMesh'
    DrawScale=1
    }
    The problem is highlighted in yellow. I am still fairly new to UnrealScript and am having a hard time figuring out whats wrong. Upon compiling it I get the
    Error, Bad or missing expression in 'if'
    Help or feedback would be greatly appreciated.
Working...
X