Displaying a single digit stat in a 2-digit space in HUD

Forum for users that want to write their own custom queries against the PT database either via the Structured Query Language (SQL) or using the PT3 custom stats/reports interface.

Moderator: Moderators

Displaying a single digit stat in a 2-digit space in HUD

Postby bloodndef » Sat Aug 14, 2010 4:35 pm

I'd like to layout my stats in my HUD in a way so that if I click on a specific stat, a pop up for that stat displays. E.g. if I click on PFR, I'll get a pop-up displaying a player's PFR by position.

I have the PFR stat set apart in its own "black box" displaying the stat, and I set the pop-up to it just fine. But when the stat is displaying a single digit value, the "black box" is smaller and when the stat is displaying a 2-digit value, the "black box" is larger.

I'd like the "black box" that the stat is in to be the same size regardless whether a single digit value or a double digit value (and perhaps even a triple digit value) is displayed.

What I believe to be the solution is to have two spaces inserted in front of the single digit value when a single digit value is displayed for that stat in the HUD, one space inserted in front of the double digit value that is displayed for that stat in the HUD, and no space inserted before the triple digit value when it is displayed in the HUD.

How do I begin going about formatting the display of a stat in this manner in the HUD?

Thanks for the assistance!
bloodndef
 
Posts: 99
Joined: Fri Feb 27, 2009 1:28 am

Re: Displaying a single digit stat in a 2-digit space in HUD

Postby WhiteRider » Sun Aug 15, 2010 9:35 am

You can't do that purely in the HUD - you'd need to duplicate the stat and change the Format Expression.
For instance, something like this, where "val" is the value you're displaying (this might be an expression):

format( '{1}{2}', if( val < 10, ' ', '' ), format_number(val,0, false, false) )

This is a little complex, so I'll break it down for you.

The "format" function replaces the {1} and {2} (and any number of others that you want to add) with the values that follow.
Here we have two {} entries so we have two values:
if( val < 10, ' ', '' )
..and..
format_number(val,0, false, false)

The first one: "if( val < 10, ' ', '' )" checks whether "val" is less than 10, and if it is it replaces {1} with a space, otherwise it replaces it with nothing.

The second one: "format_number(val,0, false, false)" just formats "val" to zero decimal places.
WhiteRider
Moderator
 
Posts: 54025
Joined: Sat Jan 19, 2008 7:06 pm
Location: UK

Re: Displaying a single digit stat in a 2-digit space in HUD

Postby bloodndef » Sun Aug 15, 2010 4:46 pm

Thank you!

Here's what I'm working with for VPIP:

