Displaying data onscreen, score for example.

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

danydrunk

New Member
Apr 27, 2006
2
0
0
Iven been reading the info at udn and wikipedia, but I cant figure out what part actually prints the info onscreen. For example in the myfirst example classes theres one called: ExampleHud.uc

This .uc file has:

class ExampleHUD extends HUD;

var PlayerController PlayerOwner;
var Material HUDScoreBox;



simulated function PostBeginPlay()
{
Super.PostBeginPlay();
PlayerOwner = PlayerController(Owner);
}


function DrawHUD(canvas Canvas)
{
local Pawn PawnOwner;
local PlayerReplicationInfo PawnOwnerPRI;
local int FontSize;
local float HUDScoreScaleX, HUDScoreScaleY;
local float HUDScorePosX, HUDScorePosY;
local int Score;
local string ScoreString;
local float XL,YL;

// Get PlayerOwner
if (PlayerOwner.ViewTarget == PlayerOwner)
{
PawnOwner = PlayerOwner.Pawn;
}
else if (PlayerOwner.ViewTarget.IsA('Pawn') && Pawn(PlayerOwner.ViewTarget).Controller != None)
{
PawnOwner = Pawn(PlayerOwner.ViewTarget);
}
else if ( PlayerOwner.Pawn != None )
{
PawnOwner = PlayerOwner.Pawn;
}
else
{
PawnOwner = None;
}

// Get PlayerReplication
if ((PawnOwner != None) && (PawnOwner.Controller != None))
PawnOwnerPRI = PawnOwner.PlayerReplicationInfo;
else
PawnOwnerPRI = PlayerOwner.PlayerReplicationInfo;

//Get Font Size - (larger numbers are smaller fonts)
if ( Canvas.ClipX <= 640 )
FontSize=2;
else if ( Canvas.ClipX <= 800 )
FontSize=3;
else if ( Canvas.ClipX <= 1024 )
FontSize=2;
else if ( Canvas.ClipX <= 1280 )
FontSize=1;
else if ( Canvas.ClipX <= 1600 )
FontSize=0;
else
FontSize=0;
Canvas.Font = LoadFontStatic(FontSize);


// Draw Hud


Right now if I run it, theres a score at the right side of the screen that increases when I do the DoDance thing. What If I want to print a second score thing on the screen ? that increases when I do the fly for example ? Of all the code presented which part is actually displaying the score to the screen? Im new to this and I just need to get started, this will help me a lot thanks.
 

_Lynx

Strategic Military Services
Staff member
Dec 5, 2003
1,965
8
38
40
Moscow, Russia
beyondunreal.com
I suppose you're talking about this: http://udn.epicgames.com/Two/MyFirstHUD#My_First_HUD

the following bit of code just prepares the variables required to to script to work properly (where from the score should be taken, etc)

Code:
// Get PlayerOwner
if (PlayerOwner.ViewTarget == PlayerOwner)
{
PawnOwner = PlayerOwner.Pawn;
}
else if (PlayerOwner.ViewTarget.IsA('Pawn') && Pawn(PlayerOwner.ViewTarget).Controller != None)
{
PawnOwner = Pawn(PlayerOwner.ViewTarget);
}
else if ( PlayerOwner.Pawn != None )
{
PawnOwner = PlayerOwner.Pawn;
}
else
{
PawnOwner = None;
}

// Get PlayerReplication
if ((PawnOwner != None) && (PawnOwner.Controller != None))
PawnOwnerPRI = PawnOwner.PlayerReplicationInfo;
else
PawnOwnerPRI = PlayerOwner.PlayerReplicationInfo;

The following fragment just selects the font fitting for the current screen resolution

Code:
//Get Font Size - (larger numbers are smaller fonts)
if ( Canvas.ClipX <= 640 )
FontSize=2;
else if ( Canvas.ClipX <= 800 )
FontSize=3;
else if ( Canvas.ClipX <= 1024 )
FontSize=2;
else if ( Canvas.ClipX <= 1280 )
FontSize=1;
else if ( Canvas.ClipX <= 1600 )
FontSize=0;
else
FontSize=0;
Canvas.Font = LoadFontStatic(FontSize);

But you left out the bit that is mentioned later:
Code:
function DrawHUD(canvas Canvas)
{
   ...

   // Draw Hud

   Canvas.SetDrawColor(255,255,255);
   HUDScoreScaleX = Canvas.ClipX/800;
   HUDScoreScaleY = Canvas.ClipY/600;
   HUDScorePosX = Canvas.ClipX - 256*HUDScoreScaleX;
   HUDScorePosY = Canvas.ClipY - 128*HUDScoreScaleY;
   Canvas.SetPos(HUDScorePosX, HUDScorePosY);
   Canvas.DrawTileScaled(HUDScoreBox, HUDScoreScaleX, HUDScoreScaleY);

   Canvas.SetDrawColor(230,240,240);
   Score = PawnOwnerPRI.Score;
   ScoreString = ""$Score;
   Canvas.StrLen(ScoreString,XL,YL);
   Canvas.SetPos(HUDScorePosX + 235*HUDScoreScaleX - XL, HUDScorePosY + 70*HUDScoreScaleY);
   Canvas.DrawText(Score);
}

That's the function that actually does the drawing.

You need to have al three bits in your function. Also the defaultproperties bit should be in defaultpropertis of you class
 

danydrunk

New Member
Apr 27, 2006
2
0
0
Yes I was talking about that Hud. What I havent been able to figure out is how to make the game display more than one score in on the screen. For example right now every time I press the key "G" my score increases by 1 (or more if I specify so). Lets say I want to put another score that decreases everytime I press F for example. How would I get to print two scores in the screen at the same time. So far all my atempts to make it have failed. Thanks