Announcement

Collapse
No announcement yet.

Scaleform Health issue Extends HUD.

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

    Scaleform Health issue Extends HUD.

    Having issues with my Base Hud. Can't get it to pull the players health, and so far I keep getting a scriptwarning: accessed none 'PlayerOwner'
    Anyone any ideas? This has been driving me mental the last 3 hours.

    GGJHud.uc
    Code:
    class GGJHud extends HUD;
    var GGJMoviePlayer HudMovie;
    var GGJPlayerController myPC;
    
    simulated function PostBeginPlay()
    {
        myPC = GGJPlayerController(PlayerOwner);
        HudMovie = new class'GGJMoviePlayer';
        HudMovie.SetTimingMode(TM_Real);
        HudMovie.Initialize(myPC);
    }
    
    defaultproperties
    {
        
    }
    GGJMoviePlayer
    Code:
    class GGJMoviePlayer extends GFxMoviePlayer;
    var float LastHealthpc;
    
    var GFxObject HealthTF;
    
    function int roundNum(float NumIn)
    {
        local int iNum;
        local float fNum;
        
        fNum = NumIn;
        iNuM = int(fNum);
        if(fNum >= 0.5f)
        {
            return (iNum + 1);
        }
        else
        {
            return iNum;   
        }
    }
    
    function int getPercentage(int val, int max)
    {
        return roundNum((float(val) / float(max)) * 100.0f);
    }
    
    function bool Initialize(optional GGJPlayerController PC)
    {
        Start();
        Advance(0.f);
    
        LastHealthpc = -1337;
        HealthTF = GetVariableObject("_root.healthTF");    
        return true;
    }
    
    function TickHUD()
    {
        local GGJPawn UTP;
        UTP = GGJPawn(GetPC().Pawn);
     
        if(UTP == None)
        return;
     
        if(LastHealthpc != getPercentage(UTP.Health,UTP.HealthMax))
        {
            LastHealthpc = getPercentage(UTP.Health,UTP.HealthMax);
            
            HealthTF.SetString("text", round(LastHealthpc)$"%");
        }   
    }
    
    defaultproperties
    {
        MovieInfo=SwfMovie'GGJ-Hud.GGJHud'  
    }
    Cheers,
    - Sythen.

    #2
    You should be passing a reference to your playercontroller into the initialize function of the GGJMoviePlayer class. Except the reference is never being stored so instead of trying to get a new one through tickhud modify the initialize function to use the variable that is being passed in:


    Code:
    class GGJMoviePlayer extends GFxMoviePlayer;
    var float LastHealthpc;
    
    var GGJPawn UTP; //Owner here
    var GFxObject HealthTF;
    
    function int roundNum(float NumIn)
    {
        local int iNum;
        local float fNum;
        
        fNum = NumIn;
        iNuM = int(fNum);
        if(fNum >= 0.5f)
        {
            return (iNum + 1);
        }
        else
        {
            return iNum;   
        }
    }
    
    function int getPercentage(int val, int max)
    {
        return roundNum((float(val) / float(max)) * 100.0f);
    }
    
    function bool Initialize(optional GGJPlayerController PC)
    {
        Start();
        Advance(0.f);
    
    	UTP = GGJPawn(PC.Pawn); //---- here
    
        LastHealthpc = -1337;
        HealthTF = GetVariableObject("_root.healthTF");    
        return true;
    }
    
    function TickHUD()
    {
        if(UTP == None)
        return;
     
        if(LastHealthpc != getPercentage(UTP.Health,UTP.HealthMax))
        {
            LastHealthpc = getPercentage(UTP.Health,UTP.HealthMax);
            
            HealthTF.SetString("text", round(LastHealthpc)$"%");
        }   
    }
    
    defaultproperties
    {
        MovieInfo=SwfMovie'GGJ-Hud.GGJHud'  
    }

    By chance the reference isn't be passed into the initialize function of the gfxmovie class correctly. This would mean that the myPC within the postbeginplay function of your hud class is being set as none. The PostBeginPlay in your code is not using "super.PostBeginPlay();" which if you look into your hud class is actually setting PlayerOwner = PlayerController(Owner); . You might not want to extend directly from HUD because you're losing some functionality for mobile hud that comes later, but maybe extend from UTHUDBase or UDKHUD. It doesn't really matter though.

    Comment

    Working...
    X