First Attempt = format( '{1}{2}{3}', if ( (((cnt_vpip / cnt_hands) * 100) < 100 AND ((cnt_vpip / cnt_hands) * 100)) > 9, ' ', '', '' ), format_number(((cnt_vpip / cnt_hands) * 100), 0, false, false) ) ) AND (format( '{1}{2}{3}', if ( ((cnt_vpip / cnt_hands) * 100) < 10, ' ', ' ', '' ), format_number(((cnt_vpip / cnt_hands) * 100), 0, false, false) )

Second Attempt = format( '{1}{2}{3}', if ( ( (((cnt_vpip / cnt_hands) * 100) < 100 AND ((cnt_vpip / cnt_hands) * 100)) > 9, ' ', '', '' ) OR ( ((cnt_vpip / cnt_hands) * 100) < 10, ' ', ' ', '' ) ), format_number(((cnt_vpip / cnt_hands) * 100), 0, false, false) )

Both are valid. Which is correct?

Thanks again!
bloodndef
 
Posts: 99
Joined: Fri Feb 27, 2009 1:28 am

Re: Displaying a single digit stat in a 2-digit space in HUD

Postby bloodndef » Sun Aug 15, 2010 5:39 pm

Hm. Neither works.
bloodndef
 
Posts: 99
Joined: Fri Feb 27, 2009 1:28 am

Re: Displaying a single digit stat in a 2-digit space in HUD

Postby WhiteRider » Sun Aug 15, 2010 5:43 pm

Neither of those look right to me - you seem to have 4 parts to your IF statements, which isn't right. There seem to be 3 quoted parts.
if ( (((cnt_vpip / cnt_hands) * 100) < 100 AND ((cnt_vpip / cnt_hands) * 100)) > 9, ' ', '', '' )

Personally, I'd do this:

format( '{1}{2}', if ( ((cnt_vpip / cnt_hands) * 100) < 10, ' ', if( ((cnt_vpip / cnt_hands) * 100) < 100, ' ', '' ), format_number(((cnt_vpip / cnt_hands) * 100), 0, false, false) )

Basically - if it's less than 10 then add 2 spaces, else if it's less than 100 add 1 space, add no spaces.
Note: I haven't actaully tried this expression in PT3 because it's busy testing something, but that kind of thing will work.
WhiteRider
Moderator
 
Posts: 54025
Joined: Sat Jan 19, 2008 7:06 pm
Location: UK

Re: Displaying a single digit stat in a 2-digit space in HUD

Postby bloodndef » Sun Aug 15, 2010 6:28 pm

Thanks for your help! Your expression was missing a small piece, but this seems to do what we're going for:

format( '{1}{2}', if ( ((cnt_vpip / cnt_hands) * 100) < 10, ' ', ''), if( ((cnt_vpip / cnt_hands) * 100) < 100, ' ', '' ), format_number(((cnt_vpip / cnt_hands) * 100), 0, false, false) )

If it's less than 10, add 1 space in front. If it's less than 100 add 1 space in front. (Therefore if it is less than 10 it will really be adding 2 spaces.) Else add no spaces.

I'm still a little confused on what the {1}{2} are doing. In this expression why do we need {1}{2} as opposed to {1} or {1}{2}{3}?

Thanks again!
bloodndef
 
Posts: 99
Joined: Fri Feb 27, 2009 1:28 am

Re: Displaying a single digit stat in a 2-digit space in HUD

Postby tarix » Sun Aug 15, 2010 7:46 pm

bloodndef wrote:I'm still a little confused on what the {1}{2} are doing. In this expression why do we need {1}{2} as opposed to {1} or {1}{2}{3}?


If I rewrite your expression like this:
Code: Select all
format( '{1}{2}',
    if ( ((cnt_vpip / cnt_hands) * 100) < 10, ' ', ''), if( ((cnt_vpip / cnt_hands) * 100) < 100, ' ', '' ),
    format_number(((cnt_vpip / cnt_hands) * 100), 0, false, false)
)


Does that help? The top-level format() is only getting two parameters.
tarix
Developer
 
Posts: 3760
Joined: Tue May 20, 2008 2:49 pm

Re: Displaying a single digit stat in a 2-digit space in HUD

Postby WhiteRider » Mon Aug 16, 2010 3:26 am

bloodndef wrote:Thanks for your help! Your expression was missing a small piece, but this seems to do what we're going for:

format( '{1}{2}', if ( ((cnt_vpip / cnt_hands) * 100) < 10, ' ', ''), if( ((cnt_vpip / cnt_hands) * 100) < 100, ' ', '' ), format_number(((cnt_vpip / cnt_hands) * 100), 0, false, false) )

If it's less than 10, add 1 space in front. If it's less than 100 add 1 space in front. (Therefore if it is less than 10 it will really be adding 2 spaces.) Else add no spaces.

I'm still a little confused on what the {1}{2} are doing. In this expression why do we need {1}{2} as opposed to {1} or {1}{2}{3}?

Thanks again!

Your expression has 3 parameters again now:

Code: Select all
format( '{1}{2}',
    if ( ((cnt_vpip / cnt_hands) * 100) < 10, ' ', ''),
    if( ((cnt_vpip / cnt_hands) * 100) < 100, ' ', '' ),
    format_number(((cnt_vpip / cnt_hands) * 100), 0, false, false)
)

..so you would need '{1}{2}{3}'.
That should work fine, though.

I was doing both of my optional spaces in one parameter, like this (pseudo-code):
Code: Select all
format( '{1}{2}',
    if vpip < 10 then 2 spaces else if vpip < 100 then 1 space else 0 spaces,
    format_number( ... )
)

..which only has 2 parameters to the format.
WhiteRider
Moderator
 
Posts: 54025
Joined: Sat Jan 19, 2008 7:06 pm
Location: UK

Re: Displaying a single digit stat in a 2-digit space in HUD

Postby bloodndef » Mon Aug 16, 2010 4:04 pm

Thank you Tarix and WhiteRider!

WhiteRider, you got to what I was struggling with: {1}{2} was working for me, but logically, I believed my expression should have been {1}{2}{3}

Is my thinking correct that while {1}{2} was working (giving me the results I wanted from my bolded expression above) it was ignoring the 3rd part? (Therefore is the 3rd part necessary?)

Finally, since PT3 rounds to the nearest whole number when displaying in the HUD, I was noticing that if a player's stat was 9.53 it would display 10 on the HUD and have 2 spaces. (When we would like a 2-digit stat to only add 1 space.) Is the expression below the solution to this?

Code: Select all
format( '{1}{2}{3}', if ( ((cnt_vpip / cnt_hands) * 100) < 9.5, ' ', ''), if( ((cnt_vpip / cnt_hands) * 100) < 99.5, ' ', '' ), format_number(((cnt_vpip / cnt_hands) * 100), 0, false, false) )


Thanks again for all the help!
bloodndef
 
Posts: 99
Joined: Fri Feb 27, 2009 1:28 am

Re: Displaying a single digit stat in a 2-digit space in HUD

Postby bloodndef » Mon Aug 16, 2010 6:44 pm

This is very cool stuff and I think the ability to click on individual stats to view pop-ups is a great addition to PT3's user interface.

But there is a small snag... the spaces we are adding are not as large as the numbers they are standing in place for, causing the black background boxes to fluctuate in size. IMO, this is detrimental because we are going for a seamless appearance.

Here we get a small gap:
[ img ]

And here it is fine:
[ img ]

What it should look like at all times(I've replaced the spaces with underscores):
[ img ]

I'm testing various options. Let me know if you have any suggestions!
bloodndef
 
Posts: 99
Joined: Fri Feb 27, 2009 1:28 am

Next

Return to Custom Stats, Reports, and SQL [Read Only]

Who is online

Users browsing this forum: No registered users and 0 guests