Announcement

Collapse
No announcement yet.

Function GetPc error

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

  • replied
    It's another function that already exists in the base classes, so you can't change anything about the function's parameter types. Init is in GFxMoviePlayer.uc, and defined as function Init(optional LocalPlayer LocPlay). This should work:

    Code:
    function Init(optional LocalPlayer LocPlay)
    {
    	Super.Init(LocPlay);
    	
    	Start();
    	Advance(0.f);
    
    	LastHealthpc = -1337;
    	HealthMC = GetVariableObject("_root.health_bar");
    	HealthBarMC = GetVariableObject("_root.healthbar_mc.bar_mc");
    	HealthTF = GetVariableObject("_root.healthbar_mc.health_txt");
    }

    Leave a comment:


  • replied
    Originally posted by isathar View Post
    There's already a function called GetPC in GFxMoviePlayer, so you'll have to use a different name.
    There's also a native function for rounding, so you won't need your roundNum function. You should be able to use Round(value) in just about every class type. Also don't forget to define your return type on the percentage function. This should work: (I'm assuming you want to return an int due to the rounding)

    Code:
    function int GetPercentage(int val, int max)
    {
        return Round((float(val) / float(max)) * 100.0f);
    }

    EDIT: I just remembered, you could also do the following instead of writing your own percentage function (there's a native function for it):
    (val and max are the values you used for the function above)

    percentageValue = int(FPctByRange(float(val), 0.0, float(max)) * 100.0);
    Ty it work, you save me here.
    But now im getting the error for this too

    function Init(PlayerController PC) {
    //Start and load the SWF Movie
    Start();
    Advance(0.f);

    //Set the cahce value so that it will get updated on the first Tick
    LastHealthpc = -1337;

    //Load the references with pointers to the movieClips and text fields in the .swf
    HealthMC = GetVariableObject("_root.health_bar");
    HealthBarMC = GetVariableObject("_root.healthbar_mc.bar_mc");
    HealthTF = GetVariableObject("_root.healthbar_mc.health_txt") ;
    }
    the error is function init differs from original D:

    Leave a comment:


  • replied
    There's already a function called GetPC in GFxMoviePlayer, so you'll have to use a different name.
    There's also a native function for rounding, so you won't need your roundNum function. You should be able to use Round(value) in just about every class type. Also don't forget to define your return type on the percentage function. This should work: (I'm assuming you want to return an int due to the rounding)

    Code:
    function int GetPercentage(int val, int max)
    {
        return Round((float(val) / float(max)) * 100.0f);
    }

    EDIT: I just remembered, you could also do the following instead of writing your own percentage function (there's a native function for it):
    (val and max are the values you used for the function above)

    percentageValue = int(FPctByRange(float(val), 0.0, float(max)) * 100.0);

    Leave a comment:


  • started a topic Function GetPc error

    Function GetPc error

    I followed an tutorial to make a health bar but im getting this error
    Code:
    C:\UDK\UDK-2014-08\Development\Src\FeelingGame\Classes\FeelingGFxHUD.uc(26) : Error, Redefinition of 'function getpc' differs from original: return value mismatch
    This is the script
    Code:
    class FeelingGFxHUD extends GFxMoviePlayer;
    
    //Create a Health Cache variable
    var float LastHealthpc;
    //Create variables to hold references to the Flash MovieClips and Text Fields that will be modified
    var GFxObject HealthMC, HealthBarMC;
    var GFxObject HealthTF;
    
    //  Function to round a float value to an int
    function int roundNum(float NumIn) {
     local int iNum;
     local float fNum;
    
     fNum = NumIn;
     iNum = int(fNum);
     fNum -= iNum;
     if (fNum >= 0.5f) {
     return (iNum + 1);
     }
     else {
     return iNum;
     }
    }
    
    //  Function to return a percentage from a value and a maximum
    function getpc(int val, int max) {
     return roundNum((float(val) / float(max)) * 100.0f);
    }
    
    //Called from STHUD'd PostBeginPlay()
    function Init(PlayerController PC) {
     //Start and load the SWF Movie
     Start();
     Advance(0.f);
    
     //Set the cahce value so that it will get updated on the first Tick
     LastHealthpc = -1337;
    
     //Load the references with pointers to the movieClips and text fields in the .swf
     HealthMC = GetVariableObject("_root.health_bar");
     HealthBarMC = GetVariableObject("_root.healthbar_mc.bar_mc");
     HealthTF = GetVariableObject("_root.healthbar_mc.health_txt");
    }
    
    //Called every update Tick
    function TickHUD() {
     local UTPawn UTP;
    
     //We need to talk to the Pawn, so create a reference and check the Pawn exists
     UTP = UTPawn(PlayerOwner.Pawn);
     if (UTP == None) {
     return;
     }
    
     //If the cached value for Health percentage isn't equal to the current...
     if (LastHealthpc != getpc(UTP.Health, UTP.HealthMax)) {
     //...Make it so...
     LastHealthpc = getpc(UTP.Health, UTP.HealthMax);
     //...Update the bar's xscale (but don't let it go over 100)...
     HealthBarMC.SetFloat("_xscale", (LastHealthpc > 100) ? 100.0f : LastHealthpc);
     //...and update the text field
     }
    }
    
    DefaultProperties
    {
     //this is the HUD. If the HUD is off, then this should be off
     bDisplayWithHudOff=false
     //The path to the swf asset we will create later
     MovieInfo=SwfMovie'myHUD.LASTHUDTEST'
     //Just put it in...
     bGammaCorrection = false
    }
    Please help me with this error, i'm a noob so please use terms i can understand xD Ty.
Working...
X