Graphics

 View Only
Expand all | Collapse all

Adding a '%' to the end...

  • 1.  Adding a '%' to the end...

    Posted 10-25-2012 00:30
    I'm wondering if anyone knows how I can have the XPression add a '%' at the end of user inputted text. I'm working on an election graphic and I don't want the producers to have to put a % every time.

    I suppose I could have the % in the field already and tell them to type before it, but it would be even easier if they didn't have to worry about it at all.

    Thanks!


  • 2.  RE: Adding a '%' to the end...

    Posted 10-25-2012 00:38
    Hey David,

    If you right click on your text object and select "edit script events" you can run a script on set text to change the string value. Try a script like this.

    text = text & "%"

    Cheers

    #XPression


  • 3.  RE: Adding a '%' to the end...

    Posted 10-25-2012 01:02
    That's awesome Andrew... So simple.

    Let me ask you this, however: I also want to have a check mark automatically appear next to the candidate with the higher percentage.

    My scene script looks like this:

    dim TopCand as xpTextObject

    dim BottomCand as xpTextObject

    dim winner1 as xpBaseObject

    dim winner2 as xpBaseObject

    dim candval1 as integer

    dim candval2 as integer

    Self.GetObjectByName("Top Candidate Percentage", TopCand)

    Self.GetObjectByName("Bottom Candidate Percentage", BottomCand)

    Self.GetObjectByName("Top Check", winner1)

    Self.GetObjectByName("Bottom Check", winner2)

    candval1 =cint(TopCand.text)

    candval2 =cint(BottomCand.text)

    if candval1 > candval2 then

    winner1.visible = true

    winner2.visible = false

    end if

    if candval2 > candval1 then

    winner1.visible = false

    winner2.visible = true

    end if

    I've got the script you gave me on the text objects in the scene. The scene script did not work, and I'm wondering if it's because it's adding the %.

    I'm wondering if there's a way to copy the inputted text, minus the '%,' to a hidden field to use in the scene script. I don't know if that makes sense, or if there's an easier way and I'm overthinking this.

    But thanks for the quick reply on the initial question. Worked like a charm!

    #XPression


  • 4.  RE: Adding a '%' to the end...

    Posted 10-25-2012 01:09
    One of the things I have done is setup two text fields. The number in one text field gets aligned right and the % in the next field just to the right of the first text field is aligned left. Of course that depends on what language you are working with...

    #XPression


  • 5.  RE: Adding a '%' to the end...

    Posted 10-25-2012 01:10
    I did think of that, Richie. I'll try it and see how it looks. That might be the easiest way to do this.

    #XPression


  • 6.  RE: Adding a '%' to the end...

    Posted 10-25-2012 01:18
    Yes you can do that, although I would do it the other way around. I would have a hidden field which is published so the invisible field is what you are typing into.

    so again on set text on the new hidden text object and make sure this is the published text object not the one that is visible.

    dim TopCand as xpTextObject

    scene.GetObjectByName("Top Candidate Percentage", TopCand)

    TopCand.Text = text & "%"

    you will have to change your scene script use the new text objects that the journalists are inputting into and turn off the publishing for the text objects we are copying too and adding the percent symbol.

    Hope that makes sense.

    #XPression


  • 7.  RE: Adding a '%' to the end...

    Posted 10-25-2012 01:27
    OK, let me see if I understand this...

    If I copy the layer I have as Top Candidate Percentage, move it off the screen, add this script to the On Set Text. This is the layer that is published, so when the journalist enters the number it is going into this hidden field.

    Does this script then copy the number they entered, add the '%' and input it into the original layer? In either case, I need to have a different name for each layer. The hidden one - the one I want the journalist to enter into, should be named Top Candidate Percentage. So I have to change the name of the original layer, the one that is ultimately seen on air. If I do that, do I need to change the script to reflect that new name?

    That doesn't make sense, does it? LOL

    #XPression


  • 8.  RE: Adding a '%' to the end...

    Posted 10-25-2012 01:29
    That is correct. you will have to make sure they have unique names. You don't have to move those objects off screen either you can just make them invisible.

    #XPression


  • 9.  RE: Adding a '%' to the end...

    Posted 10-25-2012 02:47
    OK, I almost have it.

    It all works, except the Scene Script shows up as the Bottom Candidate Perc (the visible, non published layer) when I put it into the sequencer.

    So, when I'm looking at it in the Layout view, there is nothing in that layer. As soon as I move it over to the Sequence to test it, the entire Scene Script is visible. If I erase it all, and type a number in it, everything works just fine. It doesn't show up in the Top Candidate Perc, just the bottom.

    Here are my scripts:

    In a hidden layer called Top Candidate Percentage --

    dim TopCand as xpTextObject

    scene.GetObjectByName("Top Candidate Perc", TopCand)

    TopCand.Text = text & "%"

    In a hidden layer called Bottom Candidate Percentage --

    dim BottomCand as xpTextObject

    scene.GetObjectByName("Bottom Candidate Perc", BottomCand)

    BottomCand.Text = text & "%"

    Scene Script:

    dim TopCand as xpTextObject

    dim BottomCand as xpTextObject

    dim winner1 as xpBaseObject

    dim winner2 as xpBaseObject

    dim candval1 as integer

    dim candval2 as integer

    Self.GetObjectByName("Top Candidate Percentage", TopCand)

    Self.GetObjectByName("Bottom Candidate Percentage", BottomCand)

    Self.GetObjectByName("Top Check", winner1)

    Self.GetObjectByName("Bottom Check", winner2)

    candval1 =cint(TopCand.text)

    candval2 =cint(BottomCand.text)

    if candval1 > candval2 then

    winner1.visible = true

    winner2.visible = false

    end if

    if candval2 > candval1 then

    winner1.visible = false

    winner2.visible = true

    end if

    There's a layer called Top Candidate Perc and another Bottom Candidate Perc -- Those are the visible layers.

    I'm so confused as to why this should happen.

    #XPression


  • 10.  RE: Adding a '%' to the end...

    Posted 10-26-2012 02:07
    OK, I figured this out. I don't know how or when, but somehow that script got put into the text layer, and it was at 0% on the Alpha, so I couldn't see it in the Layout view. But when it was put into the sequence, that text was already in the layer.

    Crisis averted...

    Thank you so much for you help!

    #XPression


  • 11.  RE: Adding a '%' to the end...

    Posted 03-04-2013 23:03
    David, I'm very interested in your (I'm assuming) elections setup. We use a similar system, but label our candidate groups by number, allowing us to use a loop to control all of this. We do not display a check unless we have declared a winner, however, instead of consistently. Using DataLinq, the scene will stack our candidates in order of winner, top to bottom.

    For example, if we have three candidates, then the scene has three groups, "Candidate 1," "Candidate 2," and "Candidate 3." Within those groups is "Candidate 1 Name," "Candidate 1 Votes," and "Candidate 1 Perc," an image file set at 0% alpha titled "Candidate 1 Check" and an invisible text field titled "Candidate 1 WinFlag." Those are DataLinq'ed to our elections data source, excluding the check.

    The script that runs is then:

    dim winner as xpTextObject

    dim flag as xpBaseObject

    dim i as Integer

    for i = 1 to 3

    Self.GetObjectByName("Candidate " & i & " WinFlag", winner)

    Self.GetObjectByName("Candidate " & i & " Check", flag)

    If Len(winner.Text) > 0 then

    Check.Alpha = 100

    Else

    Check.Alpha = 0

    End If

    next i


    Our data source will put a "W" in the WinFlag text field if there's a winner, empty if not. Therefore the Len(String) allows us to say if the length of text is higher than nothing, make the check visible, if not hide it.

    The other option we've gone with is InStr(String) in order to find what letter is actually in it. W is for winner, R is for runoff winner, C is for contested winner, etc, which allows us to do even more with the scene.

    Like I said, I'm interested in how you build your scenes, and think I may have some insight for your own. Send me a private message if you'd like, we may even be able to share .xpp's via ftp if that helps.

    #XPression